import{s as gl,o as Cl}from"../chunks/scheduler.cc52f4b9.js";import{S as Jl,i as Tl,e as _,s as p,c as M,h as hl,a as b,d as r,b as f,f as dl,g as d,j as $,k as yl,l as jl,m as o,n as y,o as m,u as ve,t as c,p as w,v as xe}from"../chunks/index.9480bb2b.js";import{C as vl,H as Ne,E as xl}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.52103c90.js";import{Y as wl}from"../chunks/Youtube.7b12d9e8.js";import{C}from"../chunks/CodeBlock.c5404643.js";import{C as kl}from"../chunks/CourseFloatingBanner.78fb31df.js";import{F as Zl}from"../chunks/FrameworkSwitchCourse.42d12053.js";function Bl(u){let l,s;return l=new kl({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,i){y(l,t,i),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;return l=new kl({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,i){y(l,t,i),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 Wl(u){let l,s;return l=new wl({props:{id:"d3JVgghSOew"}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,i){y(l,t,i),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 El(u){let l,s;return l=new wl({props:{id:"AhChOFRegn4"}}),{c(){M(l.$$.fragment)},l(t){d(l.$$.fragment,t)},m(t,i){y(l,t,i),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=`在本節中，我們將更詳細地瞭解如何創建和使用模型。我們將使用
AutoModel類，當您希望從檢查點實例化任何模型時，這非常方便。`,t,i,k="這個AutoModel類及其所有相關項實際上是對庫中各種可用模型的簡單包裝。它是一個聰明的包裝器，因為它可以自動猜測檢查點的適當模型體系結構，然後用該體系結構實例化模型。";return{c(){l=_("p"),l.textContent=s,t=p(),i=_("p"),i.textContent=k},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=k)},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 Rl(u){let l,s=`在本節中，我們將更詳細地瞭解如何創建和使用模型。我們將使用
AutoModel類，當您希望從檢查點實例化任何模型時，這非常方便。`,t,i,k="這個AutoModel類及其所有相關項實際上是對庫中各種可用模型的簡單包裝。它是一個聰明的包裝器，因為它可以自動猜測檢查點的適當模型體系結構，然後用該體系結構實例化模型。";return{c(){l=_("p"),l.textContent=s,t=p(),i=_("p"),i.textContent=k},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=k)},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 Vl(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,i){y(l,t,i),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;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,i){y(l,t,i),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 Nl(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,i){y(l,t,i),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 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,i){y(l,t,i),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,t,i="正如您之前看到的，我們可以用等效的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=i},l(a){d(l.$$.fragment,a),s=f(a),t=b(a,"P",{"data-svelte-h":!0}),$(t)!=="svelte-18vxhwi"&&(t.textContent=i)},m(a,g){y(l,a,g),o(a,s,g),o(a,t,g),k=!0},i(a){k||(c(l.$$.fragment,a),k=!0)},o(a){m(l.$$.fragment,a),k=!1},d(a){a&&(r(s),r(t)),w(l,a)}}}function Al(u){let l,s,t,i="正如您之前看到的，我們可以用等效的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=i},l(a){d(l.$$.fragment,a),s=f(a),t=b(a,"P",{"data-svelte-h":!0}),$(t)!=="svelte-18vxhwi"&&(t.textContent=i)},m(a,g){y(l,a,g),o(a,s,g),o(a,t,g),k=!0},i(a){k||(c(l.$$.fragment,a),k=!0)},o(a){m(l.$$.fragment,a),k=!1},d(a){a&&(r(s),r(t)),w(l,a)}}}function Hl(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,i){y(l,t,i),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 Pl(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,i){y(l,t,i),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="這個 <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,i){o(t,l,i)},d(t){t&&r(l)}}}function Yl(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,i){o(t,l,i)},d(t){t&&r(l)}}}function ql(u){let l,s;return l=new C({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0Zi5jb25zdGFudChlbmNvZGVkX3NlcXVlbmNlcyk=",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

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