import{s as kl,o as wl}from"../chunks/scheduler.37c15a92.js";import{S as gl,i as Cl,g as _,s as p,r as y,A as hl,h as b,f as r,c as f,j as $l,u as M,x as $,k as yl,y as Jl,a as o,v as d,t as m,b as je,d as c,w as k,p as ve}from"../chunks/index.2bf4358c.js";import{Y as Ml}from"../chunks/Youtube.1e50a667.js";import{C}from"../chunks/CodeBlock.4e987730.js";import{C as dl}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as Tl}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ge,E as jl}from"../chunks/index.b8688d36.js";function vl(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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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;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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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 Zl(u){let l,s;return l=new Ml({props:{id:"d3JVgghSOew"}}),{c(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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 Bl(u){let l,s;return l=new Ml({props:{id:"AhChOFRegn4"}}),{c(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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=`在本節中，我們將更詳細地瞭解如何創建和使用模型。我們將使用
AutoModel類，當您希望從檢查點實例化任何模型時，這非常方便。`,t,i,w="這個AutoModel類及其所有相關項實際上是對庫中各種可用模型的簡單包裝。它是一個聰明的包裝器，因為它可以自動猜測檢查點的適當模型體系結構，然後用該體系結構實例化模型。";return{c(){l=_("p"),l.textContent=s,t=p(),i=_("p"),i.textContent=w},l(a){l=b(a,"P",{"data-svelte-h":!0}),$(l)!=="svelte-u0ngs0"&&(l.textContent=s),t=f(a),i=b(a,"P",{"data-svelte-h":!0}),$(i)!=="svelte-muuwa9"&&(i.textContent=w)},m(a,g){o(a,l,g),o(a,t,g),o(a,i,g)},d(a){a&&(r(l),r(t),r(i))}}}function Wl(u){let l,s=`在本節中，我們將更詳細地瞭解如何創建和使用模型。我們將使用
AutoModel類，當您希望從檢查點實例化任何模型時，這非常方便。`,t,i,w="這個AutoModel類及其所有相關項實際上是對庫中各種可用模型的簡單包裝。它是一個聰明的包裝器，因為它可以自動猜測檢查點的適當模型體系結構，然後用該體系結構實例化模型。";return{c(){l=_("p"),l.textContent=s,t=p(),i=_("p"),i.textContent=w},l(a){l=b(a,"P",{"data-svelte-h":!0}),$(l)!=="svelte-u0ngs0"&&(l.textContent=s),t=f(a),i=b(a,"P",{"data-svelte-h":!0}),$(i)!=="svelte-muuwa9"&&(i.textContent=w)},m(a,g){o(a,l,g),o(a,t,g),o(a,i,g)},d(a){a&&(r(l),r(t),r(i))}}}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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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;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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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 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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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 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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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,t,i="正如您之前看到的，我們可以用等效的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(){y(l.$$.fragment),s=p(),t=_("p"),t.textContent=i},l(a){M(l.$$.fragment,a),s=f(a),t=b(a,"P",{"data-svelte-h":!0}),$(t)!=="svelte-18vxhwi"&&(t.textContent=i)},m(a,g){d(l,a,g),o(a,s,g),o(a,t,g),w=!0},i(a){w||(c(l.$$.fragment,a),w=!0)},o(a){m(l.$$.fragment,a),w=!1},d(a){a&&(r(s),r(t)),k(l,a)}}}function Nl(u){let l,s,t,i="正如您之前看到的，我們可以用等效的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(){y(l.$$.fragment),s=p(),t=_("p"),t.textContent=i},l(a){M(l.$$.fragment,a),s=f(a),t=b(a,"P",{"data-svelte-h":!0}),$(t)!=="svelte-18vxhwi"&&(t.textContent=i)},m(a,g){d(l,a,g),o(a,s,g),o(a,t,g),w=!0},i(a){w||(c(l.$$.fragment,a),w=!0)},o(a){m(l.$$.fragment,a),w=!1},d(a){a&&(r(s),r(t)),k(l,a)}}}function Ql(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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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 zl(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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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="這個 <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,i){o(t,l,i)},d(t){t&&r(l)}}}function Hl(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,i){o(t,l,i)},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(){y(l.$$.fragment)},l(t){M(l.$$.fragment,t)},m(t,i){d(l,t,i),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;return l=new C({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,i){d(l,t,i),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 Yl(u){let l,s,t,i,w,a,g,Qe,h,J,xe,T,j,Ze,Be,Q,Bt="但是，如果您知道要使用的模型類型，則可以使用直接定義其體系結構的類。讓我們看看這是如何與BERT模型一起工作的。",ze,z,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,Qt="該模型現在使用檢查點的所有權重進行初始化。它可以直接用於對訓練過的任務進行推理，也可以對新任務進行微調。通過預先訓練重量而不是從頭開始的訓練，我們可以很快取得好的效果。",et,ee,zt=`權重已下載並緩存在緩存文件夾中（因此將來對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版本。`,it,Re,ie,at,ae,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="在模型中使用張量非常簡單-我們只需將輸入稱為模型：",yt,ye,Mt,Me,Kt=`雖然模型接受許多不同的參數，但只需要
input IDs。我們稍後將解釋其他參數的作用以及何時需要它們，但首先我們需要更仔細地瞭解
Transformer模型可以理解的輸入的標記`,dt,de,kt,Ne,wt;w=new Tl({props:{fw:u[0]}}),g=new Ge({props:{title:"模型",local:"模型",headingTag:"h1"}});const Ot=[xl,vl],ke=[];function el(e,n){return e[0]==="pt"?0:1}h=el(u),J=ke[h]=Ot[h](u);const tl=[Bl,Zl],we=[];function ll(e,n){return e[0]==="pt"?0:1}T=ll(u),j=we[T]=tl[T](u);function nl(e,n){return e[0]==="pt"?Wl:Ul}let gt=nl(u),G=gt(u);z=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 il(e,n){return e[0]==="pt"?0:1}Z=il(u),B=Ce[Z]=ol[Z](u);const al=[Nl,Gl],he=[];function pl(e,n){return e[0]==="pt"?0:1}U=pl(u),W=he[U]=al[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=[zl,Ql],Je=[];function ml(e,n){return e[0]==="pt"?0:1}E=ml(u),I=Je[E]=fl[E](u);function cl(e,n){return e[0]==="pt"?Hl:Al}let Ct=cl(u),N=Ct(u);ie=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],Te=[];function _l(e,n){return e[0]==="pt"?0:1}return R=_l(u),V=Te[R]=ul[R](u),be=new Ge({props:{title:"使用張量作為模型的輸入",local:"使用張量作為模型的輸入",headingTag:"h3"}}),ye=new C({props:{code:"b3V0cHV0JTIwJTNEJTIwbW9kZWwobW9kZWxfaW5wdXRzKQ==",highlighted:"output = model(model_inputs)",wrap:!1}}),de=new jl({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter2/3.mdx"}}),{c(){l=_("meta"),s=p(),t=_("p"),i=p(),y(w.$$.fragment),a=p(),y(g.$$.fragment),Qe=p(),J.c(),xe=p(),j.c(),Ze=p(),G.c(),Be=p(),Q=_("p"),Q.textContent=Bt,ze=p(),y(z.$$.fragment),Ae=p(),A=_("p"),A.textContent=Ut,He=p(),x.c(),Ue=p(),H=_("p"),H.textContent=Wt,Pe=p(),y(P.$$.fragment),Xe=p(),y(X.$$.fragment),Ye=p(),Y=_("p"),Y.innerHTML=Et,qe=p(),y(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=Qt,et=p(),ee=_("p"),ee.textContent=zt,tt=p(),te=_("p"),te.innerHTML=At,lt=p(),y(le.$$.fragment),nt=p(),ne=_("p"),ne.textContent=Ht,st=p(),y(se.$$.fragment),rt=p(),re=_("p"),re.textContent=Pt,ot=p(),I.c(),Ie=p(),oe=_("p"),oe.textContent=Xt,it=p(),N.c(),Re=p(),y(ie.$$.fragment),at=p(),ae=_("p"),ae.textContent=Yt,pt=p(),pe=_("p"),pe.textContent=qt,ft=p(),fe=_("p"),fe.textContent=Ft,mt=p(),y(me.$$.fragment),ct=p(),ce=_("p"),ce.textContent=St,ut=p(),y(ue.$$.fragment),_t=p(),_e=_("p"),_e.textContent=Dt,bt=p(),V.c(),Ve=p(),y(be.$$.fragment),$t=p(),$e=_("p"),$e.textContent=Lt,yt=p(),y(ye.$$.fragment),Mt=p(),Me=_("p"),Me.textContent=Kt,dt=p(),y(de.$$.fragment),kt=p(),Ne=_("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),i=f(e),M(w.$$.fragment,e),a=f(e),M(g.$$.fragment,e),Qe=f(e),J.l(e),xe=f(e),j.l(e),Ze=f(e),G.l(e),Be=f(e),Q=b(e,"P",{"data-svelte-h":!0}),$(Q)!=="svelte-1avgik"&&(Q.textContent=Bt),ze=f(e),M(z.$$.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),M(P.$$.fragment,e),Xe=f(e),M(X.$$.fragment,e),Ye=f(e),Y=b(e,"P",{"data-svelte-h":!0}),$(Y)!=="svelte-1j1yk5h"&&(Y.innerHTML=Et),qe=f(e),M(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=Qt),et=f(e),ee=b(e,"P",{"data-svelte-h":!0}),$(ee)!=="svelte-eld2kp"&&(ee.textContent=zt),tt=f(e),te=b(e,"P",{"data-svelte-h":!0}),$(te)!=="svelte-dsr9bu"&&(te.innerHTML=At),lt=f(e),M(le.$$.fragment,e),nt=f(e),ne=b(e,"P",{"data-svelte-h":!0}),$(ne)!=="svelte-gw4ej0"&&(ne.textContent=Ht),st=f(e),M(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),it=f(e),N.l(e),Re=f(e),M(ie.$$.fragment,e),at=f(e),ae=b(e,"P",{"data-svelte-h":!0}),$(ae)!=="svelte-1gnygj1"&&(ae.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),M(me.$$.fragment,e),ct=f(e),ce=b(e,"P",{"data-svelte-h":!0}),$(ce)!=="svelte-3zpror"&&(ce.textContent=St),ut=f(e),M(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),M(be.$$.fragment,e),$t=f(e),$e=b(e,"P",{"data-svelte-h":!0}),$($e)!=="svelte-19h4dcl"&&($e.textContent=Lt),yt=f(e),M(ye.$$.fragment,e),Mt=f(e),Me=b(e,"P",{"data-svelte-h":!0}),$(Me)!=="svelte-1nicy15"&&(Me.textContent=Kt),dt=f(e),M(de.$$.fragment,e),kt=f(e),Ne=b(e,"P",{}),$l(Ne).forEach(r),this.h()},h(){yl(l,"name","hf:doc:metadata"),yl(l,"content",ql)},m(e,n){Jl(document.head,l),o(e,s,n),o(e,t,n),o(e,i,n),d(w,e,n),o(e,a,n),d(g,e,n),o(e,Qe,n),ke[h].m(e,n),o(e,xe,n),we[T].m(e,n),o(e,Ze,n),G.m(e,n),o(e,Be,n),o(e,Q,n),o(e,ze,n),d(z,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),d(P,e,n),o(e,Xe,n),d(X,e,n),o(e,Ye,n),o(e,Y,n),o(e,qe,n),d(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),he[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),d(le,e,n),o(e,nt,n),o(e,ne,n),o(e,st,n),d(se,e,n),o(e,rt,n),o(e,re,n),o(e,ot,n),Je[E].m(e,n),o(e,Ie,n),o(e,oe,n),o(e,it,n),N.m(e,n),o(e,Re,n),d(ie,e,n),o(e,at,n),o(e,ae,n),o(e,pt,n),o(e,pe,n),o(e,ft,n),o(e,fe,n),o(e,mt,n),d(me,e,n),o(e,ct,n),o(e,ce,n),o(e,ut,n),d(ue,e,n),o(e,_t,n),o(e,_e,n),o(e,bt,n),Te[R].m(e,n),o(e,Ve,n),d(be,e,n),o(e,$t,n),o(e,$e,n),o(e,yt,n),d(ye,e,n),o(e,Mt,n),o(e,Me,n),o(e,dt,n),d(de,e,n),o(e,kt,n),o(e,Ne,n),wt=!0},p(e,[n]){const bl={};n&1&&(bl.fw=e[0]),w.$set(bl);let ht=h;h=el(e),h!==ht&&(ve(),m(ke[ht],1,1,()=>{ke[ht]=null}),je(),J=ke[h],J||(J=ke[h]=Ot[h](e),J.c()),c(J,1),J.m(xe.parentNode,xe));let Jt=T;T=ll(e),T!==Jt&&(ve(),m(we[Jt],1,1,()=>{we[Jt]=null}),je(),j=we[T],j||(j=we[T]=tl[T](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 Tt=v;v=rl(e),v!==Tt&&(ve(),m(ge[Tt],1,1,()=>{ge[Tt]=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=il(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(he[vt],1,1,()=>{he[vt]=null}),je(),W=he[U],W||(W=he[U]=al[U](e),W.c()),c(W,1),W.m(Ee.parentNode,Ee));let xt=E;E=ml(e),E!==xt&&(ve(),m(Je[xt],1,1,()=>{Je[xt]=null}),je(),I=Je[E],I||(I=Je[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(Te[Zt],1,1,()=>{Te[Zt]=null}),je(),V=Te[R],V||(V=Te[R]=ul[R](e),V.c()),c(V,1),V.m(Ve.parentNode,Ve))},i(e){wt||(c(w.$$.fragment,e),c(g.$$.fragment,e),c(J),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(ie.$$.fragment,e),c(me.$$.fragment,e),c(ue.$$.fragment,e),c(V),c(be.$$.fragment,e),c(ye.$$.fragment,e),c(de.$$.fragment,e),wt=!0)},o(e){m(w.$$.fragment,e),m(g.$$.fragment,e),m(J),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(ie.$$.fragment,e),m(me.$$.fragment,e),m(ue.$$.fragment,e),m(V),m(be.$$.fragment,e),m(ye.$$.fragment,e),m(de.$$.fragment,e),wt=!1},d(e){e&&(r(s),r(t),r(i),r(a),r(Qe),r(xe),r(Ze),r(Be),r(Q),r(ze),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(it),r(Re),r(at),r(ae),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(yt),r(Mt),r(Me),r(dt),r(kt),r(Ne)),r(l),k(w,e),k(g,e),ke[h].d(e),we[T].d(e),G.d(e),k(z,e),ge[v].d(e),k(P,e),k(X,e),k(q,e),Ce[Z].d(e),he[U].d(e),k(le,e),k(se,e),Je[E].d(e),N.d(e),k(ie,e),k(me,e),k(ue,e),Te[R].d(e),k(be,e),k(ye,e),k(de,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 wl(()=>{const i=new URLSearchParams(window.location.search);s(0,t=i.get("fw")||"pt")}),[t]}class ln extends gl{constructor(l){super(),Cl(this,l,Fl,Yl,kl,{})}}export{ln as component};
