import{s as Le,o as Fe,n as qn}from"../chunks/scheduler.37c15a92.js";import{S as Oe,i as qe,g as o,s as t,r as J,A as Pe,h as m,f as n,c as p,j as Ge,u as y,x as d,k as Fn,y as Ke,a as e,v as j,t as r,b as Vn,d as i,w as T,p as Hn}from"../chunks/index.2bf4358c.js";import{T as On}from"../chunks/Tip.363c041f.js";import{Y as Dn}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4e987730.js";import{C as Ye}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as sa}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Tl,E as la}from"../chunks/getInferenceSnippets.97e75ee2.js";function na(b){let a,U;return a=new Ye({props:{chapter:6,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/chapter6/section3_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter6/section3_tf.ipynb"}]}}),{c(){J(a.$$.fragment)},l(M){y(a.$$.fragment,M)},m(M,u){j(a,M,u),U=!0},i(M){U||(i(a.$$.fragment,M),U=!0)},o(M){r(a.$$.fragment,M),U=!1},d(M){T(a,M)}}}function ea(b){let a,U;return a=new Ye({props:{chapter:6,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/chapter6/section3_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter6/section3_pt.ipynb"}]}}),{c(){J(a.$$.fragment)},l(M){y(a.$$.fragment,M)},m(M,u){j(a,M,u),U=!0},i(M){U||(i(a.$$.fragment,M),U=!0)},o(M){r(a.$$.fragment,M),U=!1},d(M){T(a,M)}}}function aa(b){let a,U="⚠️ 对单个句子进行 tokenize 时，你不总是能看到同一个 tokenizer 的慢速和快速版本之间的速度差异。事实上，快速版本可能更慢！只有同时对大量文本进行 tokenize 时，你才能清楚地看到差异。";return{c(){a=o("p"),a.textContent=U},l(M){a=m(M,"P",{"data-svelte-h":!0}),d(a)!=="svelte-q2akp8"&&(a.textContent=U)},m(M,u){e(M,a,u)},p:qn,d(M){M&&n(a)}}}function ta(b){let a,U="词的概念是复杂的。例如，“I’ll”（“I will”的缩写）算作一个词还是两个词？这实际上取决于 tokenizer 和它采用的预分词操作。有些 tokenizer 只在空格处分割，所以它们会把这个看作是一个词。有些其他 tokenizer 在空格的基础之上还使用标点，所以会认为它是两个词。",M,u,k="✏️ <strong>试试看！</strong>从 <code>bert base cased</code> 和 <code>roberta base</code> checkpoint 创建一个 tokenizer 并用它们对“81s”进行分词。你观察到了什么？这些词的 ID 是什么？";return{c(){a=o("p"),a.textContent=U,M=t(),u=o("p"),u.innerHTML=k},l(w){a=m(w,"P",{"data-svelte-h":!0}),d(a)!=="svelte-w994xa"&&(a.textContent=U),M=p(w),u=m(w,"P",{"data-svelte-h":!0}),d(u)!=="svelte-tyihaq"&&(u.innerHTML=k)},m(w,I){e(w,a,I),e(w,M,I),e(w,u,I)},p:qn,d(w){w&&(n(a),n(M),n(u))}}}function pa(b){let a,U="✏️ <strong>试试看！</strong> 使用自己的文本，看看你是否能理解哪些 token 与单词 ID 相关联，以及如何提取单个单词的字符跨度。附加题：请尝试使用两个句子作为输入，看看句子 ID 是否对你有意义。";return{c(){a=o("p"),a.innerHTML=U},l(M){a=m(M,"P",{"data-svelte-h":!0}),d(a)!=="svelte-12p2p31"&&(a.innerHTML=U)},m(M,u){e(M,a,u)},p:qn,d(M){M&&n(a)}}}function Ma(b){let a,U;return a=new Dn({props:{id:"PrX4CjrVnNc"}}),{c(){J(a.$$.fragment)},l(M){y(a.$$.fragment,M)},m(M,u){j(a,M,u),U=!0},i(M){U||(i(a.$$.fragment,M),U=!0)},o(M){r(a.$$.fragment,M),U=!1},d(M){T(a,M)}}}function ca(b){let a,U;return a=new Dn({props:{id:"0E7ltQB7fM8"}}),{c(){J(a.$$.fragment)},l(M){y(a.$$.fragment,M)},m(M,u){j(a,M,u),U=!0},i(M){U||(i(a.$$.fragment,M),U=!0)},o(M){r(a.$$.fragment,M),U=!1},d(M){T(a,M)}}}function ra(b){let a,U='首先，我们需要我们的输入 tokenization 并将其传递给模型。这个过程与 <a href="/course/chapter2">第二章</a> 中的方法完全相同；我们使用 <code>TFAutoXxx</code> 类实例化 tokenizer 和模型，然后将我们的示例传递给它们：',M,u,k,w,I="由于我们在此使用了 <code>TFAutoModelForTokenClassification</code> ，所以我们得到了输入序列中每个 token 的一组 logits：",Q,x,f,C,$;return u=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBURkF1dG9Nb2RlbEZvclRva2VuQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIyZGJtZHolMkZiZXJ0LWxhcmdlLWNhc2VkLWZpbmV0dW5lZC1jb25sbDAzLWVuZ2xpc2glMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JUb2tlbkNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KSUwQSUwQWV4YW1wbGUlMjAlM0QlMjAlMjJNeSUyMG5hbWUlMjBpcyUyMFN5bHZhaW4lMjBhbmQlMjBJJTIwd29yayUyMGF0JTIwSHVnZ2luZyUyMEZhY2UlMjBpbiUyMEJyb29rbHluLiUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihleGFtcGxlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJ0ZiUyMiklMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForTokenClassification

model_checkpoint = <span class="hljs-string">&quot;dbmdz/bert-large-cased-finetuned-conll03-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = TFAutoModelForTokenClassification.from_pretrained(model_checkpoint)

example = <span class="hljs-string">&quot;My name is Sylvain and I work at Hugging Face in Brooklyn.&quot;</span>
inputs = tokenizer(example, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)
outputs = model(**inputs)`,wrap:!1}}),x=new h({props:{code:"cHJpbnQoaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVELnNoYXBlKSUwQXByaW50KG91dHB1dHMubG9naXRzLnNoYXBlKQ==",highlighted:`<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].shape)
<span class="hljs-built_in">print</span>(outputs.logits.shape)`,wrap:!1}}),C=new h({props:{code:"KDElMkMlMjAxOSklMEEoMSUyQyUyMDE5JTJDJTIwOSk=",highlighted:`(<span class="hljs-number">1</span>, <span class="hljs-number">19</span>)
(<span class="hljs-number">1</span>, <span class="hljs-number">19</span>, <span class="hljs-number">9</span>)`,wrap:!1}}),{c(){a=o("p"),a.innerHTML=U,M=t(),J(u.$$.fragment),k=t(),w=o("p"),w.innerHTML=I,Q=t(),J(x.$$.fragment),f=t(),J(C.$$.fragment)},l(c){a=m(c,"P",{"data-svelte-h":!0}),d(a)!=="svelte-pmzoda"&&(a.innerHTML=U),M=p(c),y(u.$$.fragment,c),k=p(c),w=m(c,"P",{"data-svelte-h":!0}),d(w)!=="svelte-1gt69qu"&&(w.innerHTML=I),Q=p(c),y(x.$$.fragment,c),f=p(c),y(C.$$.fragment,c)},m(c,g){e(c,a,g),e(c,M,g),j(u,c,g),e(c,k,g),e(c,w,g),e(c,Q,g),j(x,c,g),e(c,f,g),j(C,c,g),$=!0},i(c){$||(i(u.$$.fragment,c),i(x.$$.fragment,c),i(C.$$.fragment,c),$=!0)},o(c){r(u.$$.fragment,c),r(x.$$.fragment,c),r(C.$$.fragment,c),$=!1},d(c){c&&(n(a),n(M),n(k),n(w),n(Q),n(f)),T(u,c),T(x,c),T(C,c)}}}function ia(b){let a,U='首先，我们需要将我们的输入进行 tokenization 并将其传递给模型。这个过程与 <a href="/course/chapter2">第二章</a> 中的方法完全相同；我们使用 <code>AutoXxx</code> 类实例化 tokenizer 和模型，然后将我们的示例传递给它们：',M,u,k,w,I="由于我们在此使用了 <code>AutoModelForTokenClassification</code> ，所以我们得到了输入序列中每个 token 的一组 logits：",Q,x,f,C,$;return u=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JUb2tlbkNsYXNzaWZpY2F0aW9uJTBBJTBBbW9kZWxfY2hlY2twb2ludCUyMCUzRCUyMCUyMmRibWR6JTJGYmVydC1sYXJnZS1jYXNlZC1maW5ldHVuZWQtY29ubGwwMy1lbmdsaXNoJTIyJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclRva2VuQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQpJTBBJTBBZXhhbXBsZSUyMCUzRCUyMCUyMk15JTIwbmFtZSUyMGlzJTIwU3lsdmFpbiUyMGFuZCUyMEklMjB3b3JrJTIwYXQlMjBIdWdnaW5nJTIwRmFjZSUyMGluJTIwQnJvb2tseW4uJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKGV4YW1wbGUlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cyk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForTokenClassification

model_checkpoint = <span class="hljs-string">&quot;dbmdz/bert-large-cased-finetuned-conll03-english&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = AutoModelForTokenClassification.from_pretrained(model_checkpoint)

example = <span class="hljs-string">&quot;My name is Sylvain and I work at Hugging Face in Brooklyn.&quot;</span>
inputs = tokenizer(example, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
outputs = model(**inputs)`,wrap:!1}}),x=new h({props:{code:"cHJpbnQoaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVELnNoYXBlKSUwQXByaW50KG91dHB1dHMubG9naXRzLnNoYXBlKQ==",highlighted:`<span class="hljs-built_in">print</span>(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].shape)
<span class="hljs-built_in">print</span>(outputs.logits.shape)`,wrap:!1}}),C=new h({props:{code:"dG9yY2guU2l6ZSglNUIxJTJDJTIwMTklNUQpJTBBdG9yY2guU2l6ZSglNUIxJTJDJTIwMTklMkMlMjA5JTVEKQ==",highlighted:`torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">19</span>])
torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">19</span>, <span class="hljs-number">9</span>])`,wrap:!1}}),{c(){a=o("p"),a.innerHTML=U,M=t(),J(u.$$.fragment),k=t(),w=o("p"),w.innerHTML=I,Q=t(),J(x.$$.fragment),f=t(),J(C.$$.fragment)},l(c){a=m(c,"P",{"data-svelte-h":!0}),d(a)!=="svelte-12e47lh"&&(a.innerHTML=U),M=p(c),y(u.$$.fragment,c),k=p(c),w=m(c,"P",{"data-svelte-h":!0}),d(w)!=="svelte-1su81kw"&&(w.innerHTML=I),Q=p(c),y(x.$$.fragment,c),f=p(c),y(C.$$.fragment,c)},m(c,g){e(c,a,g),e(c,M,g),j(u,c,g),e(c,k,g),e(c,w,g),e(c,Q,g),j(x,c,g),e(c,f,g),j(C,c,g),$=!0},i(c){$||(i(u.$$.fragment,c),i(x.$$.fragment,c),i(C.$$.fragment,c),$=!0)},o(c){r(u.$$.fragment,c),r(x.$$.fragment,c),r(C.$$.fragment,c),$=!1},d(c){c&&(n(a),n(M),n(k),n(w),n(Q),n(f)),T(u,c),T(x,c),T(C,c)}}}function Ja(b){let a,U;return a=new h({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFwcm9iYWJpbGl0aWVzJTIwJTNEJTIwdGYubWF0aC5zb2Z0bWF4KG91dHB1dHMubG9naXRzJTJDJTIwYXhpcyUzRC0xKSU1QjAlNUQlMEFwcm9iYWJpbGl0aWVzJTIwJTNEJTIwcHJvYmFiaWxpdGllcy5udW1weSgpLnRvbGlzdCgpJTBBcHJlZGljdGlvbnMlMjAlM0QlMjB0Zi5tYXRoLmFyZ21heChvdXRwdXRzLmxvZ2l0cyUyQyUyMGF4aXMlM0QtMSklNUIwJTVEJTBBcHJlZGljdGlvbnMlMjAlM0QlMjBwcmVkaWN0aW9ucy5udW1weSgpLnRvbGlzdCgpJTBBcHJpbnQocHJlZGljdGlvbnMp",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

probabilities = tf.math.softmax(outputs.logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]
probabilities = probabilities.numpy().tolist()
predictions = tf.math.argmax(outputs.logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]
predictions = predictions.numpy().tolist()
<span class="hljs-built_in">print</span>(predictions)`,wrap:!1}}),{c(){J(a.$$.fragment)},l(M){y(a.$$.fragment,M)},m(M,u){j(a,M,u),U=!0},i(M){U||(i(a.$$.fragment,M),U=!0)},o(M){r(a.$$.fragment,M),U=!1},d(M){T(a,M)}}}function ya(b){let a,U;return a=new h({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFwcm9iYWJpbGl0aWVzJTIwJTNEJTIwdG9yY2gubm4uZnVuY3Rpb25hbC5zb2Z0bWF4KG91dHB1dHMubG9naXRzJTJDJTIwZGltJTNELTEpJTVCMCU1RC50b2xpc3QoKSUwQXByZWRpY3Rpb25zJTIwJTNEJTIwb3V0cHV0cy5sb2dpdHMuYXJnbWF4KGRpbSUzRC0xKSU1QjAlNUQudG9saXN0KCklMEFwcmludChwcmVkaWN0aW9ucyk=",highlighted:`<span class="hljs-keyword">import</span> torch

probabilities = torch.nn.functional.softmax(outputs.logits, dim=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>].tolist()
predictions = outputs.logits.argmax(dim=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>].tolist()
<span class="hljs-built_in">print</span>(predictions)`,wrap:!1}}),{c(){J(a.$$.fragment)},l(M){y(a.$$.fragment,M)},m(M,u){j(a,M,u),U=!0},i(M){U||(i(a.$$.fragment,M),U=!0)},o(M){r(a.$$.fragment,M),U=!1},d(M){T(a,M)}}}function ja(b){let a,U,M,u,k,w,I,Q,x,f,C,$,c='在本节中，我们将仔细研究 🤗 Transformers 中 tokenizer 的功能。到目前为止，我们只使用它们来对文本进行 tokenize 或将token ID 解码回文本，但是 tokenizer —— 特别是由🤗 Tokenizers 库支持的 tokenizer —— 能够做的事情还有很多。为了说明这些附加功能，我们将探讨如何复现在 <a href="/course/chapter1">第一章</a> 中首次遇到的 <code>token-classification</code> （我们称之为 <code>ner</code> ） 和 <code>question-answering</code> 管道的结果。',g,v,ol,V,Pn='在接下来的讨论中，我们会经常区分“慢速”和“快速” tokenizer 。慢速 tokenizer 是在 🤗 Transformers 库中用 Python 编写的，而快速版本是由 🤗 Tokenizers 提供的，它们是用 Rust 编写的。如果你还记得在 <a href="/course/chapter5/3">第五章</a> 中对比了快速和慢速 tokenizer 对药物审查数据集进行 tokenize 所需的时间的这张表，你应该理解为什么我们称它们为“快速”和“慢速”：',ml,H,Kn=`|               | 快速 tokenizer      | 慢速 tokenizer
:--------------:|:--------------:|:-------------: <code>batched=True</code> | 10.8s          | 4min41s <code>batched=False</code> | 59.2s          | 5min3s`,ul,S,dl,D,hl,X,wl,G,se="tokenizer 的输出不是简单的 Python 字典；我们得到的实际上是一个特殊的 <code>BatchEncoding</code> 对象。它是字典的子类（这就是为什么我们之前能够直接使用索引获取结果的原因），但是它还提供了一些主要由快速 tokenizer 提供的附加方法。",xl,Y,le="除了它们的并行化能力之外，快速 tokenizer 的关键功能是它们始终跟踪最终 token 相对于的原始文本的映射——我们称之为 <code>偏移映射（offset mapping）</code> 。这反过来又解锁了如将每个词映射到它生成的 token，或者将原始文本的每个字符映射到它所在的 token 等功能。",bl,L,ne="让我们看一个例子：",gl,F,Cl,O,ee="如前所述，我们从 tokenizer 得到了一个 <code>BatchEncoding</code> 对象：",kl,q,fl,P,ae="由于 <code>AutoTokenizer</code> 类默认选择快速 tokenizer 因此我们可以使用 <code>BatchEncoding</code> 对象提供的附加方法。我们有两种方法来检查我们的 tokenizer 是快速的还是慢速的。我们可以检查 <code>tokenizer</code> 的 <code>is_fast</code> 属性：",Il,K,$l,ss,Ql,ls,te="或检查我们 <code>encoding</code> 的 <code>is_fast</code> 属性：",Al,ns,zl,es,Zl,as,pe="让我们看看快速 tokenizer 能让为我们提供什么功能。首先，我们可以直接得到Ttokenization 之前的单词而无需将 ID 转换回单词：",Bl,ts,El,ps,Nl,Ms,Me="在这种情况下，索引 5 处的 token 是 <code>##yl</code> ，它是原始句子中“Sylvain”一词的一部分。我们也可以使用 <code>word_ids()</code> 方法来获取每个 token 原始单词的索引：",Sl,cs,Rl,rs,_l,is,ce="我们可以看到 tokenizer 的特殊 token <code>[CLS]</code> 和 <code>[SEP]</code> 被映射到 <code>None</code> ，然后每个 token 都映射到它来源的单词。这对于确定一个 token 是否在单词的开头或两个 token 是否在同一个单词中特别有用。对于 BERT 类型（BERT-like）的的 tokenizer 我们也可以依靠 <code>##</code> 前缀来实现这个功能；不过只要是快速 tokenizer 它所提供的 <code>word_ids()</code> 方法适用于任何类型的 tokenizer 。在下一章，我们将看到如何利用这种能力，将我们为每个词正确地对应到词汇任务中的标签，如命名实体识别（NER）和词性标注（POS）。我们也可以使用它在掩码语言建模（masked language modeling）中来遮盖来自同一词的所有 token（一种称为 <code>全词掩码（whole word masking）</code> 的技术）。",Wl,R,vl,Js,re="同样，我们还有一个 <code>sentence_ids()</code> 方法，可以用它把一个 token 映射到它原始的句子（尽管在这种情况下，tokenizer 返回的 <code>token_type_ids</code>也可以为我们提供相同的信息）。",Vl,ys,ie="最后，我们可以通过 <code>word_to_chars()</code> 或 <code>token_to_chars()</code> 和 <code>char_to_word()</code> 或 <code>char_to_token()</code> 方法，将任何词或 token 映射到原始文本中的字符，反之亦然。例如， <code>word_ids()</code> 方法告诉我们 <code>##yl</code> 是索引 3 处单词的一部分，但它是句子中的哪个单词？我们可以这样找出来：",Hl,js,Dl,Ts,Xl,Us,Je="如前所述，这一切都是由于快速分词器跟踪每个 token 来自的文本范围的一组<em>偏移</em>。为了阐明它们的作用，接下来我们将展示如何手动复现 <code>token-classification</code> 管道的结果。",Gl,_,Yl,os,Ll,ms,ye='在 <a href="/course/chapter1">第一章</a> 我们初次尝试实现命名实体识别（NER）——该任务是确定文本的哪些部分对应于人名、地名或组织名等实体——当时是使用🤗 Transformers 的 <code>pipeline()</code> 函数实现的。然后，在 <a href="/course/chapter2">第二章</a> ，我们看到一个管道如何将获取原始文本到预测结果的三个阶段整合在一起：tokenize、通过模型处理输入和后处理。 <code>token-classification</code> 管道中的前两步与其他任何管道中的步骤相同，但后处理稍有复杂——让我们看看具体情况！',Fl,A,z,Jl,us,Ol,ds,je='首先，让我们获取一个 token 分类管道，以便我们可以手动比较一些结果。这次我们选用的模型是 <a href="https://huggingface.co/dbmdz/bert-large-cased-finetuned-conll03-english" rel="nofollow"><code>dbmdz/bert-large-cased-finetuned-conll03-english</code></a> ；我们使用它对句子进行 NER：',ql,hs,Pl,ws,Kl,xs,Te="模型正确地识别出：“Sylvain”是一个人，“Hugging Face”是一个组织，以及“Brooklyn”是一个地点。我们也可以让管道将同一实体的 token 组合在一起：",sn,bs,ln,gs,nn,Cs,Ue="选择不同的 <code>aggregation_strategy</code> 可以更改每个分组实体计算的策略。对于 <code>simple</code> 策略，最终的分数就是给定实体中每个 token 的分数的平均值：例如，“Sylvain”的分数是我们在前一个例子中看到的 token <code>S</code> ， <code>##yl</code> ， <code>##va</code> ，和 <code>##in</code> 的分数的平均值。其他可用的策略包括：",en,ks,oe="<li>“first”，其中每个实体的分数是该实体的第一个 token 的分数（因此对于“Sylvain”，分数将是 0.993828，这是“S”的分数）</li> <li>“max”，其中每个实体的分数是该实体中 token 的最大分数（因此对于“Hugging Face”，分数将是 0.98879766，即“Face”的分数）</li> <li>“average”，其中每个实体的分数是组成该实体的单词分数的平均值（因此对于“Sylvain”，与“simple”策略相同，但“Hugging Face”的得分将是 0.9819，这是“Hugging”的分数 0.975 和“Face”的分数 0.98879 的平均值）</li>",an,fs,me="现在让我们看看如何在不使用 <code>pipeline()</code> 函数的情况下获得这些结果！",tn,Is,pn,Z,B,yl,$s,ue="我们有一个包含 19 个 token 序列的 batch 和有 9 个不同的标签类型，所以模型的输出形状为 1 x 19 x 9。像文本分类管道一样，我们使用 softmax 函数将这些 logits 转化为概率，并取 argmax 来得到预测（请注意，我们可以在 logits 上直接算取 argmax，因为 softmax 不会改变顺序）：",Mn,E,N,jl,Qs,cn,As,de="<code>model.config.id2label</code> 属性包含索引到标签的映射，我们可以用它来将预测转化为标签：",rn,zs,Jn,Zs,yn,Bs,he="如前所述，这里有 9 个标签： <code>O</code> 是不在任何实体中的 token 的标签（它代表“outside”），然后我们为每种类型的实体（杂项、人员、组织和位置）提供两个标签：标签 <code>B-XXX</code> 表示 token 在实体 <code>XXX</code> 的开头，标签 <code>I-XXX</code> 表示 token 在实体 <code>XXX</code> 内部。例如，在当前的例子，我们期望我们的模型将 token <code>S</code> 分类为 <code>B-PER</code> （人物实体的开始），并且将 token <code>##yl</code> ， <code>##va</code> 和 <code>##in</code> 分类为 <code>I-PER</code> （人物实体的内部）",jn,Es,we="你可能会觉得上面模型的输出是错误的，因为它给所有这四个 token 都标上了 <code>I-PER</code> 标签，但这样理解并不完全正确。对于 <code>B-</code> 和 <code>I-</code> 标签，实际上有两种格式：IOB1 和 IOB2。我们介绍的是 IOB2 格式（如下图所示的粉色），而在 IOB1 格式（蓝色）中，以 <code>B-</code> 开头的标签只用于分隔同一类型的两个相邻实体。我们正在使用的模型在使用该格式的数据集上进行了微调，这就是为什么它将 <code>S</code> token 标上了 <code>I-PER</code> 标签的原因。",Tn,W,xe='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter6/IOB_versions.svg" alt="IOB1 vs IOB2 format"/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter6/IOB_versions-dark.svg" alt="IOB1 vs IOB2 format"/>',Un,Ns,be="有了这个映射字典，我们就可以几乎完全复现管道的结果 —— 我们只需要获取每个没有被分类为 O 的 token 的得分和标签：",on,Ss,mn,Rs,un,_s,ge="这与我们之前的结果非常相似，但有一点不同：pipeline 还给我们提供了每个实体在原始句子中的 <code>start</code> 和 <code>end</code> 的信息。如果要复现这个特性，这就是我们的偏移映射要发挥作用的地方。要获得偏移量，我们只需要在使用 tokenizer 器时设置 <code>return_offsets_mapping=True</code> ：",dn,Ws,hn,vs,wn,Vs,Ce="每个元组都是每个 token 对应的文本范围，其中 <code>(0, 0)</code> 是为特殊 token 保留的。我们之前看到索引 5 的 token 是 <code>##yl</code> ，它所对应的偏移量是 <code>(12, 14)</code> 。如果我们截取我们例子中的对应片段：",xn,Hs,bn,Ds,ke="我们会得到没有 <code>##</code> 的文本：",gn,Xs,Cn,Gs,fe="使用这个，我们现在可以完成之前的想法：",kn,Ys,fn,Ls,In,Fs,Ie="我们得到了与第一条 pipeline 相同的结果！",$n,Os,Qn,qs,$e="使用偏移来确定每个实体的开始和结束的索引很方便，但这并不是它唯一的用法。当我们希望将实体分组在一起时，偏移映射将为我们省去很多复杂的代码。例如，如果我们想将 <code>Hu</code> 、 <code>##gging</code> 和 <code>Face</code> token 分组在一起，我们可以制定特殊规则，比如说前两个应该在去除 <code>##</code> 的同时连在一起， <code>Face</code> 应该在不以 <code>##</code> 开头的情况下增加空格 —— 但这些规则只适用于这种特定类型的分词器。当我们使用 SentencePiece 或 Byte-Pair-Encoding 分词器（在本章后面讨论）时就要重新写另外一套规则。",An,Ps,Qe="有了偏移量，就可以免去为特定分词器定制特殊的分组规则：我们只需要取原始文本中以第一个 token 开始和最后一个 token 结束的范围。因此，假如说我们有 <code>Hu</code> 、 <code>##gging</code> 和 <code>Face</code> token，我们只需要从字符 33（ <code>Hu</code> 的开始）截取到字符 45（ <code>Face</code> 的结束）：",zn,Ks,Zn,sl,Bn,ll,Ae="为了编写处理预测结果并分组实体的代码，我们将对连续标记为 <code>I-XXX</code> 的实体进行分组，因为只有实体的第一个 token 可以被标记为 <code>B-XXX</code> 或 <code>I-XXX</code> ，因此，当我们遇到实体 <code>O</code> 、新类型的实体或 <code>B-XXX</code> 时，我们就可以停止聚合同一类型实体。",En,nl,Nn,el,ze="我们得到了与第二条 pipeline 相同的结果！",Sn,al,Rn,tl,Ze="另一个非常需要偏移量的任务领域是问答。我们将在下一部分深入探索这个 pipeline。同时我们也会看到🤗 Transformers 库中 tokenizer 的最后一个特性：在我们将输入超过给定长度时，处理溢出的 tokens。",_n,pl,Wn,Ul,vn;k=new sa({props:{fw:b[0]}}),I=new Tl({props:{title:"快速 tokenizer 的特殊能力",local:"快速 tokenizer 的特殊能力",headingTag:"h1"}});const Be=[ea,na],Ml=[];function Ee(s,l){return s[0]==="pt"?0:1}x=Ee(b),f=Ml[x]=Be[x](b),v=new Dn({props:{id:"g8quOxoqhHQ"}}),S=new On({props:{warning:!0,$$slots:{default:[aa]},$$scope:{ctx:b}}}),D=new Tl({props:{title:"批量编码",local:"批量编码",headingTag:"h2"}}),X=new Dn({props:{id:"3umI3tm27Vw"}}),F=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJiZXJ0LWJhc2UtY2FzZWQlMjIpJTBBZXhhbXBsZSUyMCUzRCUyMCUyMk15JTIwbmFtZSUyMGlzJTIwU3lsdmFpbiUyMGFuZCUyMEklMjB3b3JrJTIwYXQlMjBIdWdnaW5nJTIwRmFjZSUyMGluJTIwQnJvb2tseW4uJTIyJTBBZW5jb2RpbmclMjAlM0QlMjB0b2tlbml6ZXIoZXhhbXBsZSklMEFwcmludCh0eXBlKGVuY29kaW5nKSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;bert-base-cased&quot;</span>)
example = <span class="hljs-string">&quot;My name is Sylvain and I work at Hugging Face in Brooklyn.&quot;</span>
encoding = tokenizer(example)
<span class="hljs-built_in">print</span>(<span class="hljs-built_in">type</span>(encoding))`,wrap:!1}}),q=new h({props:{code:"JTNDY2xhc3MlMjAndHJhbnNmb3JtZXJzLnRva2VuaXphdGlvbl91dGlsc19iYXNlLkJhdGNoRW5jb2RpbmcnJTNF",highlighted:'&lt;<span class="hljs-keyword">class</span> <span class="hljs-string">&#x27;transformers.tokenization_utils_base.BatchEncoding&#x27;</span>&gt;',wrap:!1}}),K=new h({props:{code:"dG9rZW5pemVyLmlzX2Zhc3Q=",highlighted:"tokenizer.is_fast",wrap:!1}}),ss=new h({props:{code:"VHJ1ZQ==",highlighted:'<span class="hljs-literal">True</span>',wrap:!1}}),ns=new h({props:{code:"ZW5jb2RpbmcuaXNfZmFzdA==",highlighted:"encoding.is_fast",wrap:!1}}),es=new h({props:{code:"VHJ1ZQ==",highlighted:'<span class="hljs-literal">True</span>',wrap:!1}}),ts=new h({props:{code:"ZW5jb2RpbmcudG9rZW5zKCk=",highlighted:"encoding.tokens()",wrap:!1}}),ps=new h({props:{code:"JTVCJyU1QkNMUyU1RCclMkMlMjAnTXknJTJDJTIwJ25hbWUnJTJDJTIwJ2lzJyUyQyUyMCdTJyUyQyUyMCclMjMlMjN5bCclMkMlMjAnJTIzJTIzdmEnJTJDJTIwJyUyMyUyM2luJyUyQyUyMCdhbmQnJTJDJTIwJ0knJTJDJTIwJ3dvcmsnJTJDJTIwJ2F0JyUyQyUyMCdIdSclMkMlMjAnJTIzJTIzZ2dpbmcnJTJDJTIwJ0ZhY2UnJTJDJTIwJ2luJyUyQyUwQSUyMCdCcm9va2x5biclMkMlMjAnLiclMkMlMjAnJTVCU0VQJTVEJyU1RA==",highlighted:`[<span class="hljs-string">&#x27;[CLS]&#x27;</span>, <span class="hljs-string">&#x27;My&#x27;</span>, <span class="hljs-string">&#x27;name&#x27;</span>, <span class="hljs-string">&#x27;is&#x27;</span>, <span class="hljs-string">&#x27;S&#x27;</span>, <span class="hljs-string">&#x27;##yl&#x27;</span>, <span class="hljs-string">&#x27;##va&#x27;</span>, <span class="hljs-string">&#x27;##in&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;I&#x27;</span>, <span class="hljs-string">&#x27;work&#x27;</span>, <span class="hljs-string">&#x27;at&#x27;</span>, <span class="hljs-string">&#x27;Hu&#x27;</span>, <span class="hljs-string">&#x27;##gging&#x27;</span>, <span class="hljs-string">&#x27;Face&#x27;</span>, <span class="hljs-string">&#x27;in&#x27;</span>,
 <span class="hljs-string">&#x27;Brooklyn&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;[SEP]&#x27;</span>]`,wrap:!1}}),cs=new h({props:{code:"ZW5jb2Rpbmcud29yZF9pZHMoKQ==",highlighted:"encoding.word_ids()",wrap:!1}}),rs=new h({props:{code:"JTVCTm9uZSUyQyUyMDAlMkMlMjAxJTJDJTIwMiUyQyUyMDMlMkMlMjAzJTJDJTIwMyUyQyUyMDMlMkMlMjA0JTJDJTIwNSUyQyUyMDYlMkMlMjA3JTJDJTIwOCUyQyUyMDglMkMlMjA5JTJDJTIwMTAlMkMlMjAxMSUyQyUyMDEyJTJDJTIwTm9uZSU1RA==",highlighted:'[<span class="hljs-literal">None</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">3</span>, <span class="hljs-number">3</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>, <span class="hljs-number">10</span>, <span class="hljs-number">11</span>, <span class="hljs-number">12</span>, <span class="hljs-literal">None</span>]',wrap:!1}}),R=new On({props:{$$slots:{default:[ta]},$$scope:{ctx:b}}}),js=new h({props:{code:"c3RhcnQlMkMlMjBlbmQlMjAlM0QlMjBlbmNvZGluZy53b3JkX3RvX2NoYXJzKDMpJTBBZXhhbXBsZSU1QnN0YXJ0JTNBZW5kJTVE",highlighted:`start, end = encoding.word_to_chars(<span class="hljs-number">3</span>)
example[start:end]`,wrap:!1}}),Ts=new h({props:{code:"U3lsdmFpbg==",highlighted:"Sylvain",wrap:!1}}),_=new On({props:{$$slots:{default:[pa]},$$scope:{ctx:b}}}),os=new Tl({props:{title:"token-classification 管道内部流程",local:"token-classification 管道内部流程",headingTag:"h2"}});const Ne=[ca,Ma],cl=[];function Se(s,l){return s[0]==="pt"?0:1}A=Se(b),z=cl[A]=Ne[A](b),us=new Tl({props:{title:"使用管道获得基本结果",local:"使用管道获得基本结果",headingTag:"h3"}}),hs=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBdG9rZW5fY2xhc3NpZmllciUyMCUzRCUyMHBpcGVsaW5lKCUyMnRva2VuLWNsYXNzaWZpY2F0aW9uJTIyKSUwQXRva2VuX2NsYXNzaWZpZXIoJTIyTXklMjBuYW1lJTIwaXMlMjBTeWx2YWluJTIwYW5kJTIwSSUyMHdvcmslMjBhdCUyMEh1Z2dpbmclMjBGYWNlJTIwaW4lMjBCcm9va2x5bi4lMjIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

