import{s as dl,o as yl}from"../chunks/scheduler.37c15a92.js";import{S as kl,i as wl,g as _,s as p,r as M,A as hl,h as b,f as r,c as f,j as _l,u as d,x as $,k as bl,y as Cl,a as o,v as y,t as m,b as ge,d as c,w as k,p as je}from"../chunks/index.2bf4358c.js";import{Y as $l}from"../chunks/Youtube.1e50a667.js";import{C}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as Ml}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as Tl}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ve}from"../chunks/Heading.8ada512a.js";function Jl(u){let l,s;return l=new Ml({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/zh-CN/chapter2/section3_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter2/section3_tf.ipynb"}]}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function gl(u){let l,s;return l=new Ml({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/zh-CN/chapter2/section3_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter2/section3_pt.ipynb"}]}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function jl(u){let l,s;return l=new $l({props:{id:"d3JVgghSOew"}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function vl(u){let l,s;return l=new $l({props:{id:"AhChOFRegn4"}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function xl(u){let l,s=`在本节中，我们将更详细地了解如何创建和使用模型。我们将使用
AutoModel类，当您希望从检查点实例化任何模型时，这非常方便。`,t,a,w="这个AutoModel类及其所有相关项实际上是对库中各种可用模型的简单包装。它是一个聪明的包装器，因为它可以自动猜测检查点的适当模型体系结构，然后用该体系结构实例化模型。";return{c(){l=_("p"),l.textContent=s,t=p(),a=_("p"),a.textContent=w},l(i){l=b(i,"P",{"data-svelte-h":!0}),$(l)!=="svelte-11ue9rl"&&(l.textContent=s),t=f(i),a=b(i,"P",{"data-svelte-h":!0}),$(a)!=="svelte-3hqgu4"&&(a.textContent=w)},m(i,h){o(i,l,h),o(i,t,h),o(i,a,h)},d(i){i&&(r(l),r(t),r(a))}}}function Zl(u){let l,s=`在本节中，我们将更详细地了解如何创建和使用模型。我们将使用
AutoModel类，当您希望从检查点实例化任何模型时，这非常方便。`,t,a,w="这个AutoModel类及其所有相关项实际上是对库中各种可用模型的简单包装。它是一个聪明的包装器，因为它可以自动猜测检查点的适当模型体系结构，然后用该体系结构实例化模型。";return{c(){l=_("p"),l.textContent=s,t=p(),a=_("p"),a.textContent=w},l(i){l=b(i,"P",{"data-svelte-h":!0}),$(l)!=="svelte-11ue9rl"&&(l.textContent=s),t=f(i),a=b(i,"P",{"data-svelte-h":!0}),$(a)!=="svelte-3hqgu4"&&(a.textContent=w)},m(i,h){o(i,l,h),o(i,t,h),o(i,a,h)},d(i){i&&(r(l),r(t),r(a))}}}function Bl(u){let l,s;return l=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEJlcnRDb25maWclMkMlMjBURkJlcnRNb2RlbCUwQSUwQSUyMyUyMEJ1aWxkaW5nJTIwdGhlJTIwY29uZmlnJTBBY29uZmlnJTIwJTNEJTIwQmVydENvbmZpZygpJTBBJTBBJTIzJTIwQnVpbGRpbmclMjB0aGUlMjBtb2RlbCUyMGZyb20lMjB0aGUlMjBjb25maWclMEFtb2RlbCUyMCUzRCUyMFRGQmVydE1vZGVsKGNvbmZpZyk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertConfig, TFBertModel

<span class="hljs-comment"># Building the config</span>
config = BertConfig()

<span class="hljs-comment"># Building the model from the config</span>
model = TFBertModel(config)`,wrap:!1}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Ul(u){let l,s;return l=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEJlcnRDb25maWclMkMlMjBCZXJ0TW9kZWwlMEElMEElMjMlMjBCdWlsZGluZyUyMHRoZSUyMGNvbmZpZyUwQWNvbmZpZyUyMCUzRCUyMEJlcnRDb25maWcoKSUwQSUwQSUyMyUyMEJ1aWxkaW5nJTIwdGhlJTIwbW9kZWwlMjBmcm9tJTIwdGhlJTIwY29uZmlnJTBBbW9kZWwlMjAlM0QlMjBCZXJ0TW9kZWwoY29uZmlnKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertConfig, BertModel

<span class="hljs-comment"># Building the config</span>
config = BertConfig()

<span class="hljs-comment"># Building the model from the config</span>
model = BertModel(config)`,wrap:!1}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Wl(u){let l,s;return l=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEJlcnRDb25maWclMkMlMjBURkJlcnRNb2RlbCUwQSUwQWNvbmZpZyUyMCUzRCUyMEJlcnRDb25maWcoKSUwQW1vZGVsJTIwJTNEJTIwVEZCZXJ0TW9kZWwoY29uZmlnKSUwQSUwQSUyMyUyME1vZGVsJTIwaXMlMjByYW5kb21seSUyMGluaXRpYWxpemVkIQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertConfig, TFBertModel

config = BertConfig()
model = TFBertModel(config)

<span class="hljs-comment"># Model is randomly initialized!</span>`,wrap:!1}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function El(u){let l,s;return l=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEJlcnRDb25maWclMkMlMjBCZXJ0TW9kZWwlMEElMEFjb25maWclMjAlM0QlMjBCZXJ0Q29uZmlnKCklMEFtb2RlbCUyMCUzRCUyMEJlcnRNb2RlbChjb25maWcpJTBBJTBBJTIzJTIwTW9kZWwlMjBpcyUyMHJhbmRvbWx5JTIwaW5pdGlhbGl6ZWQh",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertConfig, BertModel

config = BertConfig()
model = BertModel(config)

<span class="hljs-comment"># Model is randomly initialized!</span>`,wrap:!1}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Il(u){let l,s,t,a="正如您之前看到的，我们可以用等效的AutoModel类替换Bert模型。从现在开始，我们将这样做，因为这会产生检查点不可知的代码；如果您的代码适用于一个检查点，那么它应该与另一个检查点无缝地工作。即使体系结构不同，这也适用，只要检查点是针对类似任务（例如，情绪分析任务）训练的。",w;return l=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQmVydE1vZGVsJTBBJTBBbW9kZWwlMjAlM0QlMjBURkJlcnRNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyYmVydC1iYXNlLWNhc2VkJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFBertModel

model = TFBertModel.from_pretrained(<span class="hljs-string">&quot;bert-base-cased&quot;</span>)`,wrap:!1}}),{c(){M(l.$$.fragment),s=p(),t=_("p"),t.textContent=a},l(i){d(l.$$.fragment,i),s=f(i),t=b(i,"P",{"data-svelte-h":!0}),$(t)!=="svelte-17h6j06"&&(t.textContent=a)},m(i,h){y(l,i,h),o(i,s,h),o(i,t,h),w=!0},i(i){w||(c(l.$$.fragment,i),w=!0)},o(i){m(l.$$.fragment,i),w=!1},d(i){i&&(r(s),r(t)),k(l,i)}}}function Rl(u){let l,s,t,a="正如您之前看到的，我们可以用等效的AutoModel类替换Bert模型。从现在开始，我们将这样做，因为这会产生检查点不可知的代码；如果您的代码适用于一个检查点，那么它应该与另一个检查点无缝地工作。即使体系结构不同，这也适用，只要检查点是针对类似任务（例如，情绪分析任务）训练的。",w;return l=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEJlcnRNb2RlbCUwQSUwQW1vZGVsJTIwJTNEJTIwQmVydE1vZGVsLmZyb21fcHJldHJhaW5lZCglMjJiZXJ0LWJhc2UtY2FzZWQlMjIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertModel

model = BertModel.from_pretrained(<span class="hljs-string">&quot;bert-base-cased&quot;</span>)`,wrap:!1}}),{c(){M(l.$$.fragment),s=p(),t=_("p"),t.textContent=a},l(i){d(l.$$.fragment,i),s=f(i),t=b(i,"P",{"data-svelte-h":!0}),$(t)!=="svelte-17h6j06"&&(t.textContent=a)},m(i,h){y(l,i,h),o(i,s,h),o(i,t,h),w=!0},i(i){w||(c(l.$$.fragment,i),w=!0)},o(i){m(l.$$.fragment,i),w=!1},d(i){i&&(r(s),r(t)),k(l,i)}}}function Vl(u){let l,s;return l=new C({props:{code:"bHMlMjBkaXJlY3Rvcnlfb25fbXlfY29tcHV0ZXIlMEElMEFjb25maWcuanNvbiUyMHRmX21vZGVsLmg1",highlighted:`ls <span class="hljs-keyword">directory_on_my_computer
</span>
<span class="hljs-built_in">config</span>.<span class="hljs-keyword">json </span>tf_model.h5`,wrap:!1}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Gl(u){let l,s;return l=new C({props:{code:"bHMlMjBkaXJlY3Rvcnlfb25fbXlfY29tcHV0ZXIlMEElMEFjb25maWcuanNvbiUyMHB5dG9yY2hfbW9kZWwuYmlu",highlighted:`ls <span class="hljs-keyword">directory_on_my_computer
</span>
<span class="hljs-built_in">config</span>.<span class="hljs-keyword">json </span>pytorch_model.<span class="hljs-keyword">bin</span>`,wrap:!1}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Nl(u){let l,s="这个 <em>pytorch_model.bin</em> 文件就是众所周知的<em>state dictionary</em>; 它包含模型的所有权重。这两个文件齐头并进；配置是了解模型体系结构所必需的，而模型权重是模型的参数。";return{c(){l=_("p"),l.innerHTML=s},l(t){l=b(t,"P",{"data-svelte-h":!0}),$(l)!=="svelte-1jqpkc0"&&(l.innerHTML=s)},m(t,a){o(t,l,a)},d(t){t&&r(l)}}}function zl(u){let l,s="这个 <em>pytorch_model.bin</em> 文件就是众所周知的<em>state dictionary</em>; 它包含模型的所有权重。这两个文件齐头并进；配置是了解模型体系结构所必需的，而模型权重是模型的参数。";return{c(){l=_("p"),l.innerHTML=s},l(t){l=b(t,"P",{"data-svelte-h":!0}),$(l)!=="svelte-1jqpkc0"&&(l.innerHTML=s)},m(t,a){o(t,l,a)},d(t){t&&r(l)}}}function Ql(u){let l,s;return l=new C({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0Zi5jb25zdGFudChlbmNvZGVkX3NlcXVlbmNlcyk=",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

model_inputs = tf.constant(encoded_sequences)`,wrap:!1}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Al(u){let l,s;return l=new C({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b3JjaC50ZW5zb3IoZW5jb2RlZF9zZXF1ZW5jZXMp",highlighted:`<span class="hljs-keyword">import</span> torch

model_inputs = torch.tensor(encoded_sequences)`,wrap:!1}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,a){y(l,t,a),s=!0},i(t){s||(c(l.$$.fragment,t),s=!0)},o(t){m(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Hl(u){let l,s,t,a,w,i,h,Ne,T,J,ve,g,j,xe,Ze,z,xt="但是，如果您知道要使用的模型类型，则可以使用直接定义其体系结构的类。让我们看看这是如何与BERT模型一起工作的。",ze,Q,Qe,A,Zt="初始化BERT模型需要做的第一件事是加载配置对象：",Ae,v,x,Be,H,Bt="配置包含许多用于构建模型的属性：",He,q,qe,P,Pe,X,Ut="虽然您还没有看到所有这些属性都做了什么，但您应该认识到其中的一些属性：hidden<em>size属性定义了hidden</em>状态向量的大小，num_hidden_layers定义了Transformer模型的层数。",Xe,Y,Ye,F,Wt="从默认配置创建模型会使用随机值对其进行初始化：",Fe,Z,B,Ue,S,Et=`该模型可以在这种状态下使用，但会输出胡言乱语；首先需要对其进行训练。我们可以根据手头的任务从头开始训练模型，但正如您在
<a href="/course/chapter1">Chapter 1</a>
，这将需要很长的时间和大量的数据，并将产生不可忽视的环境影响。为了避免不必要的重复工作，必须能够共享和重用已经训练过的模型。`,Se,D,It=`加载已经训练过的Transformers模型很简单-我们可以使用from_pretrained()
方法：`,De,U,W,We,L,Rt="在上面的代码示例中，我们没有使用BertConfig",Le,K,Vt=`，而是通过Bert base cased标识符加载了一个预训练模型。这是一个模型检查点，由BERT的作者自己训练；您可以在
<a href="https://huggingface.co/bert-base-cased" rel="nofollow">model card</a>中找到更多细节.`,Ke,O,Gt="该模型现在使用检查点的所有权重进行初始化。它可以直接用于对训练过的任务进行推理，也可以对新任务进行微调。通过预先训练重量而不是从头开始的训练，我们可以很快取得好的效果。",Oe,ee,Nt=`权重已下载并缓存在缓存文件夹中（因此将来对from_pretrained()方法的调用将不会重新下载它们）默认为
~/.cache/huggingface/transformers
. 您可以通过设置
HF_HOME
环境变量来自定义缓存文件夹。`,et,te,zt=`用于加载模型的标识符可以是模型中心Hub上任何模型的标识符，只要它与BERT体系结构兼容。可以找到可用的BERT检查点的完整列表
<a href="https://huggingface.co/models?filter=bert" rel="nofollow">here</a>
.`,tt,le,lt,ne,Qt=`保存模型和加载模型一样简单—我们使用
save_pretrained()
方法，类似于
from_pretrained()
方法：`,nt,se,st,re,At="这会将两个文件保存到磁盘：",rt,E,I,Ee,oe,Ht=`如果你看一下
config.json
文件，您将识别构建模型体系结构所需的属性。该文件还包含一些元数据，例如检查点的来源以及上次保存检查点时使用的🤗 Transformers版本。`,ot,Ie,ae,at,ie,qt="既然您知道了如何加载和保存模型，那么让我们尝试使用它进行一些预测。Transformer模型只能处理数字——分词器生成的数字。但在我们讨论标记化器之前，让我们先探讨模型接受哪些输入。",it,pe,Pt="标记化器可以将输入转换为适当的框架张量，但为了帮助您了解发生了什么，我们将快速了解在将输入发送到模型之前必须做什么。",pt,fe,Xt="假设我们有几个序列：",ft,me,mt,ce,Yt=`分词器将这些转换为词汇表索引，通常称为
input IDs
. 每个序列现在都是一个数字列表！结果是：`,ct,ue,ut,_e,Ft="这是一个编码序列列表：一个列表列表。张量只接受矩形（想想矩阵）。此“数组”已为矩形，因此将其转换为张量很容易：",_t,R,V,Re,be,bt,$e,St="在模型中使用张量非常简单-我们只需将输入称为模型：",$t,Me,Mt,de,Dt=`虽然模型接受许多不同的参数，但只需要
input IDs。我们稍后将解释其他参数的作用以及何时需要它们，但首先我们需要更仔细地了解
Transformer模型可以理解的输入的标记`,dt,Ge,yt;w=new Tl({props:{fw:u[0]}}),h=new Ve({props:{title:"模型",local:"模型",headingTag:"h1"}});const Lt=[gl,Jl],ye=[];function Kt(e,n){return e[0]==="pt"?0:1}T=Kt(u),J=ye[T]=Lt[T](u);const Ot=[vl,jl],ke=[];function el(e,n){return e[0]==="pt"?0:1}g=el(u),j=ke[g]=Ot[g](u);function tl(e,n){return e[0]==="pt"?Zl:xl}let kt=tl(u),G=kt(u);Q=new Ve({props:{title:"创建转换器",local:"创建转换器",headingTag:"h2"}});const ll=[Ul,Bl],we=[];function nl(e,n){return e[0]==="pt"?0:1}v=nl(u),x=we[v]=ll[v](u),q=new C({props:{code:"cHJpbnQoY29uZmlnKQ==",highlighted:'<span class="hljs-built_in">print</span>(config)',wrap:!1}}),P=new C({props:{code:"QmVydENvbmZpZyUyMCU3QiUwQSUyMCUyMCU1Qi4uLiU1RCUwQSUyMCUyMCUyMmhpZGRlbl9zaXplJTIyJTNBJTIwNzY4JTJDJTBBJTIwJTIwJTIyaW50ZXJtZWRpYXRlX3NpemUlMjIlM0ElMjAzMDcyJTJDJTBBJTIwJTIwJTIybWF4X3Bvc2l0aW9uX2VtYmVkZGluZ3MlMjIlM0ElMjA1MTIlMkMlMEElMjAlMjAlMjJudW1fYXR0ZW50aW9uX2hlYWRzJTIyJTNBJTIwMTIlMkMlMEElMjAlMjAlMjJudW1faGlkZGVuX2xheWVycyUyMiUzQSUyMDEyJTJDJTBBJTIwJTIwJTVCLi4uJTVEJTBBJTdE",highlighted:`BertConfig {
  [...]
  <span class="hljs-string">&quot;hidden_size&quot;</span>: <span class="hljs-number">768</span>,
  <span class="hljs-string">&quot;intermediate_size&quot;</span>: <span class="hljs-number">3072</span>,
  <span class="hljs-string">&quot;max_position_embeddings&quot;</span>: <span class="hljs-number">512</span>,
  <span class="hljs-string">&quot;num_attention_heads&quot;</span>: <span class="hljs-number">12</span>,
  <span class="hljs-string">&quot;num_hidden_layers&quot;</span>: <span class="hljs-number">12</span>,
  [...]
}`,wrap:!1}}),Y=new Ve({props:{title:"不同的加载方式",local:"不同的加载方式",headingTag:"h3"}});const sl=[El,Wl],he=[];function rl(e,n){return e[0]==="pt"?0:1}Z=rl(u),B=he[Z]=sl[Z](u);const ol=[Rl,Il],Ce=[];function al(e,n){return e[0]==="pt"?0:1}U=al(u),W=Ce[U]=ol[U](u),le=new Ve({props:{title:"保存模型",local:"保存模型",headingTag:"h3"}}),se=new C({props:{code:"bW9kZWwuc2F2ZV9wcmV0cmFpbmVkKCUyMmRpcmVjdG9yeV9vbl9teV9jb21wdXRlciUyMik=",highlighted:'model.save_pretrained(<span class="hljs-string">&quot;directory_on_my_computer&quot;</span>)',wrap:!1}});const il=[Gl,Vl],Te=[];function pl(e,n){return e[0]==="pt"?0:1}E=pl(u),I=Te[E]=il[E](u);function fl(e,n){return e[0]==="pt"?zl:Nl}let wt=fl(u),N=wt(u);ae=new Ve({props:{title:"使用Transformers模型进行推理",local:"使用Transformers模型进行推理",headingTag:"h3"}}),me=new C({props:{code:"c2VxdWVuY2VzJTIwJTNEJTIwJTVCJTIySGVsbG8hJTIyJTJDJTIwJTIyQ29vbC4lMjIlMkMlMjAlMjJOaWNlISUyMiU1RA==",highlighted:'sequences = [<span class="hljs-string">&quot;Hello!&quot;</span>, <span class="hljs-string">&quot;Cool.&quot;</span>, <span class="hljs-string">&quot;Nice!&quot;</span>]',wrap:!1}}),ue=new C({props:{code:"ZW5jb2RlZF9zZXF1ZW5jZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlNUIxMDElMkMlMjA3NTkyJTJDJTIwOTk5JTJDJTIwMTAyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTVCMTAxJTJDJTIwNDY1OCUyQyUyMDEwMTIlMkMlMjAxMDIlNUQlMkMlMEElMjAlMjAlMjAlMjAlNUIxMDElMkMlMjAzODM1JTJDJTIwOTk5JTJDJTIwMTAyJTVEJTJDJTBBJTVE",highlighted:`encoded_sequences = [
    [<span class="hljs-number">101</span>, <span class="hljs-number">7592</span>, <span class="hljs-number">999</span>, <span class="hljs-number">102</span>],
    [<span class="hljs-number">101</span>, <span class="hljs-number">4658</span>, <span class="hljs-number">1012</span>, <span class="hljs-number">102</span>],
    [<span class="hljs-number">101</span>, <span class="hljs-number">3835</span>, <span class="hljs-number">999</span>, <span class="hljs-number">102</span>],
]`,wrap:!1}});const ml=[Al,Ql],Je=[];function cl(e,n){return e[0]==="pt"?0:1}return R=cl(u),V=Je[R]=ml[R](u),be=new Ve({props:{title:"使用张量作为模型的输入",local:"使用张量作为模型的输入",headingTag:"h3"}}),Me=new C({props:{code:"b3V0cHV0JTIwJTNEJTIwbW9kZWwobW9kZWxfaW5wdXRzKQ==",highlighted:"output = model(model_inputs)",wrap:!1}}),{c(){l=_("meta"),s=p(),t=_("p"),a=p(),M(w.$$.fragment),i=p(),M(h.$$.fragment),Ne=p(),J.c(),ve=p(),j.c(),xe=p(),G.c(),Ze=p(),z=_("p"),z.textContent=xt,ze=p(),M(Q.$$.fragment),Qe=p(),A=_("p"),A.textContent=Zt,Ae=p(),x.c(),Be=p(),H=_("p"),H.textContent=Bt,He=p(),M(q.$$.fragment),qe=p(),M(P.$$.fragment),Pe=p(),X=_("p"),X.innerHTML=Ut,Xe=p(),M(Y.$$.fragment),Ye=p(),F=_("p"),F.textContent=Wt,Fe=p(),B.c(),Ue=p(),S=_("p"),S.innerHTML=Et,Se=p(),D=_("p"),D.textContent=It,De=p(),W.c(),We=p(),L=_("p"),L.textContent=Rt,Le=p(),K=_("p"),K.innerHTML=Vt,Ke=p(),O=_("p"),O.textContent=Gt,Oe=p(),ee=_("p"),ee.textContent=Nt,et=p(),te=_("p"),te.innerHTML=zt,tt=p(),M(le.$$.fragment),lt=p(),ne=_("p"),ne.textContent=Qt,nt=p(),M(se.$$.fragment),st=p(),re=_("p"),re.textContent=At,rt=p(),I.c(),Ee=p(),oe=_("p"),oe.textContent=Ht,ot=p(),N.c(),Ie=p(),M(ae.$$.fragment),at=p(),ie=_("p"),ie.textContent=qt,it=p(),pe=_("p"),pe.textContent=Pt,pt=p(),fe=_("p"),fe.textContent=Xt,ft=p(),M(me.$$.fragment),mt=p(),ce=_("p"),ce.textContent=Yt,ct=p(),M(ue.$$.fragment),ut=p(),_e=_("p"),_e.textContent=Ft,_t=p(),V.c(),Re=p(),M(be.$$.fragment),bt=p(),$e=_("p"),$e.textContent=St,$t=p(),M(Me.$$.fragment),Mt=p(),de=_("p"),de.textContent=Dt,dt=p(),Ge=_("p"),this.h()},l(e){const n=hl("svelte-u9bgzb",document.head);l=b(n,"META",{name:!0,content:!0}),n.forEach(r),s=f(e),t=b(e,"P",{}),_l(t).forEach(r),a=f(e),d(w.$$.fragment,e),i=f(e),d(h.$$.fragment,e),Ne=f(e),J.l(e),ve=f(e),j.l(e),xe=f(e),G.l(e),Ze=f(e),z=b(e,"P",{"data-svelte-h":!0}),$(z)!=="svelte-tt4uzz"&&(z.textContent=xt),ze=f(e),d(Q.$$.fragment,e),Qe=f(e),A=b(e,"P",{"data-svelte-h":!0}),$(A)!=="svelte-18tv87c"&&(A.textContent=Zt),Ae=f(e),x.l(e),Be=f(e),H=b(e,"P",{"data-svelte-h":!0}),$(H)!=="svelte-v8dsqa"&&(H.textContent=Bt),He=f(e),d(q.$$.fragment,e),qe=f(e),d(P.$$.fragment,e),Pe=f(e),X=b(e,"P",{"data-svelte-h":!0}),$(X)!=="svelte-oqzyo"&&(X.innerHTML=Ut),Xe=f(e),d(Y.$$.fragment,e),Ye=f(e),F=b(e,"P",{"data-svelte-h":!0}),$(F)!=="svelte-j8x2kw"&&(F.textContent=Wt),Fe=f(e),B.l(e),Ue=f(e),S=b(e,"P",{"data-svelte-h":!0}),$(S)!=="svelte-qpa7bi"&&(S.innerHTML=Et),Se=f(e),D=b(e,"P",{"data-svelte-h":!0}),$(D)!=="svelte-1m8irc9"&&(D.textContent=It),De=f(e),W.l(e),We=f(e),L=b(e,"P",{"data-svelte-h":!0}),$(L)!=="svelte-1hrhay1"&&(L.textContent=Rt),Le=f(e),K=b(e,"P",{"data-svelte-h":!0}),$(K)!=="svelte-1yriz2a"&&(K.innerHTML=Vt),Ke=f(e),O=b(e,"P",{"data-svelte-h":!0}),$(O)!=="svelte-hx3jk3"&&(O.textContent=Gt),Oe=f(e),ee=b(e,"P",{"data-svelte-h":!0}),$(ee)!=="svelte-1d445xo"&&(ee.textContent=Nt),et=f(e),te=b(e,"P",{"data-svelte-h":!0}),$(te)!=="svelte-kgln3t"&&(te.innerHTML=zt),tt=f(e),d(le.$$.fragment,e),lt=f(e),ne=b(e,"P",{"data-svelte-h":!0}),$(ne)!=="svelte-1hgrzig"&&(ne.textContent=Qt),nt=f(e),d(se.$$.fragment,e),st=f(e),re=b(e,"P",{"data-svelte-h":!0}),$(re)!=="svelte-1teavnk"&&(re.textContent=At),rt=f(e),I.l(e),Ee=f(e),oe=b(e,"P",{"data-svelte-h":!0}),$(oe)!=="svelte-o4p7yz"&&(oe.textContent=Ht),ot=f(e),N.l(e),Ie=f(e),d(ae.$$.fragment,e),at=f(e),ie=b(e,"P",{"data-svelte-h":!0}),$(ie)!=="svelte-197h0hq"&&(ie.textContent=qt),it=f(e),pe=b(e,"P",{"data-svelte-h":!0}),$(pe)!=="svelte-lkjryd"&&(pe.textContent=Pt),pt=f(e),fe=b(e,"P",{"data-svelte-h":!0}),$(fe)!=="svelte-1tlmn49"&&(fe.textContent=Xt),ft=f(e),d(me.$$.fragment,e),mt=f(e),ce=b(e,"P",{"data-svelte-h":!0}),$(ce)!=="svelte-11cgrbu"&&(ce.textContent=Yt),ct=f(e),d(ue.$$.fragment,e),ut=f(e),_e=b(e,"P",{"data-svelte-h":!0}),$(_e)!=="svelte-1k3afhc"&&(_e.textContent=Ft),_t=f(e),V.l(e),Re=f(e),d(be.$$.fragment,e),bt=f(e),$e=b(e,"P",{"data-svelte-h":!0}),$($e)!=="svelte-1bstyzu"&&($e.textContent=St),$t=f(e),d(Me.$$.fragment,e),Mt=f(e),de=b(e,"P",{"data-svelte-h":!0}),$(de)!=="svelte-1s7d6la"&&(de.textContent=Dt),dt=f(e),Ge=b(e,"P",{}),_l(Ge).forEach(r),this.h()},h(){bl(l,"name","hf:doc:metadata"),bl(l,"content",ql)},m(e,n){Cl(document.head,l),o(e,s,n),o(e,t,n),o(e,a,n),y(w,e,n),o(e,i,n),y(h,e,n),o(e,Ne,n),ye[T].m(e,n),o(e,ve,n),ke[g].m(e,n),o(e,xe,n),G.m(e,n),o(e,Ze,n),o(e,z,n),o(e,ze,n),y(Q,e,n),o(e,Qe,n),o(e,A,n),o(e,Ae,n),we[v].m(e,n),o(e,Be,n),o(e,H,n),o(e,He,n),y(q,e,n),o(e,qe,n),y(P,e,n),o(e,Pe,n),o(e,X,n),o(e,Xe,n),y(Y,e,n),o(e,Ye,n),o(e,F,n),o(e,Fe,n),he[Z].m(e,n),o(e,Ue,n),o(e,S,n),o(e,Se,n),o(e,D,n),o(e,De,n),Ce[U].m(e,n),o(e,We,n),o(e,L,n),o(e,Le,n),o(e,K,n),o(e,Ke,n),o(e,O,n),o(e,Oe,n),o(e,ee,n),o(e,et,n),o(e,te,n),o(e,tt,n),y(le,e,n),o(e,lt,n),o(e,ne,n),o(e,nt,n),y(se,e,n),o(e,st,n),o(e,re,n),o(e,rt,n),Te[E].m(e,n),o(e,Ee,n),o(e,oe,n),o(e,ot,n),N.m(e,n),o(e,Ie,n),y(ae,e,n),o(e,at,n),o(e,ie,n),o(e,it,n),o(e,pe,n),o(e,pt,n),o(e,fe,n),o(e,ft,n),y(me,e,n),o(e,mt,n),o(e,ce,n),o(e,ct,n),y(ue,e,n),o(e,ut,n),o(e,_e,n),o(e,_t,n),Je[R].m(e,n),o(e,Re,n),y(be,e,n),o(e,bt,n),o(e,$e,n),o(e,$t,n),y(Me,e,n),o(e,Mt,n),o(e,de,n),o(e,dt,n),o(e,Ge,n),yt=!0},p(e,[n]){const ul={};n&1&&(ul.fw=e[0]),w.$set(ul);let ht=T;T=Kt(e),T!==ht&&(je(),m(ye[ht],1,1,()=>{ye[ht]=null}),ge(),J=ye[T],J||(J=ye[T]=Lt[T](e),J.c()),c(J,1),J.m(ve.parentNode,ve));let Ct=g;g=el(e),g!==Ct&&(je(),m(ke[Ct],1,1,()=>{ke[Ct]=null}),ge(),j=ke[g],j||(j=ke[g]=Ot[g](e),j.c()),c(j,1),j.m(xe.parentNode,xe)),kt!==(kt=tl(e))&&(G.d(1),G=kt(e),G&&(G.c(),G.m(Ze.parentNode,Ze)));let Tt=v;v=nl(e),v!==Tt&&(je(),m(we[Tt],1,1,()=>{we[Tt]=null}),ge(),x=we[v],x||(x=we[v]=ll[v](e),x.c()),c(x,1),x.m(Be.parentNode,Be));let Jt=Z;Z=rl(e),Z!==Jt&&(je(),m(he[Jt],1,1,()=>{he[Jt]=null}),ge(),B=he[Z],B||(B=he[Z]=sl[Z](e),B.c()),c(B,1),B.m(Ue.parentNode,Ue));let gt=U;U=al(e),U!==gt&&(je(),m(Ce[gt],1,1,()=>{Ce[gt]=null}),ge(),W=Ce[U],W||(W=Ce[U]=ol[U](e),W.c()),c(W,1),W.m(We.parentNode,We));let jt=E;E=pl(e),E!==jt&&(je(),m(Te[jt],1,1,()=>{Te[jt]=null}),ge(),I=Te[E],I||(I=Te[E]=il[E](e),I.c()),c(I,1),I.m(Ee.parentNode,Ee)),wt!==(wt=fl(e))&&(N.d(1),N=wt(e),N&&(N.c(),N.m(Ie.parentNode,Ie)));let vt=R;R=cl(e),R!==vt&&(je(),m(Je[vt],1,1,()=>{Je[vt]=null}),ge(),V=Je[R],V||(V=Je[R]=ml[R](e),V.c()),c(V,1),V.m(Re.parentNode,Re))},i(e){yt||(c(w.$$.fragment,e),c(h.$$.fragment,e),c(J),c(j),c(Q.$$.fragment,e),c(x),c(q.$$.fragment,e),c(P.$$.fragment,e),c(Y.$$.fragment,e),c(B),c(W),c(le.$$.fragment,e),c(se.$$.fragment,e),c(I),c(ae.$$.fragment,e),c(me.$$.fragment,e),c(ue.$$.fragment,e),c(V),c(be.$$.fragment,e),c(Me.$$.fragment,e),yt=!0)},o(e){m(w.$$.fragment,e),m(h.$$.fragment,e),m(J),m(j),m(Q.$$.fragment,e),m(x),m(q.$$.fragment,e),m(P.$$.fragment,e),m(Y.$$.fragment,e),m(B),m(W),m(le.$$.fragment,e),m(se.$$.fragment,e),m(I),m(ae.$$.fragment,e),m(me.$$.fragment,e),m(ue.$$.fragment,e),m(V),m(be.$$.fragment,e),m(Me.$$.fragment,e),yt=!1},d(e){e&&(r(s),r(t),r(a),r(i),r(Ne),r(ve),r(xe),r(Ze),r(z),r(ze),r(Qe),r(A),r(Ae),r(Be),r(H),r(He),r(qe),r(Pe),r(X),r(Xe),r(Ye),r(F),r(Fe),r(Ue),r(S),r(Se),r(D),r(De),r(We),r(L),r(Le),r(K),r(Ke),r(O),r(Oe),r(ee),r(et),r(te),r(tt),r(lt),r(ne),r(nt),r(st),r(re),r(rt),r(Ee),r(oe),r(ot),r(Ie),r(at),r(ie),r(it),r(pe),r(pt),r(fe),r(ft),r(mt),r(ce),r(ct),r(ut),r(_e),r(_t),r(Re),r(bt),r($e),r($t),r(Mt),r(de),r(dt),r(Ge)),r(l),k(w,e),k(h,e),ye[T].d(e),ke[g].d(e),G.d(e),k(Q,e),we[v].d(e),k(q,e),k(P,e),k(Y,e),he[Z].d(e),Ce[U].d(e),k(le,e),k(se,e),Te[E].d(e),N.d(e),k(ae,e),k(me,e),k(ue,e),Je[R].d(e),k(be,e),k(Me,e)}}}const ql='{"title":"模型","local":"模型","sections":[{"title":"创建转换器","local":"创建转换器","sections":[{"title":"不同的加载方式","local":"不同的加载方式","sections":[],"depth":3},{"title":"保存模型","local":"保存模型","sections":[],"depth":3},{"title":"使用Transformers模型进行推理","local":"使用Transformers模型进行推理","sections":[],"depth":3},{"title":"使用张量作为模型的输入","local":"使用张量作为模型的输入","sections":[],"depth":3}],"depth":2}],"depth":1}';function Pl(u,l,s){let t="pt";return yl(()=>{const a=new URLSearchParams(window.location.search);s(0,t=a.get("fw")||"pt")}),[t]}class Ol extends kl{constructor(l){super(),wl(this,l,Pl,Hl,dl,{})}}export{Ol as component};
