import{s as Ml,o as dl}from"../chunks/scheduler.37c15a92.js";import{S as kl,i as wl,g as _,s as p,r as y,A as Cl,h as b,f as r,c as f,j as _l,u as M,x as $,k as bl,y as Jl,a as o,v as d,t as m,b as he,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 as J}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as yl}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as gl}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ve}from"../chunks/Heading.8ada512a.js";function Tl(u){let l,s;return l=new yl({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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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;return l=new yl({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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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-u0ngs0"&&(l.textContent=s),t=f(i),a=b(i,"P",{"data-svelte-h":!0}),$(a)!=="svelte-muuwa9"&&(a.textContent=w)},m(i,C){o(i,l,C),o(i,t,C),o(i,a,C)},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-u0ngs0"&&(l.textContent=s),t=f(i),a=b(i,"P",{"data-svelte-h":!0}),$(a)!=="svelte-muuwa9"&&(a.textContent=w)},m(i,C){o(i,l,C),o(i,t,C),o(i,a,C)},d(i){i&&(r(l),r(t),r(a))}}}function Bl(u){let l,s;return l=new J({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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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 J({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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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 J({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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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 J({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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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 J({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(){y(l.$$.fragment),s=p(),t=_("p"),t.textContent=a},l(i){M(l.$$.fragment,i),s=f(i),t=b(i,"P",{"data-svelte-h":!0}),$(t)!=="svelte-18vxhwi"&&(t.textContent=a)},m(i,C){d(l,i,C),o(i,s,C),o(i,t,C),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 J({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(){y(l.$$.fragment),s=p(),t=_("p"),t.textContent=a},l(i){M(l.$$.fragment,i),s=f(i),t=b(i,"P",{"data-svelte-h":!0}),$(t)!=="svelte-18vxhwi"&&(t.textContent=a)},m(i,C){d(l,i,C),o(i,s,C),o(i,t,C),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 J({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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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 J({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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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-ik3ry7"&&(l.innerHTML=s)},m(t,a){o(t,l,a)},d(t){t&&r(l)}}}function Ql(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-ik3ry7"&&(l.innerHTML=s)},m(t,a){o(t,l,a)},d(t){t&&r(l)}}}function zl(u){let l,s;return l=new J({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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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 J({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b3JjaC50ZW5zb3IoZW5jb2RlZF9zZXF1ZW5jZXMp",highlighted:`<span class="hljs-keyword">import</span> torch

model_inputs = torch.tensor(encoded_sequences)`,wrap:!1}}),{c(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,a){d(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,C,Ne,g,T,ve,h,j,xe,Ze,Q,xt="但是，如果您知道要使用的模型類型，則可以使用直接定義其體系結構的類。讓我們看看這是如何與BERT模型一起工作的。",Qe,z,ze,A,Zt="初始化BERT模型需要做的第一件事是加載配置對象：",Ae,v,x,Be,H,Bt="配置包含許多用於構建模型的屬性：",He,P,Pe,X,Xe,Y,Ut="雖然您還沒有看到所有這些屬性都做了什麼，但您應該認識到其中的一些屬性：hidden<em>size屬性定義了hidden</em>狀態向量的大小，num_hidden_layers定義了Transformer模型的層數。",Ye,q,qe,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,Qt=`用於加載模型的標識符可以是模型中心Hub上任何模型的標識符，只要它與BERT體系結構兼容。可以找到可用的BERT檢查點的完整列表
<a href="https://huggingface.co/models?filter=bert" rel="nofollow">here</a>
.`,tt,le,lt,ne,zt=`保存模型和加載模型一樣簡單—我們使用
save_pretrained()
方法，類似於
from_pretrained()
方法：`,nt,se,st,re,At="這會將兩個文件保存到磁盤：",rt,E,I,Ee,oe,Ht=`如果你看一下
config.json
文件，您將識別構建模型體系結構所需的屬性。該文件還包含一些元數據，例如檢查點的來源以及上次保存檢查點時使用的🤗 Transformers版本。`,ot,Ie,ae,at,ie,Pt="既然您知道了如何加載和保存模型，那麼讓我們嘗試使用它進行一些預測。Transformer模型只能處理數字——分詞器生成的數字。但在我們討論標記化器之前，讓我們先探討模型接受哪些輸入。",it,pe,Xt="標記化器可以將輸入轉換為適當的框架張量，但為了幫助您瞭解發生了什麼，我們將快速瞭解在將輸入發送到模型之前必須做什麼。",pt,fe,Yt="假設我們有幾個序列：",ft,me,mt,ce,qt=`分詞器將這些轉換為詞彙表索引，通常稱為
input IDs
. 每個序列現在都是一個數字列表！結果是：`,ct,ue,ut,_e,Ft="這是一個編碼序列列表：一個列表列表。張量只接受矩形（想想矩陣）。此“數組”已為矩形，因此將其轉換為張量很容易：",_t,R,V,Re,be,bt,$e,St="在模型中使用張量非常簡單-我們只需將輸入稱為模型：",$t,ye,yt,Me,Dt=`雖然模型接受許多不同的參數，但只需要
input IDs。我們稍後將解釋其他參數的作用以及何時需要它們，但首先我們需要更仔細地瞭解
Transformer模型可以理解的輸入的標記`,Mt,Ge,dt;w=new gl({props:{fw:u[0]}}),C=new Ve({props:{title:"模型",local:"模型",headingTag:"h1"}});const Lt=[hl,Tl],de=[];function Kt(e,n){return e[0]==="pt"?0:1}g=Kt(u),T=de[g]=Lt[g](u);const Ot=[vl,jl],ke=[];function el(e,n){return e[0]==="pt"?0:1}h=el(u),j=ke[h]=Ot[h](u);function tl(e,n){return e[0]==="pt"?Zl:xl}let kt=tl(u),G=kt(u);z=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),P=new J({props:{code:"cHJpbnQoY29uZmlnKQ==",highlighted:'<span class="hljs-built_in">print</span>(config)',wrap:!1}}),X=new J({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}}),q=new Ve({props:{title:"不同的加載方式",local:"不同的加載方式",headingTag:"h3"}});const sl=[El,Wl],Ce=[];function rl(e,n){return e[0]==="pt"?0:1}Z=rl(u),B=Ce[Z]=sl[Z](u);const ol=[Rl,Il],Je=[];function al(e,n){return e[0]==="pt"?0:1}U=al(u),W=Je[U]=ol[U](u),le=new Ve({props:{title:"保存模型",local:"保存模型",headingTag:"h3"}}),se=new J({props:{code:"bW9kZWwuc2F2ZV9wcmV0cmFpbmVkKCUyMmRpcmVjdG9yeV9vbl9teV9jb21wdXRlciUyMik=",highlighted:'model.save_pretrained(<span class="hljs-string">&quot;directory_on_my_computer&quot;</span>)',wrap:!1}});const il=[Gl,Vl],ge=[];function pl(e,n){return e[0]==="pt"?0:1}E=pl(u),I=ge[E]=il[E](u);function fl(e,n){return e[0]==="pt"?Ql:Nl}let wt=fl(u),N=wt(u);ae=new Ve({props:{title:"使用Transformers模型進行推理",local:"使用transformers模型進行推理",headingTag:"h3"}}),me=new J({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 J({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,zl],Te=[];function cl(e,n){return e[0]==="pt"?0:1}return R=cl(u),V=Te[R]=ml[R](u),be=new Ve({props:{title:"使用張量作為模型的輸入",local:"使用張量作為模型的輸入",headingTag:"h3"}}),ye=new J({props:{code:"b3V0cHV0JTIwJTNEJTIwbW9kZWwobW9kZWxfaW5wdXRzKQ==",highlighted:"output = model(model_inputs)",wrap:!1}}),{c(){l=_("meta"),s=p(),t=_("p"),a=p(),y(w.$$.fragment),i=p(),y(C.$$.fragment),Ne=p(),T.c(),ve=p(),j.c(),xe=p(),G.c(),Ze=p(),Q=_("p"),Q.textContent=xt,Qe=p(),y(z.$$.fragment),ze=p(),A=_("p"),A.textContent=Zt,Ae=p(),x.c(),Be=p(),H=_("p"),H.textContent=Bt,He=p(),y(P.$$.fragment),Pe=p(),y(X.$$.fragment),Xe=p(),Y=_("p"),Y.innerHTML=Ut,Ye=p(),y(q.$$.fragment),qe=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=Qt,tt=p(),y(le.$$.fragment),lt=p(),ne=_("p"),ne.textContent=zt,nt=p(),y(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(),y(ae.$$.fragment),at=p(),ie=_("p"),ie.textContent=Pt,it=p(),pe=_("p"),pe.textContent=Xt,pt=p(),fe=_("p"),fe.textContent=Yt,ft=p(),y(me.$$.fragment),mt=p(),ce=_("p"),ce.textContent=qt,ct=p(),y(ue.$$.fragment),ut=p(),_e=_("p"),_e.textContent=Ft,_t=p(),V.c(),Re=p(),y(be.$$.fragment),bt=p(),$e=_("p"),$e.textContent=St,$t=p(),y(ye.$$.fragment),yt=p(),Me=_("p"),Me.textContent=Dt,Mt=p(),Ge=_("p"),this.h()},l(e){const n=Cl("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),M(w.$$.fragment,e),i=f(e),M(C.$$.fragment,e),Ne=f(e),T.l(e),ve=f(e),j.l(e),xe=f(e),G.l(e),Ze=f(e),Q=b(e,"P",{"data-svelte-h":!0}),$(Q)!=="svelte-1avgik"&&(Q.textContent=xt),Qe=f(e),M(z.$$.fragment,e),ze=f(e),A=b(e,"P",{"data-svelte-h":!0}),$(A)!=="svelte-1c2sd0g"&&(A.textContent=Zt),Ae=f(e),x.l(e),Be=f(e),H=b(e,"P",{"data-svelte-h":!0}),$(H)!=="svelte-ifij78"&&(H.textContent=Bt),He=f(e),M(P.$$.fragment,e),Pe=f(e),M(X.$$.fragment,e),Xe=f(e),Y=b(e,"P",{"data-svelte-h":!0}),$(Y)!=="svelte-1j1yk5h"&&(Y.innerHTML=Ut),Ye=f(e),M(q.$$.fragment,e),qe=f(e),F=b(e,"P",{"data-svelte-h":!0}),$(F)!=="svelte-hqzx39"&&(F.textContent=Wt),Fe=f(e),B.l(e),Ue=f(e),S=b(e,"P",{"data-svelte-h":!0}),$(S)!=="svelte-1jg7qnm"&&(S.innerHTML=Et),Se=f(e),D=b(e,"P",{"data-svelte-h":!0}),$(D)!=="svelte-xr6qnm"&&(D.textContent=It),De=f(e),W.l(e),We=f(e),L=b(e,"P",{"data-svelte-h":!0}),$(L)!=="svelte-5i3cgs"&&(L.textContent=Rt),Le=f(e),K=b(e,"P",{"data-svelte-h":!0}),$(K)!=="svelte-o3yggw"&&(K.innerHTML=Vt),Ke=f(e),O=b(e,"P",{"data-svelte-h":!0}),$(O)!=="svelte-o19g8r"&&(O.textContent=Gt),Oe=f(e),ee=b(e,"P",{"data-svelte-h":!0}),$(ee)!=="svelte-eld2kp"&&(ee.textContent=Nt),et=f(e),te=b(e,"P",{"data-svelte-h":!0}),$(te)!=="svelte-dsr9bu"&&(te.innerHTML=Qt),tt=f(e),M(le.$$.fragment,e),lt=f(e),ne=b(e,"P",{"data-svelte-h":!0}),$(ne)!=="svelte-gw4ej0"&&(ne.textContent=zt),nt=f(e),M(se.$$.fragment,e),st=f(e),re=b(e,"P",{"data-svelte-h":!0}),$(re)!=="svelte-x1s2q0"&&(re.textContent=At),rt=f(e),I.l(e),Ee=f(e),oe=b(e,"P",{"data-svelte-h":!0}),$(oe)!=="svelte-8ydu52"&&(oe.textContent=Ht),ot=f(e),N.l(e),Ie=f(e),M(ae.$$.fragment,e),at=f(e),ie=b(e,"P",{"data-svelte-h":!0}),$(ie)!=="svelte-1gnygj1"&&(ie.textContent=Pt),it=f(e),pe=b(e,"P",{"data-svelte-h":!0}),$(pe)!=="svelte-4clp4"&&(pe.textContent=Xt),pt=f(e),fe=b(e,"P",{"data-svelte-h":!0}),$(fe)!=="svelte-17t6y9q"&&(fe.textContent=Yt),ft=f(e),M(me.$$.fragment,e),mt=f(e),ce=b(e,"P",{"data-svelte-h":!0}),$(ce)!=="svelte-3zpror"&&(ce.textContent=qt),ct=f(e),M(ue.$$.fragment,e),ut=f(e),_e=b(e,"P",{"data-svelte-h":!0}),$(_e)!=="svelte-164p9o"&&(_e.textContent=Ft),_t=f(e),V.l(e),Re=f(e),M(be.$$.fragment,e),bt=f(e),$e=b(e,"P",{"data-svelte-h":!0}),$($e)!=="svelte-19h4dcl"&&($e.textContent=St),$t=f(e),M(ye.$$.fragment,e),yt=f(e),Me=b(e,"P",{"data-svelte-h":!0}),$(Me)!=="svelte-1nicy15"&&(Me.textContent=Dt),Mt=f(e),Ge=b(e,"P",{}),_l(Ge).forEach(r),this.h()},h(){bl(l,"name","hf:doc:metadata"),bl(l,"content",Pl)},m(e,n){Jl(document.head,l),o(e,s,n),o(e,t,n),o(e,a,n),d(w,e,n),o(e,i,n),d(C,e,n),o(e,Ne,n),de[g].m(e,n),o(e,ve,n),ke[h].m(e,n),o(e,xe,n),G.m(e,n),o(e,Ze,n),o(e,Q,n),o(e,Qe,n),d(z,e,n),o(e,ze,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),d(P,e,n),o(e,Pe,n),d(X,e,n),o(e,Xe,n),o(e,Y,n),o(e,Ye,n),d(q,e,n),o(e,qe,n),o(e,F,n),o(e,Fe,n),Ce[Z].m(e,n),o(e,Ue,n),o(e,S,n),o(e,Se,n),o(e,D,n),o(e,De,n),Je[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),d(le,e,n),o(e,lt,n),o(e,ne,n),o(e,nt,n),d(se,e,n),o(e,st,n),o(e,re,n),o(e,rt,n),ge[E].m(e,n),o(e,Ee,n),o(e,oe,n),o(e,ot,n),N.m(e,n),o(e,Ie,n),d(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),d(me,e,n),o(e,mt,n),o(e,ce,n),o(e,ct,n),d(ue,e,n),o(e,ut,n),o(e,_e,n),o(e,_t,n),Te[R].m(e,n),o(e,Re,n),d(be,e,n),o(e,bt,n),o(e,$e,n),o(e,$t,n),d(ye,e,n),o(e,yt,n),o(e,Me,n),o(e,Mt,n),o(e,Ge,n),dt=!0},p(e,[n]){const ul={};n&1&&(ul.fw=e[0]),w.$set(ul);let Ct=g;g=Kt(e),g!==Ct&&(je(),m(de[Ct],1,1,()=>{de[Ct]=null}),he(),T=de[g],T||(T=de[g]=Lt[g](e),T.c()),c(T,1),T.m(ve.parentNode,ve));let Jt=h;h=el(e),h!==Jt&&(je(),m(ke[Jt],1,1,()=>{ke[Jt]=null}),he(),j=ke[h],j||(j=ke[h]=Ot[h](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 gt=v;v=nl(e),v!==gt&&(je(),m(we[gt],1,1,()=>{we[gt]=null}),he(),x=we[v],x||(x=we[v]=ll[v](e),x.c()),c(x,1),x.m(Be.parentNode,Be));let Tt=Z;Z=rl(e),Z!==Tt&&(je(),m(Ce[Tt],1,1,()=>{Ce[Tt]=null}),he(),B=Ce[Z],B||(B=Ce[Z]=sl[Z](e),B.c()),c(B,1),B.m(Ue.parentNode,Ue));let ht=U;U=al(e),U!==ht&&(je(),m(Je[ht],1,1,()=>{Je[ht]=null}),he(),W=Je[U],W||(W=Je[U]=ol[U](e),W.c()),c(W,1),W.m(We.parentNode,We));let jt=E;E=pl(e),E!==jt&&(je(),m(ge[jt],1,1,()=>{ge[jt]=null}),he(),I=ge[E],I||(I=ge[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(Te[vt],1,1,()=>{Te[vt]=null}),he(),V=Te[R],V||(V=Te[R]=ml[R](e),V.c()),c(V,1),V.m(Re.parentNode,Re))},i(e){dt||(c(w.$$.fragment,e),c(C.$$.fragment,e),c(T),c(j),c(z.$$.fragment,e),c(x),c(P.$$.fragment,e),c(X.$$.fragment,e),c(q.$$.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(ye.$$.fragment,e),dt=!0)},o(e){m(w.$$.fragment,e),m(C.$$.fragment,e),m(T),m(j),m(z.$$.fragment,e),m(x),m(P.$$.fragment,e),m(X.$$.fragment,e),m(q.$$.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(ye.$$.fragment,e),dt=!1},d(e){e&&(r(s),r(t),r(a),r(i),r(Ne),r(ve),r(xe),r(Ze),r(Q),r(Qe),r(ze),r(A),r(Ae),r(Be),r(H),r(He),r(Pe),r(Xe),r(Y),r(Ye),r(qe),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(yt),r(Me),r(Mt),r(Ge)),r(l),k(w,e),k(C,e),de[g].d(e),ke[h].d(e),G.d(e),k(z,e),we[v].d(e),k(P,e),k(X,e),k(q,e),Ce[Z].d(e),Je[U].d(e),k(le,e),k(se,e),ge[E].d(e),N.d(e),k(ae,e),k(me,e),k(ue,e),Te[R].d(e),k(be,e),k(ye,e)}}}const Pl='{"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 Xl(u,l,s){let t="pt";return dl(()=>{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,Xl,Hl,Ml,{})}}export{Ol as component};