token_classifier = pipeline(<span class="hljs-string">&quot;token-classification&quot;</span>)
token_classifier(<span class="hljs-string">&quot;My name is Sylvain and I work at Hugging Face in Brooklyn.&quot;</span>)`,wrap:!1}}),ws=new h({props:{code:"JTVCJTdCJ2VudGl0eSclM0ElMjAnSS1QRVInJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTk5MzgyOCUyQyUyMCdpbmRleCclM0ElMjA0JTJDJTIwJ3dvcmQnJTNBJTIwJ1MnJTJDJTIwJ3N0YXJ0JyUzQSUyMDExJTJDJTIwJ2VuZCclM0ElMjAxMiU3RCUyQyUwQSUyMCU3QidlbnRpdHknJTNBJTIwJ0ktUEVSJyUyQyUyMCdzY29yZSclM0ElMjAwLjk5ODE1NDc2JTJDJTIwJ2luZGV4JyUzQSUyMDUlMkMlMjAnd29yZCclM0ElMjAnJTIzJTIzeWwnJTJDJTIwJ3N0YXJ0JyUzQSUyMDEyJTJDJTIwJ2VuZCclM0ElMjAxNCU3RCUyQyUwQSUyMCU3QidlbnRpdHknJTNBJTIwJ0ktUEVSJyUyQyUyMCdzY29yZSclM0ElMjAwLjk5NTkwNzI1JTJDJTIwJ2luZGV4JyUzQSUyMDYlMkMlMjAnd29yZCclM0ElMjAnJTIzJTIzdmEnJTJDJTIwJ3N0YXJ0JyUzQSUyMDE0JTJDJTIwJ2VuZCclM0ElMjAxNiU3RCUyQyUwQSUyMCU3QidlbnRpdHknJTNBJTIwJ0ktUEVSJyUyQyUyMCdzY29yZSclM0ElMjAwLjk5OTIzMjclMkMlMjAnaW5kZXgnJTNBJTIwNyUyQyUyMCd3b3JkJyUzQSUyMCclMjMlMjNpbiclMkMlMjAnc3RhcnQnJTNBJTIwMTYlMkMlMjAnZW5kJyUzQSUyMDE4JTdEJTJDJTBBJTIwJTdCJ2VudGl0eSclM0ElMjAnSS1PUkcnJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTczODkzMzQlMkMlMjAnaW5kZXgnJTNBJTIwMTIlMkMlMjAnd29yZCclM0ElMjAnSHUnJTJDJTIwJ3N0YXJ0JyUzQSUyMDMzJTJDJTIwJ2VuZCclM0ElMjAzNSU3RCUyQyUwQSUyMCU3QidlbnRpdHknJTNBJTIwJ0ktT1JHJyUyQyUyMCdzY29yZSclM0ElMjAwLjk3NjExNSUyQyUyMCdpbmRleCclM0ElMjAxMyUyQyUyMCd3b3JkJyUzQSUyMCclMjMlMjNnZ2luZyclMkMlMjAnc3RhcnQnJTNBJTIwMzUlMkMlMjAnZW5kJyUzQSUyMDQwJTdEJTJDJTBBJTIwJTdCJ2VudGl0eSclM0ElMjAnSS1PUkcnJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTg4Nzk3NjYlMkMlMjAnaW5kZXgnJTNBJTIwMTQlMkMlMjAnd29yZCclM0ElMjAnRmFjZSclMkMlMjAnc3RhcnQnJTNBJTIwNDElMkMlMjAnZW5kJyUzQSUyMDQ1JTdEJTJDJTBBJTIwJTdCJ2VudGl0eSclM0ElMjAnSS1MT0MnJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTkzMjEwNTUlMkMlMjAnaW5kZXgnJTNBJTIwMTYlMkMlMjAnd29yZCclM0ElMjAnQnJvb2tseW4nJTJDJTIwJ3N0YXJ0JyUzQSUyMDQ5JTJDJTIwJ2VuZCclM0ElMjA1NyU3RCU1RA==",highlighted:`[{<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9993828</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">4</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;S&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">11</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">12</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99815476</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">5</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##yl&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">12</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">14</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99590725</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">6</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##va&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">14</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">16</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9992327</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">7</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##in&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">16</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">18</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97389334</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">12</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Hu&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">33</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">35</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.976115</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">13</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##gging&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">35</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">40</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.98879766</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">14</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Face&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">41</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">45</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-LOC&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99321055</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">16</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Brooklyn&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">49</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">57</span>}]`,wrap:!1}}),bs=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBdG9rZW5fY2xhc3NpZmllciUyMCUzRCUyMHBpcGVsaW5lKCUyMnRva2VuLWNsYXNzaWZpY2F0aW9uJTIyJTJDJTIwYWdncmVnYXRpb25fc3RyYXRlZ3klM0QlMjJzaW1wbGUlMjIpJTBBdG9rZW5fY2xhc3NpZmllciglMjJNeSUyMG5hbWUlMjBpcyUyMFN5bHZhaW4lMjBhbmQlMjBJJTIwd29yayUyMGF0JTIwSHVnZ2luZyUyMEZhY2UlMjBpbiUyMEJyb29rbHluLiUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

token_classifier = pipeline(<span class="hljs-string">&quot;token-classification&quot;</span>, aggregation_strategy=<span class="hljs-string">&quot;simple&quot;</span>)
token_classifier(<span class="hljs-string">&quot;My name is Sylvain and I work at Hugging Face in Brooklyn.&quot;</span>)`,wrap:!1}}),gs=new h({props:{code:"JTVCJTdCJ2VudGl0eV9ncm91cCclM0ElMjAnUEVSJyUyQyUyMCdzY29yZSclM0ElMjAwLjk5ODE2OTQlMkMlMjAnd29yZCclM0ElMjAnU3lsdmFpbiclMkMlMjAnc3RhcnQnJTNBJTIwMTElMkMlMjAnZW5kJyUzQSUyMDE4JTdEJTJDJTBBJTIwJTdCJ2VudGl0eV9ncm91cCclM0ElMjAnT1JHJyUyQyUyMCdzY29yZSclM0ElMjAwLjk3OTYwMjA0JTJDJTIwJ3dvcmQnJTNBJTIwJ0h1Z2dpbmclMjBGYWNlJyUyQyUyMCdzdGFydCclM0ElMjAzMyUyQyUyMCdlbmQnJTNBJTIwNDUlN0QlMkMlMEElMjAlN0InZW50aXR5X2dyb3VwJyUzQSUyMCdMT0MnJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTkzMjEwNTUlMkMlMjAnd29yZCclM0ElMjAnQnJvb2tseW4nJTJDJTIwJ3N0YXJ0JyUzQSUyMDQ5JTJDJTIwJ2VuZCclM0ElMjA1NyU3RCU1RA==",highlighted:`[{<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9981694</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Sylvain&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">11</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">18</span>},
 {<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97960204</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Hugging Face&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">33</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">45</span>},
 {<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;LOC&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99321055</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Brooklyn&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">49</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">57</span>}]`,wrap:!1}}),Is=new Tl({props:{title:"从输入到预测",local:"从输入到预测",headingTag:"h3"}});const Re=[ia,ra],rl=[];function _e(s,l){return s[0]==="pt"?0:1}Z=_e(b),B=rl[Z]=Re[Z](b);const We=[ya,Ja],il=[];function ve(s,l){return s[0]==="pt"?0:1}return E=ve(b),N=il[E]=We[E](b),Qs=new h({props:{code:"JTVCMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDQlMkMlMjA0JTJDJTIwNCUyQyUyMDQlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwNiUyQyUyMDYlMkMlMjA2JTJDJTIwMCUyQyUyMDglMkMlMjAwJTJDJTIwMCU1RA==",highlighted:'[<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">4</span>, <span class="hljs-number">4</span>, <span class="hljs-number">4</span>, <span class="hljs-number">4</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">6</span>, <span class="hljs-number">6</span>, <span class="hljs-number">6</span>, <span class="hljs-number">0</span>, <span class="hljs-number">8</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]',wrap:!1}}),zs=new h({props:{code:"bW9kZWwuY29uZmlnLmlkMmxhYmVs",highlighted:"model.config.id2label",wrap:!1}}),Zs=new h({props:{code:"JTdCMCUzQSUyMCdPJyUyQyUwQSUyMDElM0ElMjAnQi1NSVNDJyUyQyUwQSUyMDIlM0ElMjAnSS1NSVNDJyUyQyUwQSUyMDMlM0ElMjAnQi1QRVInJTJDJTBBJTIwNCUzQSUyMCdJLVBFUiclMkMlMEElMjA1JTNBJTIwJ0ItT1JHJyUyQyUwQSUyMDYlM0ElMjAnSS1PUkcnJTJDJTBBJTIwNyUzQSUyMCdCLUxPQyclMkMlMEElMjA4JTNBJTIwJ0ktTE9DJyU3RA==",highlighted:`{<span class="hljs-number">0</span>: <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-number">1</span>: <span class="hljs-string">&#x27;B-MISC&#x27;</span>,
 <span class="hljs-number">2</span>: <span class="hljs-string">&#x27;I-MISC&#x27;</span>,
 <span class="hljs-number">3</span>: <span class="hljs-string">&#x27;B-PER&#x27;</span>,
 <span class="hljs-number">4</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>,
 <span class="hljs-number">5</span>: <span class="hljs-string">&#x27;B-ORG&#x27;</span>,
 <span class="hljs-number">6</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>,
 <span class="hljs-number">7</span>: <span class="hljs-string">&#x27;B-LOC&#x27;</span>,
 <span class="hljs-number">8</span>: <span class="hljs-string">&#x27;I-LOC&#x27;</span>}`,wrap:!1}}),Ss=new h({props:{code:"cmVzdWx0cyUyMCUzRCUyMCU1QiU1RCUwQXRva2VucyUyMCUzRCUyMGlucHV0cy50b2tlbnMoKSUwQSUwQWZvciUyMGlkeCUyQyUyMHByZWQlMjBpbiUyMGVudW1lcmF0ZShwcmVkaWN0aW9ucyklM0ElMEElMjAlMjAlMjAlMjBsYWJlbCUyMCUzRCUyMG1vZGVsLmNvbmZpZy5pZDJsYWJlbCU1QnByZWQlNUQlMEElMjAlMjAlMjAlMjBpZiUyMGxhYmVsJTIwISUzRCUyMCUyMk8lMjIlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXN1bHRzLmFwcGVuZCglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0IlMjJlbnRpdHklMjIlM0ElMjBsYWJlbCUyQyUyMCUyMnNjb3JlJTIyJTNBJTIwcHJvYmFiaWxpdGllcyU1QmlkeCU1RCU1QnByZWQlNUQlMkMlMjAlMjJ3b3JkJTIyJTNBJTIwdG9rZW5zJTVCaWR4JTVEJTdEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUwQXByaW50KHJlc3VsdHMp",highlighted:`results = []
tokens = inputs.tokens()

<span class="hljs-keyword">for</span> idx, pred <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(predictions):
    label = model.config.id2label[pred]
    <span class="hljs-keyword">if</span> label != <span class="hljs-string">&quot;O&quot;</span>:
        results.append(
            {<span class="hljs-string">&quot;entity&quot;</span>: label, <span class="hljs-string">&quot;score&quot;</span>: probabilities[idx][pred], <span class="hljs-string">&quot;word&quot;</span>: tokens[idx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ZCclM0ElMjAnRmFjZSclN0QlMkMlMEElMjAlN0InZW50aXR5JyUzQSUyMCdJLUxPQyclMkMlMjAnc2NvcmUnJTNBJTIwMC45OTMyMTA1NSUyQyUyMCdpbmRleCclM0ElMjAxNiUyQyUyMCd3b3JkJyUzQSUyMCdCcm9va2x5biclN0QlNUQ=",highlighted:`[{<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9993828</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">4</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;S&#x27;</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99815476</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">5</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##yl&#x27;</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99590725</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">6</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##va&#x27;</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9992327</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">7</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##in&#x27;</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97389334</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">12</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Hu&#x27;</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.976115</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">13</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##gging&#x27;</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.98879766</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">14</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Face&#x27;</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-LOC&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99321055</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">16</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Brooklyn&#x27;</span>}]`,wrap:!1}}),Ws=new h({props:{code:"aW5wdXRzX3dpdGhfb2Zmc2V0cyUyMCUzRCUyMHRva2VuaXplcihleGFtcGxlJTJDJTIwcmV0dXJuX29mZnNldHNfbWFwcGluZyUzRFRydWUpJTBBaW5wdXRzX3dpdGhfb2Zmc2V0cyU1QiUyMm9mZnNldF9tYXBwaW5nJTIyJTVE",highlighted:`inputs_with_offsets = tokenizer(example, return_offsets_mapping=<span class="hljs-literal">True</span>)
inputs_with_offsets[<span class="hljs-string">&quot;offset_mapping&quot;</span>]`,wrap:!1}}),vs=new h({props:{code:"JTVCKDAlMkMlMjAwKSUyQyUyMCgwJTJDJTIwMiklMkMlMjAoMyUyQyUyMDcpJTJDJTIwKDglMkMlMjAxMCklMkMlMjAoMTElMkMlMjAxMiklMkMlMjAoMTIlMkMlMjAxNCklMkMlMjAoMTQlMkMlMjAxNiklMkMlMjAoMTYlMkMlMjAxOCklMkMlMjAoMTklMkMlMjAyMiklMkMlMjAoMjMlMkMlMjAyNCklMkMlMjAoMjUlMkMlMjAyOSklMkMlMjAoMzAlMkMlMjAzMiklMkMlMEElMjAoMzMlMkMlMjAzNSklMkMlMjAoMzUlMkMlMjA0MCklMkMlMjAoNDElMkMlMjA0NSklMkMlMjAoNDYlMkMlMjA0OCklMkMlMjAoNDklMkMlMjA1NyklMkMlMjAoNTclMkMlMjA1OCklMkMlMjAoMCUyQyUyMDApJTVE",highlighted:`[(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>), (<span class="hljs-number">0</span>, <span class="hljs-number">2</span>), (<span class="hljs-number">3</span>, <span class="hljs-number">7</span>), (<span class="hljs-number">8</span>, <span class="hljs-number">10</span>), (<span class="hljs-number">11</span>, <span class="hljs-number">12</span>), (<span class="hljs-number">12</span>, <span class="hljs-number">14</span>), (<span class="hljs-number">14</span>, <span class="hljs-number">16</span>), (<span class="hljs-number">16</span>, <span class="hljs-number">18</span>), (<span class="hljs-number">19</span>, <span class="hljs-number">22</span>), (<span class="hljs-number">23</span>, <span class="hljs-number">24</span>), (<span class="hljs-number">25</span>, <span class="hljs-number">29</span>), (<span class="hljs-number">30</span>, <span class="hljs-number">32</span>),
 (<span class="hljs-number">33</span>, <span class="hljs-number">35</span>), (<span class="hljs-number">35</span>, <span class="hljs-number">40</span>), (<span class="hljs-number">41</span>, <span class="hljs-number">45</span>), (<span class="hljs-number">46</span>, <span class="hljs-number">48</span>), (<span class="hljs-number">49</span>, <span class="hljs-number">57</span>), (<span class="hljs-number">57</span>, <span class="hljs-number">58</span>), (<span class="hljs-number">0</span>, <span class="hljs-number">0</span>)]`,wrap:!1}}),Hs=new h({props:{code:"ZXhhbXBsZSU1QjEyJTNBMTQlNUQ=",highlighted:'example[<span class="hljs-number">12</span>:<span class="hljs-number">14</span>]',wrap:!1}}),Xs=new h({props:{code:"eWw=",highlighted:"yl",wrap:!1}}),Ys=new h({props:{code:"cmVzdWx0cyUyMCUzRCUyMCU1QiU1RCUwQWlucHV0c193aXRoX29mZnNldHMlMjAlM0QlMjB0b2tlbml6ZXIoZXhhbXBsZSUyQyUyMHJldHVybl9vZmZzZXRzX21hcHBpbmclM0RUcnVlKSUwQXRva2VucyUyMCUzRCUyMGlucHV0c193aXRoX29mZnNldHMudG9rZW5zKCklMEFvZmZzZXRzJTIwJTNEJTIwaW5wdXRzX3dpdGhfb2Zmc2V0cyU1QiUyMm9mZnNldF9tYXBwaW5nJTIyJTVEJTBBJTBBZm9yJTIwaWR4JTJDJTIwcHJlZCUyMGluJTIwZW51bWVyYXRlKHByZWRpY3Rpb25zKSUzQSUwQSUyMCUyMCUyMCUyMGxhYmVsJTIwJTNEJTIwbW9kZWwuY29uZmlnLmlkMmxhYmVsJTVCcHJlZCU1RCUwQSUyMCUyMCUyMCUyMGlmJTIwbGFiZWwlMjAhJTNEJTIwJTIyTyUyMiUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHN0YXJ0JTJDJTIwZW5kJTIwJTNEJTIwb2Zmc2V0cyU1QmlkeCU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJlc3VsdHMuYXBwZW5kKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmVudGl0eSUyMiUzQSUyMGxhYmVsJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyc2NvcmUlMjIlM0ElMjBwcm9iYWJpbGl0aWVzJTVCaWR4JTVEJTVCcHJlZCU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMndvcmQlMjIlM0ElMjB0b2tlbnMlNUJpZHglNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJzdGFydCUyMiUzQSUyMHN0YXJ0JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZW5kJTIyJTNBJTIwZW5kJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUwQXByaW50KHJlc3VsdHMp",highlighted:`results = []
inputs_with_offsets = tokenizer(example, return_offsets_mapping=<span class="hljs-literal">True</span>)
tokens = inputs_with_offsets.tokens()
offsets = inputs_with_offsets[<span class="hljs-string">&quot;offset_mapping&quot;</span>]

<span class="hljs-keyword">for</span> idx, pred <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(predictions):
    label = model.config.id2label[pred]
    <span class="hljs-keyword">if</span> label != <span class="hljs-string">&quot;O&quot;</span>:
        start, end = offsets[idx]
        results.append(
            {
                <span class="hljs-string">&quot;entity&quot;</span>: label,
                <span class="hljs-string">&quot;score&quot;</span>: probabilities[idx][pred],
                <span class="hljs-string">&quot;word&quot;</span>: tokens[idx],
                <span class="hljs-string">&quot;start&quot;</span>: start,
                <span class="hljs-string">&quot;end&quot;</span>: end,
            }
        )

<span class="hljs-built_in">print</span>(results)`,wrap:!1}}),Ls=new h({props:{code:"JTVCJTdCJ2VudGl0eSclM0ElMjAnSS1QRVInJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTk5MzgyOCUyQyUyMCdpbmRleCclM0ElMjA0JTJDJTIwJ3dvcm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QnJTNBJTIwMzUlMkMlMjAnZW5kJyUzQSUyMDQwJTdEJTJDJTBBJTIwJTdCJ2VudGl0eSclM0ElMjAnSS1PUkcnJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTg4Nzk3NjYlMkMlMjAnaW5kZXgnJTNBJTIwMTQlMkMlMjAnd29yZCclM0ElMjAnRmFjZSclMkMlMjAnc3RhcnQnJTNBJTIwNDElMkMlMjAnZW5kJyUzQSUyMDQ1JTdEJTJDJTBBJTIwJTdCJ2VudGl0eSclM0ElMjAnSS1MT0MnJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTkzMjEwNTUlMkMlMjAnaW5kZXgnJTNBJTIwMTYlMkMlMjAnd29yZCclM0ElMjAnQnJvb2tseW4nJTJDJTIwJ3N0YXJ0JyUzQSUyMDQ5JTJDJTIwJ2VuZCclM0ElMjA1NyU3RCU1RA==",highlighted:`[{<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9993828</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">4</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;S&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">11</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">12</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99815476</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">5</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##yl&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">12</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">14</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99590725</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">6</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##va&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">14</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">16</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9992327</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">7</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##in&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">16</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">18</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97389334</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">12</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Hu&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">33</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">35</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.976115</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">13</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;##gging&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">35</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">40</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.98879766</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">14</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Face&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">41</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">45</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-LOC&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99321055</span>, <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">16</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Brooklyn&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">49</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">57</span>}]`,wrap:!1}}),Os=new Tl({props:{title:"实体分组",local:"实体分组",headingTag:"h3"}}),Ks=new h({props:{code:"ZXhhbXBsZSU1QjMzJTNBNDUlNUQ=",highlighted:'example[<span class="hljs-number">33</span>:<span class="hljs-number">45</span>]',wrap:!1}}),sl=new h({props:{code:"SHVnZ2luZyUyMEZhY2U=",highlighted:"Hugging Face",wrap:!1}}),nl=new h({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBcmVzdWx0cyUyMCUzRCUyMCU1QiU1RCUwQWlucHV0c193aXRoX29mZnNldHMlMjAlM0QlMjB0b2tlbml6ZXIoZXhhbXBsZSUyQyUyMHJldHVybl9vZmZzZXRzX21hcHBpbmclM0RUcnVlKSUwQXRva2VucyUyMCUzRCUyMGlucHV0c193aXRoX29mZnNldHMudG9rZW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CUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmVudGl0eV9ncm91cCUyMiUzQSUyMGxhYmVsJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyc2NvcmUlMjIlM0ElMjBzY29yZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMndvcmQlMjIlM0ElMjB3b3JkJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyc3RhcnQlMjIlM0ElMjBzdGFydCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmVuZCUyMiUzQSUyMGVuZCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjBpZHglMjAlMkIlM0QlMjAxJTBBJTBBcHJpbnQocmVzdWx0cyk=",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

results = []
inputs_with_offsets = tokenizer(example, return_offsets_mapping=<span class="hljs-literal">True</span>)
tokens = inputs_with_offsets.tokens()
offsets = inputs_with_offsets[<span class="hljs-string">&quot;offset_mapping&quot;</span>]

idx = <span class="hljs-number">0</span>
<span class="hljs-keyword">while</span> idx &lt; <span class="hljs-built_in">len</span>(predictions):
    pred = predictions[idx]
    label = model.config.id2label[pred]
    <span class="hljs-keyword">if</span> label != <span class="hljs-string">&quot;O&quot;</span>:
        <span class="hljs-comment"># 删除 B- 或者 I-</span>
        label = label[<span class="hljs-number">2</span>:]
        start, _ = offsets[idx]

        <span class="hljs-comment"># 获取所有标有 I 标签的token</span>
        all_scores = []
        <span class="hljs-keyword">while</span> (
            idx &lt; <span class="hljs-built_in">len</span>(predictions)
            <span class="hljs-keyword">and</span> model.config.id2label[predictions[idx]] == <span class="hljs-string">f&quot;I-<span class="hljs-subst">{label}</span>&quot;</span>
        ):
            all_scores.append(probabilities[idx][pred])
            _, end = offsets[idx]
            idx += <span class="hljs-number">1</span>

        <span class="hljs-comment"># 分数是该分组实体中所有token分数的平均值</span>
        score = np.mean(all_scores).item()
        word = example[start:end]
        results.append(
            {
                <span class="hljs-string">&quot;entity_group&quot;</span>: label,
                <span class="hljs-string">&quot;score&quot;</span>: score,
                <span class="hljs-string">&quot;word&quot;</span>: word,
                <span class="hljs-string">&quot;start&quot;</span>: start,
                <span class="hljs-string">&quot;end&quot;</span>: end,
            }
        )
    idx += <span class="hljs-number">1</span>

<span class="hljs-built_in">print</span>(results)`,wrap:!1}}),al=new h({props:{code:"JTVCJTdCJ2VudGl0eV9ncm91cCclM0ElMjAnUEVSJyUyQyUyMCdzY29yZSclM0ElMjAwLjk5ODE2OTQlMkMlMjAnd29yZCclM0ElMjAnU3lsdmFpbiclMkMlMjAnc3RhcnQnJTNBJTIwMTElMkMlMjAnZW5kJyUzQSUyMDE4JTdEJTJDJTBBJTIwJTdCJ2VudGl0eV9ncm91cCclM0ElMjAnT1JHJyUyQyUyMCdzY29yZSclM0ElMjAwLjk3OTYwMjA0JTJDJTIwJ3dvcmQnJTNBJTIwJ0h1Z2dpbmclMjBGYWNlJyUyQyUyMCdzdGFydCclM0ElMjAzMyUyQyUyMCdlbmQnJTNBJTIwNDUlN0QlMkMlMEElMjAlN0InZW50aXR5X2dyb3VwJyUzQSUyMCdMT0MnJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTkzMjEwNTUlMkMlMjAnd29yZCclM0ElMjAnQnJvb2tseW4nJTJDJTIwJ3N0YXJ0JyUzQSUyMDQ5JTJDJTIwJ2VuZCclM0ElMjA1NyU3RCU1RA==",highlighted:`[{<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9981694</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Sylvain&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">11</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">18</span>},
 {<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.97960204</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Hugging Face&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">33</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">45</span>},
 {<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;LOC&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.99321055</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Brooklyn&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">49</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">57</span>}]`,wrap:!1}}),pl=new la({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter6/3.mdx"}}),{c(){a=o("meta"),U=t(),M=o("p"),u=t(),J(k.$$.fragment),w=t(),J(I.$$.fragment),Q=t(),f.c(),C=t(),$=o("p"),$.innerHTML=c,g=t(),J(v.$$.fragment),ol=t(),V=o("p"),V.innerHTML=Pn,ml=t(),H=o("p"),H.innerHTML=Kn,ul=t(),J(S.$$.fragment),dl=t(),J(D.$$.fragment),hl=t(),J(X.$$.fragment),wl=t(),G=o("p"),G.innerHTML=se,xl=t(),Y=o("p"),Y.innerHTML=le,bl=t(),L=o("p"),L.textContent=ne,gl=t(),J(F.$$.fragment),Cl=t(),O=o("p"),O.innerHTML=ee,kl=t(),J(q.$$.fragment),fl=t(),P=o("p"),P.innerHTML=ae,Il=t(),J(K.$$.fragment),$l=t(),J(ss.$$.fragment),Ql=t(),ls=o("p"),ls.innerHTML=te,Al=t(),J(ns.$$.fragment),zl=t(),J(es.$$.fragment),Zl=t(),as=o("p"),as.textContent=pe,Bl=t(),J(ts.$$.fragment),El=t(),J(ps.$$.fragment),Nl=t(),Ms=o("p"),Ms.innerHTML=Me,Sl=t(),J(cs.$$.fragment),Rl=t(),J(rs.$$.fragment),_l=t(),is=o("p"),is.innerHTML=ce,Wl=t(),J(R.$$.fragment),vl=t(),Js=o("p"),Js.innerHTML=re,Vl=t(),ys=o("p"),ys.innerHTML=ie,Hl=t(),J(js.$$.fragment),Dl=t(),J(Ts.$$.fragment),Xl=t(),Us=o("p"),Us.innerHTML=Je,Gl=t(),J(_.$$.fragment),Yl=t(),J(os.$$.fragment),Ll=t(),ms=o("p"),ms.innerHTML=ye,Fl=t(),z.c(),Jl=t(),J(us.$$.fragment),Ol=t(),ds=o("p"),ds.innerHTML=je,ql=t(),J(hs.$$.fragment),Pl=t(),J(ws.$$.fragment),Kl=t(),xs=o("p"),xs.textContent=Te,sn=t(),J(bs.$$.fragment),ln=t(),J(gs.$$.fragment),nn=t(),Cs=o("p"),Cs.innerHTML=Ue,en=t(),ks=o("ul"),ks.innerHTML=oe,an=t(),fs=o("p"),fs.innerHTML=me,tn=t(),J(Is.$$.fragment),pn=t(),B.c(),yl=t(),$s=o("p"),$s.textContent=ue,Mn=t(),N.c(),jl=t(),J(Qs.$$.fragment),cn=t(),As=o("p"),As.innerHTML=de,rn=t(),J(zs.$$.fragment),Jn=t(),J(Zs.$$.fragment),yn=t(),Bs=o("p"),Bs.innerHTML=he,jn=t(),Es=o("p"),Es.innerHTML=we,Tn=t(),W=o("div"),W.innerHTML=xe,Un=t(),Ns=o("p"),Ns.textContent=be,on=t(),J(Ss.$$.fragment),mn=t(),J(Rs.$$.fragment),un=t(),_s=o("p"),_s.innerHTML=ge,dn=t(),J(Ws.$$.fragment),hn=t(),J(vs.$$.fragment),wn=t(),Vs=o("p"),Vs.innerHTML=Ce,xn=t(),J(Hs.$$.fragment),bn=t(),Ds=o("p"),Ds.innerHTML=ke,gn=t(),J(Xs.$$.fragment),Cn=t(),Gs=o("p"),Gs.textContent=fe,kn=t(),J(Ys.$$.fragment),fn=t(),J(Ls.$$.fragment),In=t(),Fs=o("p"),Fs.textContent=Ie,$n=t(),J(Os.$$.fragment),Qn=t(),qs=o("p"),qs.innerHTML=$e,An=t(),Ps=o("p"),Ps.innerHTML=Qe,zn=t(),J(Ks.$$.fragment),Zn=t(),J(sl.$$.fragment),Bn=t(),ll=o("p"),ll.innerHTML=Ae,En=t(),J(nl.$$.fragment),Nn=t(),el=o("p"),el.textContent=ze,Sn=t(),J(al.$$.fragment),Rn=t(),tl=o("p"),tl.textContent=Ze,_n=t(),J(pl.$$.fragment),Wn=t(),Ul=o("p"),this.h()},l(s){const l=Pe("svelte-u9bgzb",document.head);a=m(l,"META",{name:!0,content:!0}),l.forEach(n),U=p(s),M=m(s,"P",{}),Ge(M).forEach(n),u=p(s),y(k.$$.fragment,s),w=p(s),y(I.$$.fragment,s),Q=p(s),f.l(s),C=p(s),$=m(s,"P",{"data-svelte-h":!0}),d($)!=="svelte-xlurto"&&($.innerHTML=c),g=p(s),y(v.$$.fragment,s),ol=p(s),V=m(s,"P",{"data-svelte-h":!0}),d(V)!=="svelte-1fd33h4"&&(V.innerHTML=Pn),ml=p(s),H=m(s,"P",{"data-svelte-h":!0}),d(H)!=="svelte-1gb0ngn"&&(H.innerHTML=Kn),ul=p(s),y(S.$$.fragment,s),dl=p(s),y(D.$$.fragment,s),hl=p(s),y(X.$$.fragment,s),wl=p(s),G=m(s,"P",{"data-svelte-h":!0}),d(G)!=="svelte-44kurm"&&(G.innerHTML=se),xl=p(s),Y=m(s,"P",{"data-svelte-h":!0}),d(Y)!=="svelte-51vdoy"&&(Y.innerHTML=le),bl=p(s),L=m(s,"P",{"data-svelte-h":!0}),d(L)!=="svelte-ccdb1w"&&(L.textContent=ne),gl=p(s),y(F.$$.fragment,s),Cl=p(s),O=m(s,"P",{"data-svelte-h":!0}),d(O)!=="svelte-1prswbw"&&(O.innerHTML=ee),kl=p(s),y(q.$$.fragment,s),fl=p(s),P=m(s,"P",{"data-svelte-h":!0}),d(P)!=="svelte-18t8dto"&&(P.innerHTML=ae),Il=p(s),y(K.$$.fragment,s),$l=p(s),y(ss.$$.fragment,s),Ql=p(s),ls=m(s,"P",{"data-svelte-h":!0}),d(ls)!=="svelte-c1vrox"&&(ls.innerHTML=te),Al=p(s),y(ns.$$.fragment,s),zl=p(s),y(es.$$.fragment,s),Zl=p(s),as=m(s,"P",{"data-svelte-h":!0}),d(as)!=="svelte-thi5d6"&&(as.textContent=pe),Bl=p(s),y(ts.$$.fragment,s),El=p(s),y(ps.$$.fragment,s),Nl=p(s),Ms=m(s,"P",{"data-svelte-h":!0}),d(Ms)!=="svelte-fcvc74"&&(Ms.innerHTML=Me),Sl=p(s),y(cs.$$.fragment,s),Rl=p(s),y(rs.$$.fragment,s),_l=p(s),is=m(s,"P",{"data-svelte-h":!0}),d(is)!=="svelte-17cvpeq"&&(is.innerHTML=ce),Wl=p(s),y(R.$$.fragment,s),vl=p(s),Js=m(s,"P",{"data-svelte-h":!0}),d(Js)!=="svelte-2bb0df"&&(Js.innerHTML=re),Vl=p(s),ys=m(s,"P",{"data-svelte-h":!0}),d(ys)!=="svelte-1bnbqo7"&&(ys.innerHTML=ie),Hl=p(s),y(js.$$.fragment,s),Dl=p(s),y(Ts.$$.fragment,s),Xl=p(s),Us=m(s,"P",{"data-svelte-h":!0}),d(Us)!=="svelte-okjk4h"&&(Us.innerHTML=Je),Gl=p(s),y(_.$$.fragment,s),Yl=p(s),y(os.$$.fragment,s),Ll=p(s),ms=m(s,"P",{"data-svelte-h":!0}),d(ms)!=="svelte-1jz2ro2"&&(ms.innerHTML=ye),Fl=p(s),z.l(s),Jl=p(s),y(us.$$.fragment,s),Ol=p(s),ds=m(s,"P",{"data-svelte-h":!0}),d(ds)!=="svelte-akfn1d"&&(ds.innerHTML=je),ql=p(s),y(hs.$$.fragment,s),Pl=p(s),y(ws.$$.fragment,s),Kl=p(s),xs=m(s,"P",{"data-svelte-h":!0}),d(xs)!=="svelte-d9xwtr"&&(xs.textContent=Te),sn=p(s),y(bs.$$.fragment,s),ln=p(s),y(gs.$$.fragment,s),nn=p(s),Cs=m(s,"P",{"data-svelte-h":!0}),d(Cs)!=="svelte-1phzkd6"&&(Cs.innerHTML=Ue),en=p(s),ks=m(s,"UL",{"data-svelte-h":!0}),d(ks)!=="svelte-1oo8p38"&&(ks.innerHTML=oe),an=p(s),fs=m(s,"P",{"data-svelte-h":!0}),d(fs)!=="svelte-h5msfh"&&(fs.innerHTML=me),tn=p(s),y(Is.$$.fragment,s),pn=p(s),B.l(s),yl=p(s),$s=m(s,"P",{"data-svelte-h":!0}),d($s)!=="svelte-k5vjqp"&&($s.textContent=ue),Mn=p(s),N.l(s),jl=p(s),y(Qs.$$.fragment,s),cn=p(s),As=m(s,"P",{"data-svelte-h":!0}),d(As)!=="svelte-1oo6uyf"&&(As.innerHTML=de),rn=p(s),y(zs.$$.fragment,s),Jn=p(s),y(Zs.$$.fragment,s),yn=p(s),Bs=m(s,"P",{"data-svelte-h":!0}),d(Bs)!=="svelte-79ypth"&&(Bs.innerHTML=he),jn=p(s),Es=m(s,"P",{"data-svelte-h":!0}),d(Es)!=="svelte-9e9p0x"&&(Es.innerHTML=we),Tn=p(s),W=m(s,"DIV",{class:!0,"data-svelte-h":!0}),d(W)!=="svelte-qf2tof"&&(W.innerHTML=xe),Un=p(s),Ns=m(s,"P",{"data-svelte-h":!0}),d(Ns)!=="svelte-1iha3tj"&&(Ns.textContent=be),on=p(s),y(Ss.$$.fragment,s),mn=p(s),y(Rs.$$.fragment,s),un=p(s),_s=m(s,"P",{"data-svelte-h":!0}),d(_s)!=="svelte-554pot"&&(_s.innerHTML=ge),dn=p(s),y(Ws.$$.fragment,s),hn=p(s),y(vs.$$.fragment,s),wn=p(s),Vs=m(s,"P",{"data-svelte-h":!0}),d(Vs)!=="svelte-1w5q1k"&&(Vs.innerHTML=Ce),xn=p(s),y(Hs.$$.fragment,s),bn=p(s),Ds=m(s,"P",{"data-svelte-h":!0}),d(Ds)!=="svelte-19d85f2"&&(Ds.innerHTML=ke),gn=p(s),y(Xs.$$.fragment,s),Cn=p(s),Gs=m(s,"P",{"data-svelte-h":!0}),d(Gs)!=="svelte-1rk2cnz"&&(Gs.textContent=fe),kn=p(s),y(Ys.$$.fragment,s),fn=p(s),y(Ls.$$.fragment,s),In=p(s),Fs=m(s,"P",{"data-svelte-h":!0}),d(Fs)!=="svelte-1ucqwed"&&(Fs.textContent=Ie),$n=p(s),y(Os.$$.fragment,s),Qn=p(s),qs=m(s,"P",{"data-svelte-h":!0}),d(qs)!=="svelte-p0d26t"&&(qs.innerHTML=$e),An=p(s),Ps=m(s,"P",{"data-svelte-h":!0}),d(Ps)!=="svelte-14f3be8"&&(Ps.innerHTML=Qe),zn=p(s),y(Ks.$$.fragment,s),Zn=p(s),y(sl.$$.fragment,s),Bn=p(s),ll=m(s,"P",{"data-svelte-h":!0}),d(ll)!=="svelte-11trvo6"&&(ll.innerHTML=Ae),En=p(s),y(nl.$$.fragment,s),Nn=p(s),el=m(s,"P",{"data-svelte-h":!0}),d(el)!=="svelte-1qdaknt"&&(el.textContent=ze),Sn=p(s),y(al.$$.fragment,s),Rn=p(s),tl=m(s,"P",{"data-svelte-h":!0}),d(tl)!=="svelte-1t8oni3"&&(tl.textContent=Ze),_n=p(s),y(pl.$$.fragment,s),Wn=p(s),Ul=m(s,"P",{}),Ge(Ul).forEach(n),this.h()},h(){Fn(a,"name","hf:doc:metadata"),Fn(a,"content",Ta),Fn(W,"class","flex justify-center")},m(s,l){Ke(document.head,a),e(s,U,l),e(s,M,l),e(s,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l),e(s,yn,l),e(s,Bs,l),e(s,jn,l),e(s,Es,l),e(s,Tn,l),e(s,W,l),e(s,Un,l),e(s,Ns,l),e(s,on,l),j(Ss,s,l),e(s,mn,l),j(Rs,s,l),e(s,un,l),e(s,_s,l),e(s,dn,l),j(Ws,s,l),e(s,hn,l),j(vs,s,l),e(s,wn,l),e(s,Vs,l),e(s,xn,l),j(Hs,s,l),e(s,bn,l),e(s,Ds,l),e(s,gn,l),j(Xs,s,l),e(s,Cn,l),e(s,Gs,l),e(s,kn,l),j(Ys,s,l),e(s,fn,l),j(Ls,s,l),e(s,In,l),e(s,Fs,l),e(s,$n,l),j(Os,s,l),e(s,Qn,l),e(s,qs,l),e(s,An,l),e(s,Ps,l),e(s,zn,l),j(Ks,s,l),e(s,Zn,l),j(sl,s,l),e(s,Bn,l),e(s,ll,l),e(s,En,l),j(nl,s,l),e(s,Nn,l),e(s,el,l),e(s,Sn,l),j(al,s,l),e(s,Rn,l),e(s,tl,l),e(s,_n,l),j(pl,s,l),e(s,Wn,l),e(s,Ul,l),vn=!0},p(s,[l]){const Ve={};l&1&&(Ve.fw=s[0]),k.$set(Ve);let Xn=x;x=Ee(s),x!==Xn&&(Hn(),r(Ml[Xn],1,1,()=>{Ml[Xn]=null}),Vn(),f=Ml[x],f||(f=Ml[x]=Be[x](s),f.c()),i(f,1),f.m(C.parentNode,C));const He={};l&2&&(He.$$scope={dirty:l,ctx:s}),S.$set(He);const De={};l&2&&(De.$$scope={dirty:l,ctx:s}),R.$set(De);const Xe={};l&2&&(Xe.$$scope={dirty:l,ctx:s}),_.$set(Xe);let Gn=A;A=Se(s),A!==Gn&&(Hn(),r(cl[Gn],1,1,()=>{cl[Gn]=null}),Vn(),z=cl[A],z||(z=cl[A]=Ne[A](s),z.c()),i(z,1),z.m(Jl.parentNode,Jl));let Yn=Z;Z=_e(s),Z!==Yn&&(Hn(),r(rl[Yn],1,1,()=>{rl[Yn]=null}),Vn(),B=rl[Z],B||(B=rl[Z]=Re[Z](s),B.c()),i(B,1),B.m(yl.parentNode,yl));let Ln=E;E=ve(s),E!==Ln&&(Hn(),r(il[Ln],1,1,()=>{il[Ln]=null}),Vn(),N=il[E],N||(N=il[E]=We[E](s),N.c()),i(N,1),N.m(jl.parentNode,jl))},i(s){vn||(i(k.$$.fragment,s),i(I.$$.fragment,s),i(f),i(v.$$.fragment,s),i(S.$$.fragment,s),i(D.$$.fragment,s),i(X.$$.fragment,s),i(F.$$.fragment,s),i(q.$$.fragment,s),i(K.$$.fragment,s),i(ss.$$.fragment,s),i(ns.$$.fragment,s),i(es.$$.fragment,s),i(ts.$$.fragment,s),i(ps.$$.fragment,s),i(cs.$$.fragment,s),i(rs.$$.fragment,s),i(R.$$.fragment,s),i(js.$$.fragment,s),i(Ts.$$.fragment,s),i(_.$$.fragment,s),i(os.$$.fragment,s),i(z),i(us.$$.fragment,s),i(hs.$$.fragment,s),i(ws.$$.fragment,s),i(bs.$$.fragment,s),i(gs.$$.fragment,s),i(Is.$$.fragment,s),i(B),i(N),i(Qs.$$.fragment,s),i(zs.$$.fragment,s),i(Zs.$$.fragment,s),i(Ss.$$.fragment,s),i(Rs.$$.fragment,s),i(Ws.$$.fragment,s),i(vs.$$.fragment,s),i(Hs.$$.fragment,s),i(Xs.$$.fragment,s),i(Ys.$$.fragment,s),i(Ls.$$.fragment,s),i(Os.$$.fragment,s),i(Ks.$$.fragment,s),i(sl.$$.fragment,s),i(nl.$$.fragment,s),i(al.$$.fragment,s),i(pl.$$.fragment,s),vn=!0)},o(s){r(k.$$.fragment,s),r(I.$$.fragment,s),r(f),r(v.$$.fragment,s),r(S.$$.fragment,s),r(D.$$.fragment,s),r(X.$$.fragment,s),r(F.$$.fragment,s),r(q.$$.fragment,s),r(K.$$.fragment,s),r(ss.$$.fragment,s),r(ns.$$.fragment,s),r(es.$$.fragment,s),r(ts.$$.fragment,s),r(ps.$$.fragment,s),r(cs.$$.fragment,s),r(rs.$$.fragment,s),r(R.$$.fragment,s),r(js.$$.fragment,s),r(Ts.$$.fragment,s),r(_.$$.fragment,s),r(os.$$.fragment,s),r(z),r(us.$$.fragment,s),r(hs.$$.fragment,s),r(ws.$$.fragment,s),r(bs.$$.fragment,s),r(gs.$$.fragment,s),r(Is.$$.fragment,s),r(B),r(N),r(Qs.$$.fragment,s),r(zs.$$.fragment,s),r(Zs.$$.fragment,s),r(Ss.$$.fragment,s),r(Rs.$$.fragment,s),r(Ws.$$.fragment,s),r(vs.$$.fragment,s),r(Hs.$$.fragment,s),r(Xs.$$.fragment,s),r(Ys.$$.fragment,s),r(Ls.$$.fragment,s),r(Os.$$.fragment,s),r(Ks.$$.fragment,s),r(sl.$$.fragment,s),r(nl.$$.fragment,s),r(al.$$.fragment,s),r(pl.$$.fragment,s),vn=!1},d(s){s&&(n(U),n(M),n(u),n(w),n(Q),n(C),n($),n(g),n(ol),n(V),n(ml),n(H),n(ul),n(dl),n(hl),n(wl),n(G),n(xl),n(Y),n(bl),n(L),n(gl),n(Cl),n(O),n(kl),n(fl),n(P),n(Il),n($l),n(Ql),n(ls),n(Al),n(zl),n(Zl),n(as),n(Bl),n(El),n(Nl),n(Ms),n(Sl),n(Rl),n(_l),n(is),n(Wl),n(vl),n(Js),n(Vl),n(ys),n(Hl),n(Dl),n(Xl),n(Us),n(Gl),n(Yl),n(Ll),n(ms),n(Fl),n(Jl),n(Ol),n(ds),n(ql),n(Pl),n(Kl),n(xs),n(sn),n(ln),n(nn),n(Cs),n(en),n(ks),n(an),n(fs),n(tn),n(pn),n(yl),n($s),n(Mn),n(jl),n(cn),n(As),n(rn),n(Jn),n(yn),n(Bs),n(jn),n(Es),n(Tn),n(W),n(Un),n(Ns),n(on),n(mn),n(un),n(_s),n(dn),n(hn),n(wn),n(Vs),n(xn),n(bn),n(Ds),n(gn),n(Cn),n(Gs),n(kn),n(fn),n(In),n(Fs),n($n),n(Qn),n(qs),n(An),n(Ps),n(zn),n(Zn),n(Bn),n(ll),n(En),n(Nn),n(el),n(Sn),n(Rn),n(tl),n(_n),n(Wn),n(Ul)),n(a),T(k,s),T(I,s),Ml[x].d(s),T(v,s),T(S,s),T(D,s),T(X,s),T(F,s),T(q,s),T(K,s),T(ss,s),T(ns,s),T(es,s),T(ts,s),T(ps,s),T(cs,s),T(rs,s),T(R,s),T(js,s),T(Ts,s),T(_,s),T(os,s),cl[A].d(s),T(us,s),T(hs,s),T(ws,s),T(bs,s),T(gs,s),T(Is,s),rl[Z].d(s),il[E].d(s),T(Qs,s),T(zs,s),T(Zs,s),T(Ss,s),T(Rs,s),T(Ws,s),T(vs,s),T(Hs,s),T(Xs,s),T(Ys,s),T(Ls,s),T(Os,s),T(Ks,s),T(sl,s),T(nl,s),T(al,s),T(pl,s)}}}const Ta='{"title":"快速 tokenizer 的特殊能力","local":"快速 tokenizer 的特殊能力","sections":[{"title":"批量编码","local":"批量编码","sections":[],"depth":2},{"title":"token-classification 管道内部流程","local":"token-classification 管道内部流程","sections":[{"title":"使用管道获得基本结果","local":"使用管道获得基本结果","sections":[],"depth":3},{"title":"从输入到预测","local":"从输入到预测","sections":[],"depth":3},{"title":"实体分组","local":"实体分组","sections":[],"depth":3}],"depth":2}],"depth":1}';function Ua(b,a,U){let M="pt";return Fe(()=>{const u=new URLSearchParams(window.location.search);U(0,M=u.get("fw")||"pt")}),[M]}class ga extends Oe{constructor(a){super(),qe(this,a,Ua,ja,Le,{})}}export{ga as component};
