import{s as Ml,o as $l}from"../chunks/scheduler.37c15a92.js";import{S as yl,i as kl,g as b,s as p,r as M,A as Tl,h as _,f as r,c as m,j as ul,u as $,x as d,k as bl,y as wl,a as i,v as y,t as c,b as je,d as f,w as k,p as Ce}from"../chunks/index.2bf4358c.js";import{Y as _l}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as dl}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as hl}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as He,E as Jl}from"../chunks/EditOnGithub.8916dc7c.js";function gl(u){let l,s;return l=new dl({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function jl(u){let l,s;return l=new dl({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Cl(u){let l,s;return l=new _l({props:{id:"d3JVgghSOew"}}),{c(){M(l.$$.fragment)},l(t){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Zl(u){let l,s=`在本节中，我们将更详细地了解如何创建和使用模型。我们将使用
AutoModel类，它极大程度的方便您从<em>checkpoint</em>实例化任何模型。`,t,o,T="AutoModel 类与其相关类本质上是对库中各种模型的简化包装。其智能之处在于能够自动识别检查点所对应的模型架构，并据此实例化相应的模型。";return{c(){l=b("p"),l.innerHTML=s,t=p(),o=b("p"),o.textContent=T},l(a){l=_(a,"P",{"data-svelte-h":!0}),d(l)!=="svelte-5vmkrr"&&(l.innerHTML=s),t=m(a),o=_(a,"P",{"data-svelte-h":!0}),d(o)!=="svelte-obubxl"&&(o.textContent=T)},m(a,w){i(a,l,w),i(a,t,w),i(a,o,w)},d(a){a&&(r(l),r(t),r(o))}}}function Bl(u){let l,s=`在本节中，我们将更详细地了解如何创建和使用模型。我们将使用
AutoModel类，它极大程度的方便您从<em>checkpoint</em>实例化任何模型。`,t,o,T="AutoModel 类与其相关类本质上是对库中各种模型的简化包装。其智能之处在于能够自动识别检查点所对应的模型架构，并据此实例化相应的模型。";return{c(){l=b("p"),l.innerHTML=s,t=p(),o=b("p"),o.textContent=T},l(a){l=_(a,"P",{"data-svelte-h":!0}),d(l)!=="svelte-5vmkrr"&&(l.innerHTML=s),t=m(a),o=_(a,"P",{"data-svelte-h":!0}),d(o)!=="svelte-obubxl"&&(o.textContent=T)},m(a,w){i(a,l,w),i(a,t,w),i(a,o,w)},d(a){a&&(r(l),r(t),r(o))}}}function Ul(u){let l,s;return l=new h({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Wl(u){let l,s;return l=new h({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function El(u){let l,s;return l=new h({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function xl(u){let l,s;return l=new h({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Il(u){let l,s,t,o="正如您之前看到的，我们可以用等效的<code>AutoModel</code>替换<code>BertModel</code>类。从现在开始，我们将这样做，因为这会产生检查点不可知的代码；如果您的代码适用于一个<em>checkpoint</em>，那么它应该与另一个<em>checkpoint</em>无缝地工作。即使体系结构不同，这也适用，只要检查点是针对类似任务（例如，情绪分析任务）训练的。",T;return l=new h({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=b("p"),t.innerHTML=o},l(a){$(l.$$.fragment,a),s=m(a),t=_(a,"P",{"data-svelte-h":!0}),d(t)!=="svelte-1b9o1wr"&&(t.innerHTML=o)},m(a,w){y(l,a,w),i(a,s,w),i(a,t,w),T=!0},i(a){T||(f(l.$$.fragment,a),T=!0)},o(a){c(l.$$.fragment,a),T=!1},d(a){a&&(r(s),r(t)),k(l,a)}}}function Rl(u){let l,s,t,o="正如您之前看到的，我们可以用等效的<code>AutoModel</code>类替换<code>BertModel</code>类。从现在开始，我们将这样做，因为这会产生检查点不可知的代码；如果您的代码适用于一个<em>checkpoint</em>，那么它应该与另一个<em>checkpoint</em>无缝地工作。即使体系结构不同，这也适用，只要检查点是针对类似任务（例如，情绪分析任务）训练的。",T;return l=new h({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=b("p"),t.innerHTML=o},l(a){$(l.$$.fragment,a),s=m(a),t=_(a,"P",{"data-svelte-h":!0}),d(t)!=="svelte-1ejcwis"&&(t.innerHTML=o)},m(a,w){y(l,a,w),i(a,s,w),i(a,t,w),T=!0},i(a){T||(f(l.$$.fragment,a),T=!0)},o(a){c(l.$$.fragment,a),T=!1},d(a){a&&(r(s),r(t)),k(l,a)}}}function Hl(u){let l,s;return l=new h({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Vl(u){let l,s;return l=new h({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Gl(u){let l,s="这个 <em>tf_model.h5</em> 文件就是众所周知的<em>state dictionary</em>; 它包含模型的所有权重。这两个文件密切相关；这个配置是了解您的模型架构所必需的，而模型权重则是您模型的参数。";return{c(){l=b("p"),l.innerHTML=s},l(t){l=_(t,"P",{"data-svelte-h":!0}),d(l)!=="svelte-cqqdy9"&&(l.innerHTML=s)},m(t,o){i(t,l,o)},d(t){t&&r(l)}}}function Nl(u){let l,s="这个 <em>pytorch_model.bin</em> 文件就是众所周知的<em>state dictionary</em>; 它包含模型的所有权重。这两个文件密切相关；这个配置是了解您的模型架构所必需的，而模型权重则是您模型的参数。";return{c(){l=b("p"),l.innerHTML=s},l(t){l=_(t,"P",{"data-svelte-h":!0}),d(l)!=="svelte-4rvj0o"&&(l.innerHTML=s)},m(t,o){i(t,l,o)},d(t){t&&r(l)}}}function zl(u){let l,s;return l=new h({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Ql(u){let l,s;return l=new h({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){$(l.$$.fragment,t)},m(t,o){y(l,t,o),s=!0},i(t){s||(f(l.$$.fragment,t),s=!0)},o(t){c(l.$$.fragment,t),s=!1},d(t){k(l,t)}}}function Ll(u){let l,s,t,o,T,a,w,Ge,J,g,ve,j,C,Ze,Be,N,Zt="如果您知道要使用的模型类型，则可以使用直接定义其体系结构的类。让我们看看这是如何与BERT模型一起工作的。",Ne,z,ze,Q,Bt="初始化BERT模型需要做的第一件事是加载配置对象：",Qe,v,Z,Ue,L,Ut="配置包含许多用于构建模型的属性：",Le,A,Ae,q,qe,X,Wt="虽然您还没有看到所有这些属性都做了什么，但您应该认识到其中的一些属性：<code>hidden_size</code>属性定义了<code>hidden_states</code>向量的大小，<code>num_hidden_layers</code>定义了Transformer模型的层数。",Xe,Y,Ye,P,Et="从默认配置创建模型会使用随机值对其进行初始化：",Pe,B,U,We,F,xt=`该模型可以在这种状态下使用，但会输出胡言乱语；首先需要对其进行训练，我们可以根据手头的任务从头开始训练模型，但正如您在
<a href="/course/chapter1">Chapter 1</a>
所见，这将需要很长的时间和大量的数据，并将产生不可忽视的环境影响。为了避免不必要的重复工作，必须能够共享和重用已经训练过的模型。`,Fe,S,It=`加载已经训练过的Transformers模型很简单-我们可以使用<code>from_pretrained()</code>
方法：`,Se,W,E,Ee,D,Rt=`在上面的代码示例中，我们没有使用BertConfig，而是通过<code>bert-base-cased</code>标识符加载了一个预训练模型。这是一个模型检查点，由<code>BERT</code>的作者自己训练；您可以在
<a href="https://huggingface.co/bert-base-cased" rel="nofollow">model card</a>中找到更多细节.`,De,K,Ht="该模型现在使用<em>checkpoint</em>的所有权重进行初始化。它可以直接用于对训练过的任务进行推理，也可以对新任务进行微调。通过预先训练重量而不是从头开始的训练，我们可以很快取得好的效果。",Ke,O,Vt=`权重已下载并缓存在缓存文件夹中（因此将来对from_pretrained()方法的调用将不会重新下载它们）默认为
~/.cache/huggingface/transformers
. 您可以通过设置
HF_HOME
环境变量来自定义缓存文件夹。`,Oe,ee,Gt=`用于加载模型的标识符可以是模型中心Hub上任何模型的标识符，只要它与<code>BERT</code>体系结构兼容。可以找到可用的<code>BERT</code><em>checkpoint</em>的完整列表
<a href="https://huggingface.co/models?filter=bert" rel="nofollow">here</a>
.`,et,te,tt,le,Nt=`保存模型和加载模型一样简单—我们使用
save_pretrained()
方法，类似于
from_pretrained()
方法：`,lt,ne,nt,se,zt="这会将两个文件保存到磁盘：",st,x,I,xe,re,Qt=`如果你看一下
config.json
文件，您将识别构建模型体系结构所需的属性。该文件还包含一些元数据，例如<em>checkpoint</em>的来源以及上次保存检查点时使用的🤗 Transformers版本。`,rt,Ie,ie,it,oe,Lt="既然您知道了如何加载和保存模型，那么让我们尝试使用它进行一些预测。Transformer模型只能处理数字——分词器生成的数字。但在我们讨论<em>Tokenizer</em>之前，让我们先探讨模型接受哪些输入。",ot,ae,At="<em>Tokenizer</em>可以将输入转换为适当的框架张量，但为了帮助您了解发生了什么，我们将快速了解在将输入发送到模型之前必须做什么。",at,pe,qt="假设我们有几个序列：",pt,me,mt,ce,Xt=`<em>Tokenizer</em>将这些转换为词汇表索引，通常称为
<em>input IDs</em>
. 每个序列现在都是一个数字列表！结果是：`,ct,fe,ft,ue,Yt="这是一个编码序列的列表：一个嵌套列表（列表的列表）。张量只接受矩形形状（可以想象成矩阵）。这个“数组”已经是矩形形状，因此将其转换为张量很容易：",ut,R,H,Re,be,bt,_e,Pt="在模型中使用张量非常简单-我们只需将输入称为模型：",_t,de,dt,Me,Ft="虽然模型接受许多不同的参数，但只有输入 ID 是必需的。 我们将在后面解释其他参数的作用以及何时需要它们，但首先我们需要仔细研究构建 Transformer 模型可以理解的输入的<em>tokenizer</em>。",Mt,$e,$t,Ve,yt;T=new hl({props:{fw:u[0]}}),w=new He({props:{title:"模型",local:"模型",headingTag:"h1"}});const St=[jl,gl],ye=[];function Dt(e,n){return e[0]==="pt"?0:1}J=Dt(u),g=ye[J]=St[J](u);const Kt=[vl,Cl],ke=[];function Ot(e,n){return e[0]==="pt"?0:1}j=Ot(u),C=ke[j]=Kt[j](u);function el(e,n){return e[0]==="pt"?Bl:Zl}let kt=el(u),V=kt(u);z=new He({props:{title:"创建转换器",local:"创建转换器",headingTag:"h2"}});const tl=[Wl,Ul],Te=[];function ll(e,n){return e[0]==="pt"?0:1}v=ll(u),Z=Te[v]=tl[v](u),A=new h({props:{code:"cHJpbnQoY29uZmlnKQ==",highlighted:'<span class="hljs-built_in">print</span>(config)',wrap:!1}}),q=new h({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 He({props:{title:"不同的加载方式",local:"不同的加载方式",headingTag:"h3"}});const nl=[xl,El],we=[];function sl(e,n){return e[0]==="pt"?0:1}B=sl(u),U=we[B]=nl[B](u);const rl=[Rl,Il],he=[];function il(e,n){return e[0]==="pt"?0:1}W=il(u),E=he[W]=rl[W](u),te=new He({props:{title:"保存模型",local:"保存模型",headingTag:"h3"}}),ne=new h({props:{code:"bW9kZWwuc2F2ZV9wcmV0cmFpbmVkKCUyMmRpcmVjdG9yeV9vbl9teV9jb21wdXRlciUyMik=",highlighted:'model.save_pretrained(<span class="hljs-string">&quot;directory_on_my_computer&quot;</span>)',wrap:!1}});const ol=[Vl,Hl],Je=[];function al(e,n){return e[0]==="pt"?0:1}x=al(u),I=Je[x]=ol[x](u);function pl(e,n){return e[0]==="pt"?Nl:Gl}let Tt=pl(u),G=Tt(u);ie=new He({props:{title:"使用Transformers模型进行推理",local:"使用Transformers模型进行推理",headingTag:"h3"}}),me=new h({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}}),fe=new h({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=[Ql,zl],ge=[];function cl(e,n){return e[0]==="pt"?0:1}return R=cl(u),H=ge[R]=ml[R](u),be=new He({props:{title:"使用张量作为模型的输入",local:"使用张量作为模型的输入",headingTag:"h3"}}),de=new h({props:{code:"b3V0cHV0JTIwJTNEJTIwbW9kZWwobW9kZWxfaW5wdXRzKQ==",highlighted:"output = model(model_inputs)",wrap:!1}}),$e=new Jl({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter2/3.mdx"}}),{c(){l=b("meta"),s=p(),t=b("p"),o=p(),M(T.$$.fragment),a=p(),M(w.$$.fragment),Ge=p(),g.c(),ve=p(),C.c(),Ze=p(),V.c(),Be=p(),N=b("p"),N.textContent=Zt,Ne=p(),M(z.$$.fragment),ze=p(),Q=b("p"),Q.textContent=Bt,Qe=p(),Z.c(),Ue=p(),L=b("p"),L.textContent=Ut,Le=p(),M(A.$$.fragment),Ae=p(),M(q.$$.fragment),qe=p(),X=b("p"),X.innerHTML=Wt,Xe=p(),M(Y.$$.fragment),Ye=p(),P=b("p"),P.textContent=Et,Pe=p(),U.c(),We=p(),F=b("p"),F.innerHTML=xt,Fe=p(),S=b("p"),S.innerHTML=It,Se=p(),E.c(),Ee=p(),D=b("p"),D.innerHTML=Rt,De=p(),K=b("p"),K.innerHTML=Ht,Ke=p(),O=b("p"),O.textContent=Vt,Oe=p(),ee=b("p"),ee.innerHTML=Gt,et=p(),M(te.$$.fragment),tt=p(),le=b("p"),le.textContent=Nt,lt=p(),M(ne.$$.fragment),nt=p(),se=b("p"),se.textContent=zt,st=p(),I.c(),xe=p(),re=b("p"),re.innerHTML=Qt,rt=p(),G.c(),Ie=p(),M(ie.$$.fragment),it=p(),oe=b("p"),oe.innerHTML=Lt,ot=p(),ae=b("p"),ae.innerHTML=At,at=p(),pe=b("p"),pe.textContent=qt,pt=p(),M(me.$$.fragment),mt=p(),ce=b("p"),ce.innerHTML=Xt,ct=p(),M(fe.$$.fragment),ft=p(),ue=b("p"),ue.textContent=Yt,ut=p(),H.c(),Re=p(),M(be.$$.fragment),bt=p(),_e=b("p"),_e.textContent=Pt,_t=p(),M(de.$$.fragment),dt=p(),Me=b("p"),Me.innerHTML=Ft,Mt=p(),M($e.$$.fragment),$t=p(),Ve=b("p"),this.h()},l(e){const n=Tl("svelte-u9bgzb",document.head);l=_(n,"META",{name:!0,content:!0}),n.forEach(r),s=m(e),t=_(e,"P",{}),ul(t).forEach(r),o=m(e),$(T.$$.fragment,e),a=m(e),$(w.$$.fragment,e),Ge=m(e),g.l(e),ve=m(e),C.l(e),Ze=m(e),V.l(e),Be=m(e),N=_(e,"P",{"data-svelte-h":!0}),d(N)!=="svelte-i15tde"&&(N.textContent=Zt),Ne=m(e),$(z.$$.fragment,e),ze=m(e),Q=_(e,"P",{"data-svelte-h":!0}),d(Q)!=="svelte-18tv87c"&&(Q.textContent=Bt),Qe=m(e),Z.l(e),Ue=m(e),L=_(e,"P",{"data-svelte-h":!0}),d(L)!=="svelte-v8dsqa"&&(L.textContent=Ut),Le=m(e),$(A.$$.fragment,e),Ae=m(e),$(q.$$.fragment,e),qe=m(e),X=_(e,"P",{"data-svelte-h":!0}),d(X)!=="svelte-1sb4kbb"&&(X.innerHTML=Wt),Xe=m(e),$(Y.$$.fragment,e),Ye=m(e),P=_(e,"P",{"data-svelte-h":!0}),d(P)!=="svelte-j8x2kw"&&(P.textContent=Et),Pe=m(e),U.l(e),We=m(e),F=_(e,"P",{"data-svelte-h":!0}),d(F)!=="svelte-67mun1"&&(F.innerHTML=xt),Fe=m(e),S=_(e,"P",{"data-svelte-h":!0}),d(S)!=="svelte-7qvbvw"&&(S.innerHTML=It),Se=m(e),E.l(e),Ee=m(e),D=_(e,"P",{"data-svelte-h":!0}),d(D)!=="svelte-15wil7"&&(D.innerHTML=Rt),De=m(e),K=_(e,"P",{"data-svelte-h":!0}),d(K)!=="svelte-l5qov6"&&(K.innerHTML=Ht),Ke=m(e),O=_(e,"P",{"data-svelte-h":!0}),d(O)!=="svelte-1d445xo"&&(O.textContent=Vt),Oe=m(e),ee=_(e,"P",{"data-svelte-h":!0}),d(ee)!=="svelte-4t1f4a"&&(ee.innerHTML=Gt),et=m(e),$(te.$$.fragment,e),tt=m(e),le=_(e,"P",{"data-svelte-h":!0}),d(le)!=="svelte-1hgrzig"&&(le.textContent=Nt),lt=m(e),$(ne.$$.fragment,e),nt=m(e),se=_(e,"P",{"data-svelte-h":!0}),d(se)!=="svelte-1teavnk"&&(se.textContent=zt),st=m(e),I.l(e),xe=m(e),re=_(e,"P",{"data-svelte-h":!0}),d(re)!=="svelte-8esd5o"&&(re.innerHTML=Qt),rt=m(e),G.l(e),Ie=m(e),$(ie.$$.fragment,e),it=m(e),oe=_(e,"P",{"data-svelte-h":!0}),d(oe)!=="svelte-ofpx6f"&&(oe.innerHTML=Lt),ot=m(e),ae=_(e,"P",{"data-svelte-h":!0}),d(ae)!=="svelte-bcgkx6"&&(ae.innerHTML=At),at=m(e),pe=_(e,"P",{"data-svelte-h":!0}),d(pe)!=="svelte-1tlmn49"&&(pe.textContent=qt),pt=m(e),$(me.$$.fragment,e),mt=m(e),ce=_(e,"P",{"data-svelte-h":!0}),d(ce)!=="svelte-13qwg3k"&&(ce.innerHTML=Xt),ct=m(e),$(fe.$$.fragment,e),ft=m(e),ue=_(e,"P",{"data-svelte-h":!0}),d(ue)!=="svelte-qmktmi"&&(ue.textContent=Yt),ut=m(e),H.l(e),Re=m(e),$(be.$$.fragment,e),bt=m(e),_e=_(e,"P",{"data-svelte-h":!0}),d(_e)!=="svelte-1bstyzu"&&(_e.textContent=Pt),_t=m(e),$(de.$$.fragment,e),dt=m(e),Me=_(e,"P",{"data-svelte-h":!0}),d(Me)!=="svelte-1v2jqy4"&&(Me.innerHTML=Ft),Mt=m(e),$($e.$$.fragment,e),$t=m(e),Ve=_(e,"P",{}),ul(Ve).forEach(r),this.h()},h(){bl(l,"name","hf:doc:metadata"),bl(l,"content",Al)},m(e,n){wl(document.head,l),i(e,s,n),i(e,t,n),i(e,o,n),y(T,e,n),i(e,a,n),y(w,e,n),i(e,Ge,n),ye[J].m(e,n),i(e,ve,n),ke[j].m(e,n),i(e,Ze,n),V.m(e,n),i(e,Be,n),i(e,N,n),i(e,Ne,n),y(z,e,n),i(e,ze,n),i(e,Q,n),i(e,Qe,n),Te[v].m(e,n),i(e,Ue,n),i(e,L,n),i(e,Le,n),y(A,e,n),i(e,Ae,n),y(q,e,n),i(e,qe,n),i(e,X,n),i(e,Xe,n),y(Y,e,n),i(e,Ye,n),i(e,P,n),i(e,Pe,n),we[B].m(e,n),i(e,We,n),i(e,F,n),i(e,Fe,n),i(e,S,n),i(e,Se,n),he[W].m(e,n),i(e,Ee,n),i(e,D,n),i(e,De,n),i(e,K,n),i(e,Ke,n),i(e,O,n),i(e,Oe,n),i(e,ee,n),i(e,et,n),y(te,e,n),i(e,tt,n),i(e,le,n),i(e,lt,n),y(ne,e,n),i(e,nt,n),i(e,se,n),i(e,st,n),Je[x].m(e,n),i(e,xe,n),i(e,re,n),i(e,rt,n),G.m(e,n),i(e,Ie,n),y(ie,e,n),i(e,it,n),i(e,oe,n),i(e,ot,n),i(e,ae,n),i(e,at,n),i(e,pe,n),i(e,pt,n),y(me,e,n),i(e,mt,n),i(e,ce,n),i(e,ct,n),y(fe,e,n),i(e,ft,n),i(e,ue,n),i(e,ut,n),ge[R].m(e,n),i(e,Re,n),y(be,e,n),i(e,bt,n),i(e,_e,n),i(e,_t,n),y(de,e,n),i(e,dt,n),i(e,Me,n),i(e,Mt,n),y($e,e,n),i(e,$t,n),i(e,Ve,n),yt=!0},p(e,[n]){const fl={};n&1&&(fl.fw=e[0]),T.$set(fl);let wt=J;J=Dt(e),J!==wt&&(Ce(),c(ye[wt],1,1,()=>{ye[wt]=null}),je(),g=ye[J],g||(g=ye[J]=St[J](e),g.c()),f(g,1),g.m(ve.parentNode,ve));let ht=j;j=Ot(e),j!==ht&&(Ce(),c(ke[ht],1,1,()=>{ke[ht]=null}),je(),C=ke[j],C||(C=ke[j]=Kt[j](e),C.c()),f(C,1),C.m(Ze.parentNode,Ze)),kt!==(kt=el(e))&&(V.d(1),V=kt(e),V&&(V.c(),V.m(Be.parentNode,Be)));let Jt=v;v=ll(e),v!==Jt&&(Ce(),c(Te[Jt],1,1,()=>{Te[Jt]=null}),je(),Z=Te[v],Z||(Z=Te[v]=tl[v](e),Z.c()),f(Z,1),Z.m(Ue.parentNode,Ue));let gt=B;B=sl(e),B!==gt&&(Ce(),c(we[gt],1,1,()=>{we[gt]=null}),je(),U=we[B],U||(U=we[B]=nl[B](e),U.c()),f(U,1),U.m(We.parentNode,We));let jt=W;W=il(e),W!==jt&&(Ce(),c(he[jt],1,1,()=>{he[jt]=null}),je(),E=he[W],E||(E=he[W]=rl[W](e),E.c()),f(E,1),E.m(Ee.parentNode,Ee));let Ct=x;x=al(e),x!==Ct&&(Ce(),c(Je[Ct],1,1,()=>{Je[Ct]=null}),je(),I=Je[x],I||(I=Je[x]=ol[x](e),I.c()),f(I,1),I.m(xe.parentNode,xe)),Tt!==(Tt=pl(e))&&(G.d(1),G=Tt(e),G&&(G.c(),G.m(Ie.parentNode,Ie)));let vt=R;R=cl(e),R!==vt&&(Ce(),c(ge[vt],1,1,()=>{ge[vt]=null}),je(),H=ge[R],H||(H=ge[R]=ml[R](e),H.c()),f(H,1),H.m(Re.parentNode,Re))},i(e){yt||(f(T.$$.fragment,e),f(w.$$.fragment,e),f(g),f(C),f(z.$$.fragment,e),f(Z),f(A.$$.fragment,e),f(q.$$.fragment,e),f(Y.$$.fragment,e),f(U),f(E),f(te.$$.fragment,e),f(ne.$$.fragment,e),f(I),f(ie.$$.fragment,e),f(me.$$.fragment,e),f(fe.$$.fragment,e),f(H),f(be.$$.fragment,e),f(de.$$.fragment,e),f($e.$$.fragment,e),yt=!0)},o(e){c(T.$$.fragment,e),c(w.$$.fragment,e),c(g),c(C),c(z.$$.fragment,e),c(Z),c(A.$$.fragment,e),c(q.$$.fragment,e),c(Y.$$.fragment,e),c(U),c(E),c(te.$$.fragment,e),c(ne.$$.fragment,e),c(I),c(ie.$$.fragment,e),c(me.$$.fragment,e),c(fe.$$.fragment,e),c(H),c(be.$$.fragment,e),c(de.$$.fragment,e),c($e.$$.fragment,e),yt=!1},d(e){e&&(r(s),r(t),r(o),r(a),r(Ge),r(ve),r(Ze),r(Be),r(N),r(Ne),r(ze),r(Q),r(Qe),r(Ue),r(L),r(Le),r(Ae),r(qe),r(X),r(Xe),r(Ye),r(P),r(Pe),r(We),r(F),r(Fe),r(S),r(Se),r(Ee),r(D),r(De),r(K),r(Ke),r(O),r(Oe),r(ee),r(et),r(tt),r(le),r(lt),r(nt),r(se),r(st),r(xe),r(re),r(rt),r(Ie),r(it),r(oe),r(ot),r(ae),r(at),r(pe),r(pt),r(mt),r(ce),r(ct),r(ft),r(ue),r(ut),r(Re),r(bt),r(_e),r(_t),r(dt),r(Me),r(Mt),r($t),r(Ve)),r(l),k(T,e),k(w,e),ye[J].d(e),ke[j].d(e),V.d(e),k(z,e),Te[v].d(e),k(A,e),k(q,e),k(Y,e),we[B].d(e),he[W].d(e),k(te,e),k(ne,e),Je[x].d(e),G.d(e),k(ie,e),k(me,e),k(fe,e),ge[R].d(e),k(be,e),k(de,e),k($e,e)}}}const Al='{"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 ql(u,l,s){let t="pt";return $l(()=>{const o=new URLSearchParams(window.location.search);s(0,t=o.get("fw")||"pt")}),[t]}class Ol extends yl{constructor(l){super(),kl(this,l,ql,Ll,Ml,{})}}export{Ol as component};
