import{s as wl,o as kl}from"../chunks/scheduler.37c15a92.js";import{S as gl,i as Cl,g as _,s as p,r as M,A as Jl,h as b,f as r,c as f,j as $l,u as d,x as $,k as Ml,y as Tl,a as o,v as y,t as m,b as je,d as c,w,p as ve}from"../chunks/index.2bf4358c.js";import{Y as dl}from"../chunks/Youtube.1e50a667.js";import{C}from"../chunks/CodeBlock.4e987730.js";import{C as yl}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as hl}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ge,E as jl}from"../chunks/getInferenceSnippets.1837c472.js";function vl(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(){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){w(l,t)}}}function xl(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(){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){w(l,t)}}}function Zl(u){let l,s;return l=new dl({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){w(l,t)}}}function Bl(u){let l,s;return l=new dl({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){w(l,t)}}}function Ul(u){let l,s=`在本節中，我們將更詳細地瞭解如何創建和使用模型。我們將使用
AutoModel類，當您希望從檢查點實例化任何模型時，這非常方便。`,t,a,k="這個AutoModel類及其所有相關項實際上是對庫中各種可用模型的簡單包裝。它是一個聰明的包裝器，因為它可以自動猜測檢查點的適當模型體系結構，然後用該體系結構實例化模型。";return{c(){l=_("p"),l.textContent=s,t=p(),a=_("p"),a.textContent=k},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=k)},m(i,g){o(i,l,g),o(i,t,g),o(i,a,g)},d(i){i&&(r(l),r(t),r(a))}}}function Wl(u){let l,s=`在本節中，我們將更詳細地瞭解如何創建和使用模型。我們將使用
AutoModel類，當您希望從檢查點實例化任何模型時，這非常方便。`,t,a,k="這個AutoModel類及其所有相關項實際上是對庫中各種可用模型的簡單包裝。它是一個聰明的包裝器，因為它可以自動猜測檢查點的適當模型體系結構，然後用該體系結構實例化模型。";return{c(){l=_("p"),l.textContent=s,t=p(),a=_("p"),a.textContent=k},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=k)},m(i,g){o(i,l,g),o(i,t,g),o(i,a,g)},d(i){i&&(r(l),r(t),r(a))}}}function El(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){w(l,t)}}}function Il(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){w(l,t)}}}function Rl(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){w(l,t)}}}function Vl(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){w(l,t)}}}function Gl(u){let l,s,t,a="正如您之前看到的，我們可以用等效的AutoModel類替換Bert模型。從現在開始，我們將這樣做，因為這會產生檢查點不可知的代碼；如果您的代碼適用於一個檢查點，那麼它應該與另一個檢查點無縫地工作。即使體系結構不同，這也適用，只要檢查點是針對類似任務（例如，情緒分析任務）訓練的。",k;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-18vxhwi"&&(t.textContent=a)},m(i,g){y(l,i,g),o(i,s,g),o(i,t,g),k=!0},i(i){k||(c(l.$$.fragment,i),k=!0)},o(i){m(l.$$.fragment,i),k=!1},d(i){i&&(r(s),r(t)),w(l,i)}}}function Nl(u){let l,s,t,a="正如您之前看到的，我們可以用等效的AutoModel類替換Bert模型。從現在開始，我們將這樣做，因為這會產生檢查點不可知的代碼；如果您的代碼適用於一個檢查點，那麼它應該與另一個檢查點無縫地工作。即使體系結構不同，這也適用，只要檢查點是針對類似任務（例如，情緒分析任務）訓練的。",k;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-18vxhwi"&&(t.textContent=a)},m(i,g){y(l,i,g),o(i,s,g),o(i,t,g),k=!0},i(i){k||(c(l.$$.fragment,i),k=!0)},o(i){m(l.$$.fragment,i),k=!1},d(i){i&&(r(s),r(t)),w(l,i)}}}function zl(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){w(l,t)}}}function Ql(u){let l,s;return l=new C({props:{code:"bHMlMjBkaXJlY3Rvcnlfb25fbXlfY29tcHV0ZXIlMEElMEFjb25maWcuanNvbiUyMG1vZGVsLnNhZmV0ZW5zb3Jz",highlighted:`ls <span class="hljs-keyword">directory_on_my_computer
</span>
<span class="hljs-built_in">config</span>.<span class="hljs-keyword">json </span>model.safetensors`,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){w(l,t)}}}function Al(u){let l,s="這個 <em>model.safetensors</em> 文件就是眾所周知的<em>state dictionary</em>; 它包含模型的所有權重。這兩個文件齊頭並進；配置是瞭解模型體系結構所必需的，而模型權重是模型的參數。";return{c(){l=_("p"),l.innerHTML=s},l(t){l=b(t,"P",{"data-svelte-h":!0}),$(l)!=="svelte-1llbtjn"&&(l.innerHTML=s)},m(t,a){o(t,l,a)},d(t){t&&r(l)}}}function Hl(u){let l,s="這個 <em>model.safetensors</em> 文件就是眾所周知的<em>state dictionary</em>; 它包含模型的所有權重。這兩個文件齊頭並進；配置是瞭解模型體系結構所必需的，而模型權重是模型的參數。";return{c(){l=_("p"),l.innerHTML=s},l(t){l=b(t,"P",{"data-svelte-h":!0}),$(l)!=="svelte-1llbtjn"&&(l.innerHTML=s)},m(t,a){o(t,l,a)},d(t){t&&r(l)}}}function Pl(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){w(l,t)}}}function Xl(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){w(l,t)}}}function Yl(u){let l,s,t,a,k,i,g,ze,J,T,xe,h,j,Ze,Be,z,Bt="但是，如果您知道要使用的模型類型，則可以使用直接定義其體系結構的類。讓我們看看這是如何與BERT模型一起工作的。",Qe,Q,Ae,A,Ut="初始化BERT模型需要做的第一件事是加載配置對象：",He,v,x,Ue,H,Wt="配置包含許多用於構建模型的屬性：",Pe,P,Xe,X,Ye,Y,Et="雖然您還沒有看到所有這些屬性都做了什麼，但您應該認識到其中的一些屬性：hidden<em>size屬性定義了hidden</em>狀態向量的大小，num_hidden_layers定義了Transformer模型的層數。",qe,q,Fe,F,It="從默認配置創建模型會使用隨機值對其進行初始化：",Se,Z,B,We,S,Rt=`該模型可以在這種狀態下使用，但會輸出胡言亂語；首先需要對其進行訓練。我們可以根據手頭的任務從頭開始訓練模型，但正如您在
<a href="/course/chapter1">Chapter 1</a>
，這將需要很長的時間和大量的數據，並將產生不可忽視的環境影響。為了避免不必要的重複工作，必須能夠共享和重用已經訓練過的模型。`,De,D,Vt=`加載已經訓練過的Transformers模型很簡單-我們可以使用from_pretrained()
方法：`,Le,U,W,Ee,L,Gt="在上面的代碼示例中，我們沒有使用BertConfig",Ke,K,Nt=`，而是通過Bert base cased標識符加載了一個預訓練模型。這是一個模型檢查點，由BERT的作者自己訓練；您可以在
<a href="https://huggingface.co/bert-base-cased" rel="nofollow">model card</a>中找到更多細節.`,Oe,O,zt="該模型現在使用檢查點的所有權重進行初始化。它可以直接用於對訓練過的任務進行推理，也可以對新任務進行微調。通過預先訓練重量而不是從頭開始的訓練，我們可以很快取得好的效果。",et,ee,Qt=`權重已下載並緩存在緩存文件夾中（因此將來對from_pretrained()方法的調用將不會重新下載它們）默認為
~/.cache/huggingface/transformers
. 您可以通過設置
HF_HOME
環境變量來自定義緩存文件夾。`,tt,te,At=`用於加載模型的標識符可以是模型中心Hub上任何模型的標識符，只要它與BERT體系結構兼容。可以找到可用的BERT檢查點的完整列表
<a href="https://huggingface.co/models?filter=bert" rel="nofollow">here</a>
.`,lt,le,nt,ne,Ht=`保存模型和加載模型一樣簡單—我們使用
save_pretrained()
方法，類似於
from_pretrained()
方法：`,st,se,rt,re,Pt="這會將兩個文件保存到磁盤：",ot,E,I,Ie,oe,Xt=`如果你看一下
config.json
文件，您將識別構建模型體系結構所需的屬性。該文件還包含一些元數據，例如檢查點的來源以及上次保存檢查點時使用的🤗 Transformers版本。`,at,Re,ae,it,ie,Yt="既然您知道了如何加載和保存模型，那麼讓我們嘗試使用它進行一些預測。Transformer模型只能處理數字——分詞器生成的數字。但在我們討論標記化器之前，讓我們先探討模型接受哪些輸入。",pt,pe,qt="標記化器可以將輸入轉換為適當的框架張量，但為了幫助您瞭解發生了什麼，我們將快速瞭解在將輸入發送到模型之前必須做什麼。",ft,fe,Ft="假設我們有幾個序列：",mt,me,ct,ce,St=`分詞器將這些轉換為詞彙表索引，通常稱為
input IDs
. 每個序列現在都是一個數字列表！結果是：`,ut,ue,_t,_e,Dt="這是一個編碼序列列表：一個列表列表。張量只接受矩形（想想矩陣）。此“數組”已為矩形，因此將其轉換為張量很容易：",bt,R,V,Ve,be,$t,$e,Lt="在模型中使用張量非常簡單-我們只需將輸入稱為模型：",Mt,Me,dt,de,Kt=`雖然模型接受許多不同的參數，但只需要
input IDs。我們稍後將解釋其他參數的作用以及何時需要它們，但首先我們需要更仔細地瞭解
Transformer模型可以理解的輸入的標記`,yt,ye,wt,Ne,kt;k=new hl({props:{fw:u[0]}}),g=new Ge({props:{title:"模型",local:"模型",headingTag:"h1"}});const Ot=[xl,vl],we=[];function el(e,n){return e[0]==="pt"?0:1}J=el(u),T=we[J]=Ot[J](u);const tl=[Bl,Zl],ke=[];function ll(e,n){return e[0]==="pt"?0:1}h=ll(u),j=ke[h]=tl[h](u);function nl(e,n){return e[0]==="pt"?Wl:Ul}let gt=nl(u),G=gt(u);Q=new Ge({props:{title:"創建轉換器",local:"創建轉換器",headingTag:"h2"}});const sl=[Il,El],ge=[];function rl(e,n){return e[0]==="pt"?0:1}v=rl(u),x=ge[v]=sl[v](u),P=new C({props:{code:"cHJpbnQoY29uZmlnKQ==",highlighted:'<span class="hljs-built_in">print</span>(config)',wrap:!1}}),X=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}}),q=new Ge({props:{title:"不同的加載方式",local:"不同的加載方式",headingTag:"h3"}});const ol=[Vl,Rl],Ce=[];function al(e,n){return e[0]==="pt"?0:1}Z=al(u),B=Ce[Z]=ol[Z](u);const il=[Nl,Gl],Je=[];function pl(e,n){return e[0]==="pt"?0:1}U=pl(u),W=Je[U]=il[U](u),le=new Ge({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 fl=[Ql,zl],Te=[];function ml(e,n){return e[0]==="pt"?0:1}E=ml(u),I=Te[E]=fl[E](u);function cl(e,n){return e[0]==="pt"?Hl:Al}let Ct=cl(u),N=Ct(u);ae=new Ge({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 ul=[Xl,Pl],he=[];function _l(e,n){return e[0]==="pt"?0:1}return R=_l(u),V=he[R]=ul[R](u),be=new Ge({props:{title:"使用張量作為模型的輸入",local:"使用張量作為模型的輸入",headingTag:"h3"}}),Me=new C({props:{code:"b3V0cHV0JTIwJTNEJTIwbW9kZWwobW9kZWxfaW5wdXRzKQ==",highlighted:"output = model(model_inputs)",wrap:!1}}),ye=new jl({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter2/3.mdx"}}),{c(){l=_("meta"),s=p(),t=_("p"),a=p(),M(k.$$.fragment),i=p(),M(g.$$.fragment),ze=p(),T.c(),xe=p(),j.c(),Ze=p(),G.c(),Be=p(),z=_("p"),z.textContent=Bt,Qe=p(),M(Q.$$.fragment),Ae=p(),A=_("p"),A.textContent=Ut,He=p(),x.c(),Ue=p(),H=_("p"),H.textContent=Wt,Pe=p(),M(P.$$.fragment),Xe=p(),M(X.$$.fragment),Ye=p(),Y=_("p"),Y.innerHTML=Et,qe=p(),M(q.$$.fragment),Fe=p(),F=_("p"),F.textContent=It,Se=p(),B.c(),We=p(),S=_("p"),S.innerHTML=Rt,De=p(),D=_("p"),D.textContent=Vt,Le=p(),W.c(),Ee=p(),L=_("p"),L.textContent=Gt,Ke=p(),K=_("p"),K.innerHTML=Nt,Oe=p(),O=_("p"),O.textContent=zt,et=p(),ee=_("p"),ee.textContent=Qt,tt=p(),te=_("p"),te.innerHTML=At,lt=p(),M(le.$$.fragment),nt=p(),ne=_("p"),ne.textContent=Ht,st=p(),M(se.$$.fragment),rt=p(),re=_("p"),re.textContent=Pt,ot=p(),I.c(),Ie=p(),oe=_("p"),oe.textContent=Xt,at=p(),N.c(),Re=p(),M(ae.$$.fragment),it=p(),ie=_("p"),ie.textContent=Yt,pt=p(),pe=_("p"),pe.textContent=qt,ft=p(),fe=_("p"),fe.textContent=Ft,mt=p(),M(me.$$.fragment),ct=p(),ce=_("p"),ce.textContent=St,ut=p(),M(ue.$$.fragment),_t=p(),_e=_("p"),_e.textContent=Dt,bt=p(),V.c(),Ve=p(),M(be.$$.fragment),$t=p(),$e=_("p"),$e.textContent=Lt,Mt=p(),M(Me.$$.fragment),dt=p(),de=_("p"),de.textContent=Kt,yt=p(),M(ye.$$.fragment),wt=p(),Ne=_("p"),this.h()},l(e){const n=Jl("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(k.$$.fragment,e),i=f(e),d(g.$$.fragment,e),ze=f(e),T.l(e),xe=f(e),j.l(e),Ze=f(e),G.l(e),Be=f(e),z=b(e,"P",{"data-svelte-h":!0}),$(z)!=="svelte-1avgik"&&(z.textContent=Bt),Qe=f(e),d(Q.$$.fragment,e),Ae=f(e),A=b(e,"P",{"data-svelte-h":!0}),$(A)!=="svelte-1c2sd0g"&&(A.textContent=Ut),He=f(e),x.l(e),Ue=f(e),H=b(e,"P",{"data-svelte-h":!0}),$(H)!=="svelte-ifij78"&&(H.textContent=Wt),Pe=f(e),d(P.$$.fragment,e),Xe=f(e),d(X.$$.fragment,e),Ye=f(e),Y=b(e,"P",{"data-svelte-h":!0}),$(Y)!=="svelte-1j1yk5h"&&(Y.innerHTML=Et),qe=f(e),d(q.$$.fragment,e),Fe=f(e),F=b(e,"P",{"data-svelte-h":!0}),$(F)!=="svelte-hqzx39"&&(F.textContent=It),Se=f(e),B.l(e),We=f(e),S=b(e,"P",{"data-svelte-h":!0}),$(S)!=="svelte-1jg7qnm"&&(S.innerHTML=Rt),De=f(e),D=b(e,"P",{"data-svelte-h":!0}),$(D)!=="svelte-xr6qnm"&&(D.textContent=Vt),Le=f(e),W.l(e),Ee=f(e),L=b(e,"P",{"data-svelte-h":!0}),$(L)!=="svelte-5i3cgs"&&(L.textContent=Gt),Ke=f(e),K=b(e,"P",{"data-svelte-h":!0}),$(K)!=="svelte-o3yggw"&&(K.innerHTML=Nt),Oe=f(e),O=b(e,"P",{"data-svelte-h":!0}),$(O)!=="svelte-o19g8r"&&(O.textContent=zt),et=f(e),ee=b(e,"P",{"data-svelte-h":!0}),$(ee)!=="svelte-eld2kp"&&(ee.textContent=Qt),tt=f(e),te=b(e,"P",{"data-svelte-h":!0}),$(te)!=="svelte-dsr9bu"&&(te.innerHTML=At),lt=f(e),d(le.$$.fragment,e),nt=f(e),ne=b(e,"P",{"data-svelte-h":!0}),$(ne)!=="svelte-gw4ej0"&&(ne.textContent=Ht),st=f(e),d(se.$$.fragment,e),rt=f(e),re=b(e,"P",{"data-svelte-h":!0}),$(re)!=="svelte-x1s2q0"&&(re.textContent=Pt),ot=f(e),I.l(e),Ie=f(e),oe=b(e,"P",{"data-svelte-h":!0}),$(oe)!=="svelte-8ydu52"&&(oe.textContent=Xt),at=f(e),N.l(e),Re=f(e),d(ae.$$.fragment,e),it=f(e),ie=b(e,"P",{"data-svelte-h":!0}),$(ie)!=="svelte-1gnygj1"&&(ie.textContent=Yt),pt=f(e),pe=b(e,"P",{"data-svelte-h":!0}),$(pe)!=="svelte-4clp4"&&(pe.textContent=qt),ft=f(e),fe=b(e,"P",{"data-svelte-h":!0}),$(fe)!=="svelte-17t6y9q"&&(fe.textContent=Ft),mt=f(e),d(me.$$.fragment,e),ct=f(e),ce=b(e,"P",{"data-svelte-h":!0}),$(ce)!=="svelte-3zpror"&&(ce.textContent=St),ut=f(e),d(ue.$$.fragment,e),_t=f(e),_e=b(e,"P",{"data-svelte-h":!0}),$(_e)!=="svelte-164p9o"&&(_e.textContent=Dt),bt=f(e),V.l(e),Ve=f(e),d(be.$$.fragment,e),$t=f(e),$e=b(e,"P",{"data-svelte-h":!0}),$($e)!=="svelte-19h4dcl"&&($e.textContent=Lt),Mt=f(e),d(Me.$$.fragment,e),dt=f(e),de=b(e,"P",{"data-svelte-h":!0}),$(de)!=="svelte-1nicy15"&&(de.textContent=Kt),yt=f(e),d(ye.$$.fragment,e),wt=f(e),Ne=b(e,"P",{}),$l(Ne).forEach(r),this.h()},h(){Ml(l,"name","hf:doc:metadata"),Ml(l,"content",ql)},m(e,n){Tl(document.head,l),o(e,s,n),o(e,t,n),o(e,a,n),y(k,e,n),o(e,i,n),y(g,e,n),o(e,ze,n),we[J].m(e,n),o(e,xe,n),ke[h].m(e,n),o(e,Ze,n),G.m(e,n),o(e,Be,n),o(e,z,n),o(e,Qe,n),y(Q,e,n),o(e,Ae,n),o(e,A,n),o(e,He,n),ge[v].m(e,n),o(e,Ue,n),o(e,H,n),o(e,Pe,n),y(P,e,n),o(e,Xe,n),y(X,e,n),o(e,Ye,n),o(e,Y,n),o(e,qe,n),y(q,e,n),o(e,Fe,n),o(e,F,n),o(e,Se,n),Ce[Z].m(e,n),o(e,We,n),o(e,S,n),o(e,De,n),o(e,D,n),o(e,Le,n),Je[U].m(e,n),o(e,Ee,n),o(e,L,n),o(e,Ke,n),o(e,K,n),o(e,Oe,n),o(e,O,n),o(e,et,n),o(e,ee,n),o(e,tt,n),o(e,te,n),o(e,lt,n),y(le,e,n),o(e,nt,n),o(e,ne,n),o(e,st,n),y(se,e,n),o(e,rt,n),o(e,re,n),o(e,ot,n),Te[E].m(e,n),o(e,Ie,n),o(e,oe,n),o(e,at,n),N.m(e,n),o(e,Re,n),y(ae,e,n),o(e,it,n),o(e,ie,n),o(e,pt,n),o(e,pe,n),o(e,ft,n),o(e,fe,n),o(e,mt,n),y(me,e,n),o(e,ct,n),o(e,ce,n),o(e,ut,n),y(ue,e,n),o(e,_t,n),o(e,_e,n),o(e,bt,n),he[R].m(e,n),o(e,Ve,n),y(be,e,n),o(e,$t,n),o(e,$e,n),o(e,Mt,n),y(Me,e,n),o(e,dt,n),o(e,de,n),o(e,yt,n),y(ye,e,n),o(e,wt,n),o(e,Ne,n),kt=!0},p(e,[n]){const bl={};n&1&&(bl.fw=e[0]),k.$set(bl);let Jt=J;J=el(e),J!==Jt&&(ve(),m(we[Jt],1,1,()=>{we[Jt]=null}),je(),T=we[J],T||(T=we[J]=Ot[J](e),T.c()),c(T,1),T.m(xe.parentNode,xe));let Tt=h;h=ll(e),h!==Tt&&(ve(),m(ke[Tt],1,1,()=>{ke[Tt]=null}),je(),j=ke[h],j||(j=ke[h]=tl[h](e),j.c()),c(j,1),j.m(Ze.parentNode,Ze)),gt!==(gt=nl(e))&&(G.d(1),G=gt(e),G&&(G.c(),G.m(Be.parentNode,Be)));let ht=v;v=rl(e),v!==ht&&(ve(),m(ge[ht],1,1,()=>{ge[ht]=null}),je(),x=ge[v],x||(x=ge[v]=sl[v](e),x.c()),c(x,1),x.m(Ue.parentNode,Ue));let jt=Z;Z=al(e),Z!==jt&&(ve(),m(Ce[jt],1,1,()=>{Ce[jt]=null}),je(),B=Ce[Z],B||(B=Ce[Z]=ol[Z](e),B.c()),c(B,1),B.m(We.parentNode,We));let vt=U;U=pl(e),U!==vt&&(ve(),m(Je[vt],1,1,()=>{Je[vt]=null}),je(),W=Je[U],W||(W=Je[U]=il[U](e),W.c()),c(W,1),W.m(Ee.parentNode,Ee));let xt=E;E=ml(e),E!==xt&&(ve(),m(Te[xt],1,1,()=>{Te[xt]=null}),je(),I=Te[E],I||(I=Te[E]=fl[E](e),I.c()),c(I,1),I.m(Ie.parentNode,Ie)),Ct!==(Ct=cl(e))&&(N.d(1),N=Ct(e),N&&(N.c(),N.m(Re.parentNode,Re)));let Zt=R;R=_l(e),R!==Zt&&(ve(),m(he[Zt],1,1,()=>{he[Zt]=null}),je(),V=he[R],V||(V=he[R]=ul[R](e),V.c()),c(V,1),V.m(Ve.parentNode,Ve))},i(e){kt||(c(k.$$.fragment,e),c(g.$$.fragment,e),c(T),c(j),c(Q.$$.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(Me.$$.fragment,e),c(ye.$$.fragment,e),kt=!0)},o(e){m(k.$$.fragment,e),m(g.$$.fragment,e),m(T),m(j),m(Q.$$.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(Me.$$.fragment,e),m(ye.$$.fragment,e),kt=!1},d(e){e&&(r(s),r(t),r(a),r(i),r(ze),r(xe),r(Ze),r(Be),r(z),r(Qe),r(Ae),r(A),r(He),r(Ue),r(H),r(Pe),r(Xe),r(Ye),r(Y),r(qe),r(Fe),r(F),r(Se),r(We),r(S),r(De),r(D),r(Le),r(Ee),r(L),r(Ke),r(K),r(Oe),r(O),r(et),r(ee),r(tt),r(te),r(lt),r(nt),r(ne),r(st),r(rt),r(re),r(ot),r(Ie),r(oe),r(at),r(Re),r(it),r(ie),r(pt),r(pe),r(ft),r(fe),r(mt),r(ct),r(ce),r(ut),r(_t),r(_e),r(bt),r(Ve),r($t),r($e),r(Mt),r(dt),r(de),r(yt),r(wt),r(Ne)),r(l),w(k,e),w(g,e),we[J].d(e),ke[h].d(e),G.d(e),w(Q,e),ge[v].d(e),w(P,e),w(X,e),w(q,e),Ce[Z].d(e),Je[U].d(e),w(le,e),w(se,e),Te[E].d(e),N.d(e),w(ae,e),w(me,e),w(ue,e),he[R].d(e),w(be,e),w(Me,e),w(ye,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 Fl(u,l,s){let t="pt";return kl(()=>{const a=new URLSearchParams(window.location.search);s(0,t=a.get("fw")||"pt")}),[t]}class ln extends gl{constructor(l){super(),Cl(this,l,Fl,Yl,wl,{})}}export{ln as component};
