import{s as qs,o as Ls,n as As}from"../chunks/scheduler.37c15a92.js";import{S as Ks,i as Ps,g as b,s as p,r,A as Os,h as w,f as s,c as i,j as vs,u as T,x as f,k as ql,l as Ms,y as le,a as e,v as y,t as c,b as ls,d as o,w as u,p as ts}from"../chunks/index.2bf4358c.js";import{T as Hs}from"../chunks/Tip.363c041f.js";import{Y as te}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4e987730.js";import{C as Ds}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as se}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ll,E as ee}from"../chunks/index.b8688d36.js";function ae(I){let a,J;return a=new Ds({props:{chapter:5,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/chapter5/section6_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter5/section6_tf.ipynb"}]}}),{c(){r(a.$$.fragment)},l(n){T(a.$$.fragment,n)},m(n,j){y(a,n,j),J=!0},i(n){J||(o(a.$$.fragment,n),J=!0)},o(n){c(a.$$.fragment,n),J=!1},d(n){u(a,n)}}}function ne(I){let a,J;return a=new Ds({props:{chapter:5,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/chapter5/section6_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter5/section6_pt.ipynb"}]}}),{c(){r(a.$$.fragment)},l(n){T(a.$$.fragment,n)},m(n,j){y(a,n,j),J=!0},i(n){J||(o(a.$$.fragment,n),J=!0)},o(n){c(a.$$.fragment,n),J=!1},d(n){u(a,n)}}}function Me(I){let a,J='✏️ <strong>试试看！</strong> 看看你是否可以使用 <code>Dataset.map()</code> 展开 <code>issues_dataset</code> 的 <code>comments</code> 列，这有点棘手；你可能会发现 🤗 Datasets 文档的 <a href="https://huggingface.co/docs/datasets/about_map_batch#batch-mapping" rel="nofollow">“批处理映射(Batch mapping)”</a> 对这个任务很有用。';return{c(){a=b("p"),a.innerHTML=J},l(n){a=w(n,"P",{"data-svelte-h":!0}),f(a)!=="svelte-17yt0fw"&&(a.innerHTML=J)},m(n,j){e(n,a,j)},p:As,d(n){n&&s(a)}}}function pe(I){let a,J,n,j="请注意，我们在调用 <code>from_pretrained()</code> 方法的时候添加了 <code>from_pt=True</code> 参数。这是因为 <code>multi-qa-mpnet-base-dot-v1</code> checkpoint 只有 PyTorch 权重，因此设置 <code>from_pt=True</code> 会自动将它们转换为 TensorFlow 格式。如你所见，在🤗 Transformers 中切换框架非常简单！",d;return a=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBURkF1dG9Nb2RlbCUwQSUwQW1vZGVsX2NrcHQlMjAlM0QlMjAlMjJzZW50ZW5jZS10cmFuc2Zvcm1lcnMlMkZtdWx0aS1xYS1tcG5ldC1iYXNlLWRvdC12MSUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NrcHQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbC5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2twdCUyQyUyMGZyb21fcHQlM0RUcnVlKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModel

model_ckpt = <span class="hljs-string">&quot;sentence-transformers/multi-qa-mpnet-base-dot-v1&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
model = TFAutoModel.from_pretrained(model_ckpt, from_pt=<span class="hljs-literal">True</span>)`,wrap:!1}}),{c(){r(a.$$.fragment),J=p(),n=b("p"),n.innerHTML=j},l(m){T(a.$$.fragment,m),J=i(m),n=w(m,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1hc0hii"&&(n.innerHTML=j)},m(m,N){y(a,m,N),e(m,J,N),e(m,n,N),d=!0},i(m){d||(o(a.$$.fragment,m),d=!0)},o(m){c(a.$$.fragment,m),d=!1},d(m){m&&(s(J),s(n)),u(a,m)}}}function ie(I){let a,J,n,j="将模型和输入的文本放到 GPU 上会加速嵌入过程，所以让我们现在就这么做：",d,m,N;return a=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWwlMEElMEFtb2RlbF9ja3B0JTIwJTNEJTIwJTIyc2VudGVuY2UtdHJhbnNmb3JtZXJzJTJGbXVsdGktcWEtbXBuZXQtYmFzZS1kb3QtdjElMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9ja3B0KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsLmZyb21fcHJldHJhaW5lZChtb2RlbF9ja3B0KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModel

model_ckpt = <span class="hljs-string">&quot;sentence-transformers/multi-qa-mpnet-base-dot-v1&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
model = AutoModel.from_pretrained(model_ckpt)`,wrap:!1}}),m=new h({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFkZXZpY2UlMjAlM0QlMjB0b3JjaC5kZXZpY2UoJTIyY3VkYSUyMiklMEFtb2RlbC50byhkZXZpY2Up",highlighted:`<span class="hljs-keyword">import</span> torch

device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>)
model.to(device)`,wrap:!1}}),{c(){r(a.$$.fragment),J=p(),n=b("p"),n.textContent=j,d=p(),r(m.$$.fragment)},l(U){T(a.$$.fragment,U),J=i(U),n=w(U,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1qindrm"&&(n.textContent=j),d=i(U),T(m.$$.fragment,U)},m(U,g){y(a,U,g),e(U,J,g),e(U,n,g),e(U,d,g),y(m,U,g),N=!0},i(U){N||(o(a.$$.fragment,U),o(m.$$.fragment,U),N=!0)},o(U){c(a.$$.fragment,U),c(m.$$.fragment,U),N=!1},d(U){U&&(s(J),s(n),s(d)),u(a,U),u(m,U)}}}function de(I){let a,J,n,j="我们可以将第一个文本条目喂给它并检查输出的形状来测试这个函数是否正常工作：",d,m,N,U,g,G,k="太好了，我们已经将语料库中的第一个条目转换为了一个 768 维向量！我们可以用 <code>Dataset.map()</code> 将我们的 <code>get_embeddings()</code> 函数应用到我们语料库中的每一行，然后创建一个新的 <code>embeddings</code> 列：",Q,C,$;return a=new h({props:{code:"ZGVmJTIwZ2V0X2VtYmVkZGluZ3ModGV4dF9saXN0KSUzQSUwQSUyMCUyMCUyMCUyMGVuY29kZWRfaW5wdXQlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdGV4dF9saXN0JTJDJTIwcGFkZGluZyUzRFRydWUlMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIlMEElMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwZW5jb2RlZF9pbnB1dCUyMCUzRCUyMCU3QmslM0ElMjB2JTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMGVuY29kZWRfaW5wdXQuaXRlbXMoKSU3RCUwQSUyMCUyMCUyMCUyMG1vZGVsX291dHB1dCUyMCUzRCUyMG1vZGVsKCoqZW5jb2RlZF9pbnB1dCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBjbHNfcG9vbGluZyhtb2RlbF9vdXRwdXQp",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_embeddings</span>(<span class="hljs-params">text_list</span>):
    encoded_input = tokenizer(
        text_list, padding=<span class="hljs-literal">True</span>, truncation=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>
    )
    encoded_input = {k: v <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> encoded_input.items()}
    model_output = model(**encoded_input)
    <span class="hljs-keyword">return</span> cls_pooling(model_output)`,wrap:!1}}),m=new h({props:{code:"ZW1iZWRkaW5nJTIwJTNEJTIwZ2V0X2VtYmVkZGluZ3MoY29tbWVudHNfZGF0YXNldCU1QiUyMnRleHQlMjIlNUQlNUIwJTVEKSUwQWVtYmVkZGluZy5zaGFwZQ==",highlighted:`embedding = get_embeddings(comments_dataset[<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>])
embedding.shape`,wrap:!1}}),U=new h({props:{code:"VGVuc29yU2hhcGUoJTVCMSUyQyUyMDc2OCU1RCk=",highlighted:'TensorShape([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),C=new h({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0JTIwJTNEJTIwY29tbWVudHNfZGF0YXNldC5tYXAoJTBBJTIwJTIwJTIwJTIwbGFtYmRhJTIweCUzQSUyMCU3QiUyMmVtYmVkZGluZ3MlMjIlM0ElMjBnZXRfZW1iZWRkaW5ncyh4JTVCJTIydGV4dCUyMiU1RCkubnVtcHkoKSU1QjAlNUQlN0QlMEEp",highlighted:`embeddings_dataset = comments_dataset.<span class="hljs-built_in">map</span>(
    <span class="hljs-keyword">lambda</span> x: {<span class="hljs-string">&quot;embeddings&quot;</span>: get_embeddings(x[<span class="hljs-string">&quot;text&quot;</span>]).numpy()[<span class="hljs-number">0</span>]}
)`,wrap:!1}}),{c(){r(a.$$.fragment),J=p(),n=b("p"),n.textContent=j,d=p(),r(m.$$.fragment),N=p(),r(U.$$.fragment),g=p(),G=b("p"),G.innerHTML=k,Q=p(),r(C.$$.fragment)},l(M){T(a.$$.fragment,M),J=i(M),n=w(M,"P",{"data-svelte-h":!0}),f(n)!=="svelte-11461nd"&&(n.textContent=j),d=i(M),T(m.$$.fragment,M),N=i(M),T(U.$$.fragment,M),g=i(M),G=w(M,"P",{"data-svelte-h":!0}),f(G)!=="svelte-17bz3th"&&(G.innerHTML=k),Q=i(M),T(C.$$.fragment,M)},m(M,Z){y(a,M,Z),e(M,J,Z),e(M,n,Z),e(M,d,Z),y(m,M,Z),e(M,N,Z),y(U,M,Z),e(M,g,Z),e(M,G,Z),e(M,Q,Z),y(C,M,Z),$=!0},i(M){$||(o(a.$$.fragment,M),o(m.$$.fragment,M),o(U.$$.fragment,M),o(C.$$.fragment,M),$=!0)},o(M){c(a.$$.fragment,M),c(m.$$.fragment,M),c(U.$$.fragment,M),c(C.$$.fragment,M),$=!1},d(M){M&&(s(J),s(n),s(d),s(N),s(g),s(G),s(Q)),u(a,M),u(m,M),u(U,M),u(C,M)}}}function ce(I){let a,J,n,j="我们可以将第一条数据喂给它并检查输出的形状来测试这个函数是否正常工作：",d,m,N,U,g,G,k="太好了，我们已经将语料库中的第一个条目转换为了一个 768 维向量！我们可以用 <code>Dataset.map()</code> 将我们的 <code>get_embeddings()</code> 函数应用到我们语料库中的每一行，然后创建一个新的 <code>embeddings</code> 列：",Q,C,$;return a=new h({props:{code:"ZGVmJTIwZ2V0X2VtYmVkZGluZ3ModGV4dF9saXN0KSUzQSUwQSUyMCUyMCUyMCUyMGVuY29kZWRfaW5wdXQlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdGV4dF9saXN0JTJDJTIwcGFkZGluZyUzRFRydWUlMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIlMEElMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwZW5jb2RlZF9pbnB1dCUyMCUzRCUyMCU3QmslM0ElMjB2LnRvKGRldmljZSklMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwZW5jb2RlZF9pbnB1dC5pdGVtcygpJTdEJTBBJTIwJTIwJTIwJTIwbW9kZWxfb3V0cHV0JTIwJTNEJTIwbW9kZWwoKiplbmNvZGVkX2lucHV0KSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMGNsc19wb29saW5nKG1vZGVsX291dHB1dCk=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_embeddings</span>(<span class="hljs-params">text_list</span>):
    encoded_input = tokenizer(
        text_list, padding=<span class="hljs-literal">True</span>, truncation=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>
    )
    encoded_input = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> encoded_input.items()}
    model_output = model(**encoded_input)
    <span class="hljs-keyword">return</span> cls_pooling(model_output)`,wrap:!1}}),m=new h({props:{code:"ZW1iZWRkaW5nJTIwJTNEJTIwZ2V0X2VtYmVkZGluZ3MoY29tbWVudHNfZGF0YXNldCU1QiUyMnRleHQlMjIlNUQlNUIwJTVEKSUwQWVtYmVkZGluZy5zaGFwZQ==",highlighted:`embedding = get_embeddings(comments_dataset[<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>])
embedding.shape`,wrap:!1}}),U=new h({props:{code:"dG9yY2guU2l6ZSglNUIxJTJDJTIwNzY4JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),C=new h({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0JTIwJTNEJTIwY29tbWVudHNfZGF0YXNldC5tYXAoJTBBJTIwJTIwJTIwJTIwbGFtYmRhJTIweCUzQSUyMCU3QiUyMmVtYmVkZGluZ3MlMjIlM0ElMjBnZXRfZW1iZWRkaW5ncyh4JTVCJTIydGV4dCUyMiU1RCkuZGV0YWNoKCkuY3B1KCkubnVtcHkoKSU1QjAlNUQlN0QlMEEp",highlighted:`embeddings_dataset = comments_dataset.<span class="hljs-built_in">map</span>(
    <span class="hljs-keyword">lambda</span> x: {<span class="hljs-string">&quot;embeddings&quot;</span>: get_embeddings(x[<span class="hljs-string">&quot;text&quot;</span>]).detach().cpu().numpy()[<span class="hljs-number">0</span>]}
)`,wrap:!1}}),{c(){r(a.$$.fragment),J=p(),n=b("p"),n.textContent=j,d=p(),r(m.$$.fragment),N=p(),r(U.$$.fragment),g=p(),G=b("p"),G.innerHTML=k,Q=p(),r(C.$$.fragment)},l(M){T(a.$$.fragment,M),J=i(M),n=w(M,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1bda0jo"&&(n.textContent=j),d=i(M),T(m.$$.fragment,M),N=i(M),T(U.$$.fragment,M),g=i(M),G=w(M,"P",{"data-svelte-h":!0}),f(G)!=="svelte-17bz3th"&&(G.innerHTML=k),Q=i(M),T(C.$$.fragment,M)},m(M,Z){y(a,M,Z),e(M,J,Z),e(M,n,Z),e(M,d,Z),y(m,M,Z),e(M,N,Z),y(U,M,Z),e(M,g,Z),e(M,G,Z),e(M,Q,Z),y(C,M,Z),$=!0},i(M){$||(o(a.$$.fragment,M),o(m.$$.fragment,M),o(U.$$.fragment,M),o(C.$$.fragment,M),$=!0)},o(M){c(a.$$.fragment,M),c(m.$$.fragment,M),c(U.$$.fragment,M),c(C.$$.fragment,M),$=!1},d(M){M&&(s(J),s(n),s(d),s(N),s(g),s(G),s(Q)),u(a,M),u(m,M),u(U,M),u(C,M)}}}function oe(I){let a,J,n,j;return a=new h({props:{code:"cXVlc3Rpb24lMjAlM0QlMjAlMjJIb3clMjBjYW4lMjBJJTIwbG9hZCUyMGElMjBkYXRhc2V0JTIwb2ZmbGluZSUzRiUyMiUwQXF1ZXN0aW9uX2VtYmVkZGluZyUyMCUzRCUyMGdldF9lbWJlZGRpbmdzKCU1QnF1ZXN0aW9uJTVEKS5udW1weSgpJTBBcXVlc3Rpb25fZW1iZWRkaW5nLnNoYXBl",highlighted:`question = <span class="hljs-string">&quot;How can I load a dataset offline?&quot;</span>
question_embedding = get_embeddings([question]).numpy()
question_embedding.shape`,wrap:!1}}),n=new h({props:{code:"KDElMkMlMjA3Njgp",highlighted:'(<span class="hljs-number">1</span>, <span class="hljs-number">768</span>)',wrap:!1}}),{c(){r(a.$$.fragment),J=p(),r(n.$$.fragment)},l(d){T(a.$$.fragment,d),J=i(d),T(n.$$.fragment,d)},m(d,m){y(a,d,m),e(d,J,m),y(n,d,m),j=!0},i(d){j||(o(a.$$.fragment,d),o(n.$$.fragment,d),j=!0)},o(d){c(a.$$.fragment,d),c(n.$$.fragment,d),j=!1},d(d){d&&s(J),u(a,d),u(n,d)}}}function Je(I){let a,J,n,j;return a=new h({props:{code:"cXVlc3Rpb24lMjAlM0QlMjAlMjJIb3clMjBjYW4lMjBJJTIwbG9hZCUyMGElMjBkYXRhc2V0JTIwb2ZmbGluZSUzRiUyMiUwQXF1ZXN0aW9uX2VtYmVkZGluZyUyMCUzRCUyMGdldF9lbWJlZGRpbmdzKCU1QnF1ZXN0aW9uJTVEKS5jcHUoKS5kZXRhY2goKS5udW1weSgpJTBBcXVlc3Rpb25fZW1iZWRkaW5nLnNoYXBl",highlighted:`question = <span class="hljs-string">&quot;How can I load a dataset offline?&quot;</span>
question_embedding = get_embeddings([question]).cpu().detach().numpy()
question_embedding.shape`,wrap:!1}}),n=new h({props:{code:"dG9yY2guU2l6ZSglNUIxJTJDJTIwNzY4JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),{c(){r(a.$$.fragment),J=p(),r(n.$$.fragment)},l(d){T(a.$$.fragment,d),J=i(d),T(n.$$.fragment,d)},m(d,m){y(a,d,m),e(d,J,m),y(n,d,m),j=!0},i(d){j||(o(a.$$.fragment,d),o(n.$$.fragment,d),j=!0)},o(d){c(a.$$.fragment,d),c(n.$$.fragment,d),j=!1},d(d){d&&s(J),u(a,d),u(n,d)}}}function me(I){let a,J="✏️  试试看！创建你自己的查询并查看你是否可以在检索到的文档中找到答案。你可能需要在 <code>Dataset.get_nearest_examples()</code> 增加参数 <code>k</code> 以扩大搜索范围。";return{c(){a=b("p"),a.innerHTML=J},l(n){a=w(n,"P",{"data-svelte-h":!0}),f(a)!=="svelte-sglmwj"&&(a.innerHTML=J)},m(n,j){e(n,a,j)},p:As,d(n){n&&s(a)}}}function re(I){let a,J,n,j,d,m,N,U,g,G,k,Q,C='在 <a href="/course/chapter5/5">第5小节</a> ，我们创建了一个 🤗 Datasets 仓库的 GitHub issues 和评论组成的数据集。在本节，我们将使用这些信息构建一个搜索引擎，帮助我们找到关于该库的最相关的 issue 的答案！',$,M,Z,F,Kl,S,ps='正如我们在 <a href="/course/chapter1">第一章</a> ，学习的，基于 Transformer 的语言模型会将文本中的每个 token 转换为嵌入向量。事实证明，我们可以 “池化（pool）” 嵌入向量以创建整个句子、段落或（在某些情况下）文档的向量表示。然后，通过计算每个嵌入之间的点积相似度（或其他一些相似度度量）并返回相似度最大的文档，这些嵌入可用于在语料库中找到相似的文档。',Pl,v,is="在本节中，我们将使用文本嵌入向量来开发语义搜索引擎。与基于将查询中的关键字的传统方法相比，这些搜索引擎具有多种优势。",Ol,E,ds='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter5/semantic-search.svg" alt="Semantic search."/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter5/semantic-search-dark.svg" alt="Semantic search."/>',lt,H,tt,A,cs="首先，我们需要下载我们的 GitHub issues 数据集，所以让我们像往常那样使用 <code>load_dataset()</code> 函数：",st,D,et,q,at,L,os="在此，我们在 <code>load_dataset()</code> 中指定了默认的 <code>train（训练集）</code> 部分，因此它返回一个 <code>Dataset</code> 而不是 <code>DatasetDict</code> 。首要任务是排除掉拉取请求（pull），因为这些请求往往很少用于回答提出的 issue，会为我们的搜索引擎引入干扰。正如我们现在熟悉的那样，我们可以使用 <code>Dataset.filter()</code> 函数来排除数据集中的这些行。与此同时，让我们也筛选掉没有评论的行，因为这些行没有为用户提问提供回答：",nt,K,Mt,P,pt,O,Js="我们可以看到，我们的数据集中有很多列，其中大部分在构建我们的搜索引擎都不会使用。从搜索的角度来看，信息量最大的列是 <code>title</code> ， <code>body</code> ，和 <code>comments</code> ，而 <code>html_url</code> 为我们提供了一个回到原 issue 的链接。让我们使用 <code>Dataset.remove_columns()</code> 删除其余的列：",it,ll,dt,tl,ct,sl,ms='为了创建我们的文本嵌入数据集，我们将用 issue 的标题和正文来扩充每条评论，因为这些字段通常包含有用的上下文信息。因为我们的 <code>comments</code> 列当前是每个 issue 的评论列表，我们需要“重新组合”列，使得每一行都是由一个 <code>(html_url, title, body, comment)</code> 元组组成。在 Pandas 中，我们可以使用 <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.explode.html" rel="nofollow">DataFrame.explode() 函数</a> 完成这个操作 它为类似列表的列中的每个元素创建一个新行，同时复制所有其他列值。让我们首先切换到 Pandas 的 <code>DataFrame</code> 格式：',ot,el,Jt,al,rs="如果我们检查这个 <code>DataFrame</code> 的第一行，我们可以看到这个 issue 有四个相关评论：",mt,nl,rt,Ml,Tt,pl,Ts="我们希望使用 <code>explode()</code> 将这些评论中的每一条都展开成为一行。让我们看看是否可以做到：",yt,il,ut,R,ys='<thead><tr style="text-align: right;"><th></th> <th>html_url</th> <th>title</th> <th>comments</th> <th>body</th></tr></thead> <tbody><tr><th>0</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>the bug code locate in ：\\r\\n    if data_args.task_name is not None...</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr> <tr><th>1</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>Hi @jinec,\\r\\n\\r\\nFrom time to time we get this kind of `ConnectionError` coming from the github.com website: https://raw.githubusercontent.com...</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr> <tr><th>2</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>cannot connect，even by Web browser，please check that  there is some  problems。</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr> <tr><th>3</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>I can access https://raw.githubusercontent.com/huggingface/datasets/1.7.0/datasets/glue/glue.py without problem...</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr></tbody>',Ut,dl,us="非常好，我们可以看到其他三列已经被复制了，并且 <code>comments</code> 列里存放着单独的评论！现在我们已经完成了 Pandas 要完成的部分功能，我们可以通过加载内存中的 <code>DataFrame</code> 快速切换回 <code>Dataset</code> ：",bt,cl,wt,ol,ht,Jl,Us="太好了，我们获取到了几千条的评论！",jt,z,ft,ml,bs="既然我们每行有一个评论，让我们创建一个新的 <code>comments_length</code> 列来存放每条评论的字数：",Zt,rl,gt,Tl,ws="我们可以使用这个新列来过滤掉简短的评论，其中通常包括“cc @lewtun”或“谢谢！”之类与我们的搜索引擎无关的内容。筛选的精确数字没有硬性规定，但大约大于 15 个单词似乎是一个不错的选择：",Gt,yl,Nt,ul,It,Ul,hs="稍微清理了我们的数据集后，让我们使用 issue 标题、描述和评论构建一个新的 <code>text</code> 列。像往常一样，我们可以编写一个简单的函数，并将其传递给 <code>Dataset.map()</code> 来完成这些操作",Ct,bl,Qt,wl,js="我们终于准备好创建一些文本嵌入了！让我们继续。",$t,hl,kt,jl,fs='正如我们在 <a href="/course/chapter2">第二章</a> 学过，我们可以通过使用 <code>AutoModel</code> 类来完成文本嵌入。首先需要做的就是选择一个合适的 checkpoint。幸运的是，有一个名为 <code>sentence-transformers</code> 的库专门用于创建文本嵌入。如库中的 <a href="https://www.sbert.net/examples/applications/semantic-search/README.html#symmetric-vs-asymmetric-semantic-search" rel="nofollow">文档</a> 所述的，我们这次要实现的是非对称语义搜索（asymmetric semantic search），因为我们有一个简短的查询，我们希望在比如 issue 评论等更长的文档中找到其匹配的文本。通过查看 <a href="https://www.sbert.net/docs/pretrained_models.html#model-overview" rel="nofollow">模型概述表</a> 我们可以发现 <code>multi-qa-mpnet-base-dot-v1</code> checkpoint 在语义搜索方面具有最佳性能，因此我们将使用它。我们还将使用这个 checkpoint 加载了对应的 tokenizer ：',Rt,B,_,vl,fl,Zs="根据我们之前的想法，我们希望将我们的 GitHub issue 中的每一条记录转化为一个单一的向量，所以我们需要以某种方式“池化（pool）”或平均每个词的嵌入向量。一种流行的方法是在我们模型的输出上进行 <code>CLS 池化</code> ，我们只需要收集 <code>[CLS]</code> token 的的最后一个隐藏状态。以下函数实现了这个功能：",Bt,Zl,_t,gl,gs="接下来，我们将创建一个辅助函数，它将对一组文档进行 tokenize，然后将张量放在 GPU 上，接着将它们喂给模型，最后对输出进行 CLS 池化：",Xt,X,x,Hl,Gl,Gs="请注意，在上面的代码中我们已经将文本嵌入转换为 NumPy 数组——这是因为当我们尝试使用 FAISS 搜索它们时，🤗 Datasets 需要这种格式，让我们继续吧。",xt,Nl,Vt,Il,Ns='现在我们有了一个文本嵌入数据集，我们需要一些方法来搜索它们。为此，我们将使用🤗 Datasets 中一种特殊的数据结构，称为 FAISS 指数。 <a href="https://faiss.ai/" rel="nofollow">FAISS</a> （Facebook AI Similarity Search 的缩写）是一个库，提供了用于快速搜索和聚类嵌入向量的高效算法。',Wt,Cl,Is="FAISS 背后的基本思想是创建一个特殊的数据结构，称为 <code>index（索引）</code> 它可以找到哪些嵌入与输入嵌入相似。在 🤗 Datasets 中创建一个 FAISS index（索引）很简单——我们使用 <code>Dataset.add_faiss_index()</code> 函数并指定我们要索引的数据集的哪一列：",Et,Ql,zt,$l,Cs="现在，我们可以使用 <code>Dataset.get_nearest_examples()</code> 函数进行最近邻居查找。让我们通过首先嵌入一个 issue 来测试这一点，如下所示：",Yt,V,W,Al,kl,Qs="就像对文档进行嵌入一样，我们现在有一个表示查询的 768 维向量，我们可以将其与整个语料库进行比较以找到最相似的嵌入：",Ft,Rl,St,Bl,$s="<code>Dataset.get_nearest_examples()</code> 函数返回一个元组，包括评分（评价查询和文档之间的相似程度）和对应的样本（这里是 5 个最佳匹配）。让我们把这些收集到一个 <code>pandas.DataFrame</code> ，这样我们就可以轻松地对它们进行排序：",vt,_l,Ht,Xl,ks="现在我们可以遍历前几行来查看我们的查询与评论的匹配程度如何：",At,xl,Dt,Vl,qt,Wl,Rs="不错！我们的输出的第 2 个结果似乎与查询匹配。",Lt,Y,Kt,El,Pt,Dl,Ot;d=new se({props:{fw:I[0]}}),N=new Ll({props:{title:"使用 FAISS 进行语义搜索",local:"使用 FAISS 进行语义搜索",headingTag:"h1"}});const Bs=[ne,ae],zl=[];function _s(l,t){return l[0]==="pt"?0:1}g=_s(I),G=zl[g]=Bs[g](I),M=new te({props:{id:"OATCgQtNX2o"}}),F=new Ll({props:{title:"使用文本嵌入进行语义搜索",local:"使用文本嵌入进行语义搜索",headingTag:"h2"}}),H=new Ll({props:{title:"加载和准备数据集",local:"加载和准备数据集",headingTag:"h2"}}),D=new h({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBaXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIybGV3dHVuJTJGZ2l0aHViLWlzc3VlcyUyMiUyQyUyMHNwbGl0JTNEJTIydHJhaW4lMjIpJTBBJTBBaXNzdWVzX2RhdGFzZXQ=",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

issues_dataset = load_dataset(<span class="hljs-string">&quot;lewtun/github-issues&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)

issues_dataset`,wrap:!1}}),q=new h({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1Qid1cmwnJTJDJTIwJ3JlcG9zaXRvcnlfdXJsJyUyQyUyMCdsYWJlbHNfdXJsJyUyQyUyMCdjb21tZW50c191cmwnJTJDJTIwJ2V2ZW50c191cmwnJTJDJTIwJ2h0bWxfdXJsJyUyQyUyMCdpZCclMkMlMjAnbm9kZV9pZCclMkMlMjAnbnVtYmVyJyUyQyUyMCd0aXRsZSclMkMlMjAndXNlciclMkMlMjAnbGFiZWxzJyUyQyUyMCdzdGF0ZSclMkMlMjAnbG9ja2VkJyUyQyUyMCdhc3NpZ25lZSclMkMlMjAnYXNzaWduZWVzJyUyQyUyMCdtaWxlc3RvbmUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdjcmVhdGVkX2F0JyUyQyUyMCd1cGRhdGVkX2F0JyUyQyUyMCdjbG9zZWRfYXQnJTJDJTIwJ2F1dGhvcl9hc3NvY2lhdGlvbiclMkMlMjAnYWN0aXZlX2xvY2tfcmVhc29uJyUyQyUyMCdwdWxsX3JlcXVlc3QnJTJDJTIwJ2JvZHknJTJDJTIwJ3BlcmZvcm1lZF92aWFfZ2l0aHViX2FwcCclMkMlMjAnaXNfcHVsbF9yZXF1ZXN0JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMjg1NSUwQSU3RCk=",highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;url&#x27;</span>, <span class="hljs-string">&#x27;repository_url&#x27;</span>, <span class="hljs-string">&#x27;labels_url&#x27;</span>, <span class="hljs-string">&#x27;comments_url&#x27;</span>, <span class="hljs-string">&#x27;events_url&#x27;</span>, <span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;node_id&#x27;</span>, <span class="hljs-string">&#x27;number&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;user&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;state&#x27;</span>, <span class="hljs-string">&#x27;locked&#x27;</span>, <span class="hljs-string">&#x27;assignee&#x27;</span>, <span class="hljs-string">&#x27;assignees&#x27;</span>, <span class="hljs-string">&#x27;milestone&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;created_at&#x27;</span>, <span class="hljs-string">&#x27;updated_at&#x27;</span>, <span class="hljs-string">&#x27;closed_at&#x27;</span>, <span class="hljs-string">&#x27;author_association&#x27;</span>, <span class="hljs-string">&#x27;active_lock_reason&#x27;</span>, <span class="hljs-string">&#x27;pull_request&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>, <span class="hljs-string">&#x27;performed_via_github_app&#x27;</span>, <span class="hljs-string">&#x27;is_pull_request&#x27;</span>],
    num_rows: <span class="hljs-number">2855</span>
})`,wrap:!1}}),K=new h({props:{code:"aXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldC5maWx0ZXIoJTBBJTIwJTIwJTIwJTIwbGFtYmRhJTIweCUzQSUyMCh4JTVCJTIyaXNfcHVsbF9yZXF1ZXN0JTIyJTVEJTIwJTNEJTNEJTIwRmFsc2UlMjBhbmQlMjBsZW4oeCU1QiUyMmNvbW1lbnRzJTIyJTVEKSUyMCUzRSUyMDApJTBBKSUwQWlzc3Vlc19kYXRhc2V0",highlighted:`issues_dataset = issues_dataset.<span class="hljs-built_in">filter</span>(
    <span class="hljs-keyword">lambda</span> x: (x[<span class="hljs-string">&quot;is_pull_request&quot;</span>] == <span class="hljs-literal">False</span> <span class="hljs-keyword">and</span> <span class="hljs-built_in">len</span>(x[<span class="hljs-string">&quot;comments&quot;</span>]) &gt; <span class="hljs-number">0</span>)
)
issues_dataset`,wrap:!1}}),P=new h({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1Qid1cmwnJTJDJTIwJ3JlcG9zaXRvcnlfdXJsJyUyQyUyMCdsYWJlbHNfdXJsJyUyQyUyMCdjb21tZW50c191cmwnJTJDJTIwJ2V2ZW50c191cmwnJTJDJTIwJ2h0bWxfdXJsJyUyQyUyMCdpZCclMkMlMjAnbm9kZV9pZCclMkMlMjAnbnVtYmVyJyUyQyUyMCd0aXRsZSclMkMlMjAndXNlciclMkMlMjAnbGFiZWxzJyUyQyUyMCdzdGF0ZSclMkMlMjAnbG9ja2VkJyUyQyUyMCdhc3NpZ25lZSclMkMlMjAnYXNzaWduZWVzJyUyQyUyMCdtaWxlc3RvbmUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdjcmVhdGVkX2F0JyUyQyUyMCd1cGRhdGVkX2F0JyUyQyUyMCdjbG9zZWRfYXQnJTJDJTIwJ2F1dGhvcl9hc3NvY2lhdGlvbiclMkMlMjAnYWN0aXZlX2xvY2tfcmVhc29uJyUyQyUyMCdwdWxsX3JlcXVlc3QnJTJDJTIwJ2JvZHknJTJDJTIwJ3BlcmZvcm1lZF92aWFfZ2l0aHViX2FwcCclMkMlMjAnaXNfcHVsbF9yZXF1ZXN0JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNzcxJTBBJTdEKQ==",highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;url&#x27;</span>, <span class="hljs-string">&#x27;repository_url&#x27;</span>, <span class="hljs-string">&#x27;labels_url&#x27;</span>, <span class="hljs-string">&#x27;comments_url&#x27;</span>, <span class="hljs-string">&#x27;events_url&#x27;</span>, <span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;node_id&#x27;</span>, <span class="hljs-string">&#x27;number&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;user&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;state&#x27;</span>, <span class="hljs-string">&#x27;locked&#x27;</span>, <span class="hljs-string">&#x27;assignee&#x27;</span>, <span class="hljs-string">&#x27;assignees&#x27;</span>, <span class="hljs-string">&#x27;milestone&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;created_at&#x27;</span>, <span class="hljs-string">&#x27;updated_at&#x27;</span>, <span class="hljs-string">&#x27;closed_at&#x27;</span>, <span class="hljs-string">&#x27;author_association&#x27;</span>, <span class="hljs-string">&#x27;active_lock_reason&#x27;</span>, <span class="hljs-string">&#x27;pull_request&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>, <span class="hljs-string">&#x27;performed_via_github_app&#x27;</span>, <span class="hljs-string">&#x27;is_pull_request&#x27;</span>],
    num_rows: <span class="hljs-number">771</span>
})`,wrap:!1}}),ll=new h({props:{code:"Y29sdW1ucyUyMCUzRCUyMGlzc3Vlc19kYXRhc2V0LmNvbHVtbl9uYW1lcyUwQWNvbHVtbnNfdG9fa2VlcCUyMCUzRCUyMCU1QiUyMnRpdGxlJTIyJTJDJTIwJTIyYm9keSUyMiUyQyUyMCUyMmh0bWxfdXJsJTIyJTJDJTIwJTIyY29tbWVudHMlMjIlNUQlMEFjb2x1bW5zX3RvX3JlbW92ZSUyMCUzRCUyMHNldChjb2x1bW5zX3RvX2tlZXApLnN5bW1ldHJpY19kaWZmZXJlbmNlKGNvbHVtbnMpJTBBaXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldC5yZW1vdmVfY29sdW1ucyhjb2x1bW5zX3RvX3JlbW92ZSklMEFpc3N1ZXNfZGF0YXNldA==",highlighted:`columns = issues_dataset.column_names
columns_to_keep = [<span class="hljs-string">&quot;title&quot;</span>, <span class="hljs-string">&quot;body&quot;</span>, <span class="hljs-string">&quot;html_url&quot;</span>, <span class="hljs-string">&quot;comments&quot;</span>]
columns_to_remove = <span class="hljs-built_in">set</span>(columns_to_keep).symmetric_difference(columns)
issues_dataset = issues_dataset.remove_columns(columns_to_remove)
issues_dataset`,wrap:!1}}),tl=new h({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidodG1sX3VybCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdib2R5JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNzcxJTBBJTdEKQ==",highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>],
    num_rows: <span class="hljs-number">771</span>
})`,wrap:!1}}),el=new h({props:{code:"aXNzdWVzX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJwYW5kYXMlMjIpJTBBZGYlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldCU1QiUzQSU1RA==",highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`,wrap:!1}}),nl=new h({props:{code:"ZGYlNUIlMjJjb21tZW50cyUyMiU1RCU1QjAlNUQudG9saXN0KCk=",highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()',wrap:!1}}),Ml=new h({props:{code:"JTVCJ3RoZSUyMGJ1ZyUyMGNvZGUlMjBsb2NhdGUlMjBpbiUyMCUzQSU1Q3IlNUNuJTIwJTIwJTIwJTIwaWYlMjBkYXRhX2FyZ3MudGFza19uYW1lJTIwaXMlMjBub3QlMjBOb25lJTNBJTVDciU1Q24lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBEb3dubG9hZGluZyUyMGFuZCUyMGxvYWRpbmclMjBhJTIwZGF0YXNldCUyMGZyb20lMjB0aGUlMjBodWIuJTVDciU1Q24lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkYXRhc2V0cyUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJnbHVlJTIyJTJDJTIwZGF0YV9hcmdzLnRhc2tfbmFtZSUyQyUyMGNhY2hlX2RpciUzRG1vZGVsX2FyZ3MuY2FjaGVfZGlyKSclMkMlMEElMjAnSGklMjAlNDBqaW5lYyUyQyU1Q3IlNUNuJTVDciU1Q25Gcm9tJTIwdGltZSUyMHRvJTIwdGltZSUyMHdlJTIwZ2V0JTIwdGhpcyUyMGtpbmQlMjBvZiUyMCU2MENvbm5lY3Rpb25FcnJvciU2MCUyMGNvbWluZyUyMGZyb20lMjB0aGUlMjBnaXRodWIuY29tJTIwd2Vic2l0ZSUzQSUyMGh0dHBzJTNBJTJGJTJGcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSU1Q3IlNUNuJTVDciU1Q25Ob3JtYWxseSUyQyUyMGl0JTIwc2hvdWxkJTIwd29yayUyMGlmJTIweW91JTIwd2FpdCUyMGElMjBsaXR0bGUlMjBhbmQlMjB0aGVuJTIwcmV0cnkuJTVDciU1Q24lNUNyJTVDbkNvdWxkJTIweW91JTIwcGxlYXNlJTIwY29uZmlybSUyMGlmJTIwdGhlJTIwcHJvYmxlbSUyMHBlcnNpc3RzJTNGJyUyQyUwQSUyMCdjYW5ub3QlMjBjb25uZWN0JTJDZXZlbiUyMGJ5JTIwV2ViJTIwYnJvd3NlciUyQ3BsZWFzZSUyMGNoZWNrJTIwdGhhdCUyMCUyMHRoZXJlJTIwaXMlMjBzb21lJTIwJTIwcHJvYmxlbXMlRTMlODAlODInJTJDJTBBJTIwJ0klMjBjYW4lMjBhY2Nlc3MlMjBodHRwcyUzQSUyRiUyRnJhdy5naXRodWJ1c2VyY29udGVudC5jb20lMkZodWdnaW5nZmFjZSUyRmRhdGFzZXRzJTJGMS43LjAlMkZkYXRhc2V0cyUyRmdsdWUlMkZnbHVlLnB5JTIwd2l0aG91dCUyMHByb2JsZW0uLi4nJTVE",highlighted:`[<span class="hljs-string">&#x27;the bug code locate in :\\r\\n    if data_args.task_name is not None:\\r\\n        # Downloading and loading a dataset from the hub.\\r\\n        datasets = load_dataset(&quot;glue&quot;, data_args.task_name, cache_dir=model_args.cache_dir)&#x27;</span>,
 <span class="hljs-string">&#x27;Hi @jinec,\\r\\n\\r\\nFrom time to time we get this kind of \`ConnectionError\` coming from the github.com website: https://raw.githubusercontent.com\\r\\n\\r\\nNormally, it should work if you wait a little and then retry.\\r\\n\\r\\nCould you please confirm if the problem persists?&#x27;</span>,
 <span class="hljs-string">&#x27;cannot connect,even by Web browser,please check that  there is some  problems。&#x27;</span>,
 <span class="hljs-string">&#x27;I can access https://raw.githubusercontent.com/huggingface/datasets/1.7.0/datasets/glue/glue.py without problem...&#x27;</span>]`,wrap:!1}}),il=new h({props:{code:"Y29tbWVudHNfZGYlMjAlM0QlMjBkZi5leHBsb2RlKCUyMmNvbW1lbnRzJTIyJTJDJTIwaWdub3JlX2luZGV4JTNEVHJ1ZSklMEFjb21tZW50c19kZi5oZWFkKDQp",highlighted:`comments_df = df.explode(<span class="hljs-string">&quot;comments&quot;</span>, ignore_index=<span class="hljs-literal">True</span>)
comments_df.head(<span class="hljs-number">4</span>)`,wrap:!1}}),cl=new h({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwRGF0YXNldCUwQSUwQWNvbW1lbnRzX2RhdGFzZXQlMjAlM0QlMjBEYXRhc2V0LmZyb21fcGFuZGFzKGNvbW1lbnRzX2RmKSUwQWNvbW1lbnRzX2RhdGFzZXQ=",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> Dataset

comments_dataset = Dataset.from_pandas(comments_df)
comments_dataset`,wrap:!1}}),ol=new h({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidodG1sX3VybCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdib2R5JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMjg0MiUwQSU3RCk=",highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>],
    num_rows: <span class="hljs-number">2842</span>
})`,wrap:!1}}),z=new Hs({props:{$$slots:{default:[Me]},$$scope:{ctx:I}}}),rl=new h({props:{code:"Y29tbWVudHNfZGF0YXNldCUyMCUzRCUyMGNvbW1lbnRzX2RhdGFzZXQubWFwKCUwQSUyMCUyMCUyMCUyMGxhbWJkYSUyMHglM0ElMjAlN0IlMjJjb21tZW50X2xlbmd0aCUyMiUzQSUyMGxlbih4JTVCJTIyY29tbWVudHMlMjIlNUQuc3BsaXQoKSklN0QlMEEp",highlighted:`comments_dataset = comments_dataset.<span class="hljs-built_in">map</span>(
    <span class="hljs-keyword">lambda</span> x: {<span class="hljs-string">&quot;comment_length&quot;</span>: <span class="hljs-built_in">len</span>(x[<span class="hljs-string">&quot;comments&quot;</span>].split())}
)`,wrap:!1}}),yl=new h({props:{code:"Y29tbWVudHNfZGF0YXNldCUyMCUzRCUyMGNvbW1lbnRzX2RhdGFzZXQuZmlsdGVyKGxhbWJkYSUyMHglM0ElMjB4JTVCJTIyY29tbWVudF9sZW5ndGglMjIlNUQlMjAlM0UlMjAxNSklMEFjb21tZW50c19kYXRhc2V0",highlighted:`comments_dataset = comments_dataset.<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> x: x[<span class="hljs-string">&quot;comment_length&quot;</span>] &gt; <span class="hljs-number">15</span>)
comments_dataset`,wrap:!1}}),ul=new h({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidodG1sX3VybCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdib2R5JyUyQyUyMCdjb21tZW50X2xlbmd0aCclNUQlMkMlMEElMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDIwOTglMEElN0Qp",highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>, <span class="hljs-string">&#x27;comment_length&#x27;</span>],
    num_rows: <span class="hljs-number">2098</span>
})`,wrap:!1}}),bl=new h({props:{code:"ZGVmJTIwY29uY2F0ZW5hdGVfdGV4dChleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ0ZXh0JTIyJTNBJTIwZXhhbXBsZXMlNUIlMjJ0aXRsZSUyMiU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyQiUyMCUyMiUyMCU1Q24lMjAlMjIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMkIlMjBleGFtcGxlcyU1QiUyMmJvZHklMjIlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMkIlMjAlMjIlMjAlNUNuJTIwJTIyJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTJCJTIwZXhhbXBsZXMlNUIlMjJjb21tZW50cyUyMiU1RCUwQSUyMCUyMCUyMCUyMCU3RCUwQSUwQSUwQWNvbW1lbnRzX2RhdGFzZXQlMjAlM0QlMjBjb21tZW50c19kYXRhc2V0Lm1hcChjb25jYXRlbmF0ZV90ZXh0KQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">concatenate_text</span>(<span class="hljs-params">examples</span>):
    <span class="hljs-keyword">return</span> {
        <span class="hljs-string">&quot;text&quot;</span>: examples[<span class="hljs-string">&quot;title&quot;</span>]
        + <span class="hljs-string">&quot; \\n &quot;</span>
        + examples[<span class="hljs-string">&quot;body&quot;</span>]
        + <span class="hljs-string">&quot; \\n &quot;</span>
        + examples[<span class="hljs-string">&quot;comments&quot;</span>]
    }


comments_dataset = comments_dataset.<span class="hljs-built_in">map</span>(concatenate_text)`,wrap:!1}}),hl=new Ll({props:{title:"创建文本嵌入",local:"创建文本嵌入",headingTag:"h2"}});const Xs=[ie,pe],Yl=[];function xs(l,t){return l[0]==="pt"?0:1}B=xs(I),_=Yl[B]=Xs[B](I),Zl=new h({props:{code:"ZGVmJTIwY2xzX3Bvb2xpbmcobW9kZWxfb3V0cHV0KSUzQSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMG1vZGVsX291dHB1dC5sYXN0X2hpZGRlbl9zdGF0ZSU1QiUzQSUyQyUyMDAlNUQ=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">cls_pooling</span>(<span class="hljs-params">model_output</span>):
    <span class="hljs-keyword">return</span> model_output.last_hidden_state[:, <span class="hljs-number">0</span>]`,wrap:!1}});const Vs=[ce,de],Fl=[];function Ws(l,t){return l[0]==="pt"?0:1}X=Ws(I),x=Fl[X]=Vs[X](I),Nl=new Ll({props:{title:"使用 FAISS 进行高效的相似性搜索",local:"使用 FAISS 进行高效的相似性搜索",headingTag:"h2"}}),Ql=new h({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0LmFkZF9mYWlzc19pbmRleChjb2x1bW4lM0QlMjJlbWJlZGRpbmdzJTIyKQ==",highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)',wrap:!1}});const Es=[Je,oe],Sl=[];function zs(l,t){return l[0]==="pt"?0:1}return V=zs(I),W=Sl[V]=Es[V](I),Rl=new h({props:{code:"c2NvcmVzJTJDJTIwc2FtcGxlcyUyMCUzRCUyMGVtYmVkZGluZ3NfZGF0YXNldC5nZXRfbmVhcmVzdF9leGFtcGxlcyglMEElMjAlMjAlMjAlMjAlMjJlbWJlZGRpbmdzJTIyJTJDJTIwcXVlc3Rpb25fZW1iZWRkaW5nJTJDJTIwayUzRDUlMEEp",highlighted:`scores, samples = embeddings_dataset.get_nearest_examples(
    <span class="hljs-string">&quot;embeddings&quot;</span>, question_embedding, k=<span class="hljs-number">5</span>
)`,wrap:!1}}),_l=new h({props:{code:"aW1wb3J0JTIwcGFuZGFzJTIwYXMlMjBwZCUwQSUwQXNhbXBsZXNfZGYlMjAlM0QlMjBwZC5EYXRhRnJhbWUuZnJvbV9kaWN0KHNhbXBsZXMpJTBBc2FtcGxlc19kZiU1QiUyMnNjb3JlcyUyMiU1RCUyMCUzRCUyMHNjb3JlcyUwQXNhbXBsZXNfZGYuc29ydF92YWx1ZXMoJTIyc2NvcmVzJTIyJTJDJTIwYXNjZW5kaW5nJTNERmFsc2UlMkMlMjBpbnBsYWNlJTNEVHJ1ZSk=",highlighted:`<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd

samples_df = pd.DataFrame.from_dict(samples)
samples_df[<span class="hljs-string">&quot;scores&quot;</span>] = scores
samples_df.sort_values(<span class="hljs-string">&quot;scores&quot;</span>, ascending=<span class="hljs-literal">False</span>, inplace=<span class="hljs-literal">True</span>)`,wrap:!1}}),xl=new h({props:{code:"Zm9yJTIwXyUyQyUyMHJvdyUyMGluJTIwc2FtcGxlc19kZi5pdGVycm93cygpJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMkNPTU1FTlQlM0ElMjAlN0Jyb3cuY29tbWVudHMlN0QlMjIpJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMlNDT1JFJTNBJTIwJTdCcm93LnNjb3JlcyU3RCUyMiklMEElMjAlMjAlMjAlMjBwcmludChmJTIyVElUTEUlM0ElMjAlN0Jyb3cudGl0bGUlN0QlMjIpJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMlVSTCUzQSUyMCU3QnJvdy5odG1sX3VybCU3RCUyMiklMEElMjAlMjAlMjAlMjBwcmludCglMjIlM0QlMjIlMjAqJTIwNTApJTBBJTIwJTIwJTIwJTIwcHJpbnQoKQ==",highlighted:`<span class="hljs-keyword">for</span> _, row <span class="hljs-keyword">in</span> samples_df.iterrows():
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;COMMENT: <span class="hljs-subst">{row.comments}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;SCORE: <span class="hljs-subst">{row.scores}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;TITLE: <span class="hljs-subst">{row.title}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;URL: <span class="hljs-subst">{row.html_url}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;=&quot;</span> * <span class="hljs-number">50</span>)
    <span class="hljs-built_in">print</span>()`,wrap:!1}}),Vl=new h({props:{code:" ",highlighted:`<span class="hljs-string">&quot;&quot;&quot;
COMMENT: Requiring online connection is a deal breaker in some cases unfortunately so it&#x27;d be great if offline mode is added similar to how \`transformers\` loads models offline fine.

@mandubian&#x27;s second bullet point suggests that there&#x27;s a workaround allowing you to use your offline (custom?) dataset with \`datasets\`. Could you please elaborate on how that should look like?
SCORE: 25.505046844482422
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: The local dataset builders (csv, text , json and pandas) are now part of the \`datasets\` package since #1726 :)
You can now use them offline
\\\`\\\`\\\`python
datasets = load_dataset(&quot;text&quot;, data_files=data_files)
\\\`\\\`\\\`

We&#x27;ll do a new release soon
SCORE: 24.555509567260742
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: I opened a PR that allows to reload modules that have already been loaded once even if there&#x27;s no internet.

Let me know if you know other ways that can make the offline mode experience better. I&#x27;d be happy to add them :)

I already note the &quot;freeze&quot; modules option, to prevent local modules updates. It would be a cool feature.

----------

&gt; @mandubian&#x27;s second bullet point suggests that there&#x27;s a workaround allowing you to use your offline (custom?) dataset with \`datasets\`. Could you please elaborate on how that should look like?

Indeed \`load_dataset\` allows to load remote dataset script (squad, glue, etc.) but also you own local ones.
For example if you have a dataset script at \`./my_dataset/my_dataset.py\` then you can do
\\\`\\\`\\\`python
load_dataset(&quot;./my_dataset&quot;)
\\\`\\\`\\\`
and the dataset script will generate your dataset once and for all.

----------

About I&#x27;m looking into having \`csv\`, \`json\`, \`text\`, \`pandas\` dataset builders already included in the \`datasets\` package, so that they are available offline by default, as opposed to the other datasets that require the script to be downloaded.
cf #1724
SCORE: 24.14896583557129
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: &gt; here is my way to load a dataset offline, but it **requires** an online machine
&gt;
&gt; 1. (online machine)
&gt;
&gt; \`\`\`
&gt;
&gt; import datasets
&gt;
&gt; data = datasets.load_dataset(.)
&gt;
&gt; data.save_to_disk(/YOUR/DATASET/DIR)
&gt;
&gt; \`\`\`
&gt;
&gt; 2. copy the dir from online to the offline machine
&gt;
&gt; 3. (offline machine)
&gt;
&gt; \`\`\`
&gt;
&gt; import datasets
&gt;
&gt; data = datasets.load_from_disk(/SAVED/DATA/DIR)
&gt;
&gt; \`\`\`
&gt;
&gt;
&gt;
&gt; HTH.


SCORE: 22.893993377685547
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: here is my way to load a dataset offline, but it **requires** an online machine
1. (online machine)
\\\`\\\`\\\`
import datasets
data = datasets.load_dataset(...)
data.save_to_disk(/YOUR/DATASET/DIR)
\\\`\\\`\\\`
2. copy the dir from online to the offline machine
3. (offline machine)
\\\`\\\`\\\`
import datasets
data = datasets.load_from_disk(/SAVED/DATA/DIR)
\\\`\\\`\\\`

HTH.
SCORE: 22.406635284423828
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================
&quot;&quot;&quot;</span>`,wrap:!1}}),Y=new Hs({props:{$$slots:{default:[me]},$$scope:{ctx:I}}}),El=new ee({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter5/6.mdx"}}),{c(){a=b("meta"),J=p(),n=b("p"),j=p(),r(d.$$.fragment),m=p(),r(N.$$.fragment),U=p(),G.c(),k=p(),Q=b("p"),Q.innerHTML=C,$=p(),r(M.$$.fragment),Z=p(),r(F.$$.fragment),Kl=p(),S=b("p"),S.innerHTML=ps,Pl=p(),v=b("p"),v.textContent=is,Ol=p(),E=b("div"),E.innerHTML=ds,lt=p(),r(H.$$.fragment),tt=p(),A=b("p"),A.innerHTML=cs,st=p(),r(D.$$.fragment),et=p(),r(q.$$.fragment),at=p(),L=b("p"),L.innerHTML=os,nt=p(),r(K.$$.fragment),Mt=p(),r(P.$$.fragment),pt=p(),O=b("p"),O.innerHTML=Js,it=p(),r(ll.$$.fragment),dt=p(),r(tl.$$.fragment),ct=p(),sl=b("p"),sl.innerHTML=ms,ot=p(),r(el.$$.fragment),Jt=p(),al=b("p"),al.innerHTML=rs,mt=p(),r(nl.$$.fragment),rt=p(),r(Ml.$$.fragment),Tt=p(),pl=b("p"),pl.innerHTML=Ts,yt=p(),r(il.$$.fragment),ut=p(),R=b("table"),R.innerHTML=ys,Ut=p(),dl=b("p"),dl.innerHTML=us,bt=p(),r(cl.$$.fragment),wt=p(),r(ol.$$.fragment),ht=p(),Jl=b("p"),Jl.textContent=Us,jt=p(),r(z.$$.fragment),ft=p(),ml=b("p"),ml.innerHTML=bs,Zt=p(),r(rl.$$.fragment),gt=p(),Tl=b("p"),Tl.textContent=ws,Gt=p(),r(yl.$$.fragment),Nt=p(),r(ul.$$.fragment),It=p(),Ul=b("p"),Ul.innerHTML=hs,Ct=p(),r(bl.$$.fragment),Qt=p(),wl=b("p"),wl.textContent=js,$t=p(),r(hl.$$.fragment),kt=p(),jl=b("p"),jl.innerHTML=fs,Rt=p(),_.c(),vl=p(),fl=b("p"),fl.innerHTML=Zs,Bt=p(),r(Zl.$$.fragment),_t=p(),gl=b("p"),gl.textContent=gs,Xt=p(),x.c(),Hl=p(),Gl=b("p"),Gl.textContent=Gs,xt=p(),r(Nl.$$.fragment),Vt=p(),Il=b("p"),Il.innerHTML=Ns,Wt=p(),Cl=b("p"),Cl.innerHTML=Is,Et=p(),r(Ql.$$.fragment),zt=p(),$l=b("p"),$l.innerHTML=Cs,Yt=p(),W.c(),Al=p(),kl=b("p"),kl.textContent=Qs,Ft=p(),r(Rl.$$.fragment),St=p(),Bl=b("p"),Bl.innerHTML=$s,vt=p(),r(_l.$$.fragment),Ht=p(),Xl=b("p"),Xl.textContent=ks,At=p(),r(xl.$$.fragment),Dt=p(),r(Vl.$$.fragment),qt=p(),Wl=b("p"),Wl.textContent=Rs,Lt=p(),r(Y.$$.fragment),Kt=p(),r(El.$$.fragment),Pt=p(),Dl=b("p"),this.h()},l(l){const t=Os("svelte-u9bgzb",document.head);a=w(t,"META",{name:!0,content:!0}),t.forEach(s),J=i(l),n=w(l,"P",{}),vs(n).forEach(s),j=i(l),T(d.$$.fragment,l),m=i(l),T(N.$$.fragment,l),U=i(l),G.l(l),k=i(l),Q=w(l,"P",{"data-svelte-h":!0}),f(Q)!=="svelte-1k1uitg"&&(Q.innerHTML=C),$=i(l),T(M.$$.fragment,l),Z=i(l),T(F.$$.fragment,l),Kl=i(l),S=w(l,"P",{"data-svelte-h":!0}),f(S)!=="svelte-1bo3r1m"&&(S.innerHTML=ps),Pl=i(l),v=w(l,"P",{"data-svelte-h":!0}),f(v)!=="svelte-17w33xe"&&(v.textContent=is),Ol=i(l),E=w(l,"DIV",{class:!0,"data-svelte-h":!0}),f(E)!=="svelte-yxatr"&&(E.innerHTML=ds),lt=i(l),T(H.$$.fragment,l),tt=i(l),A=w(l,"P",{"data-svelte-h":!0}),f(A)!=="svelte-1j4s9k3"&&(A.innerHTML=cs),st=i(l),T(D.$$.fragment,l),et=i(l),T(q.$$.fragment,l),at=i(l),L=w(l,"P",{"data-svelte-h":!0}),f(L)!=="svelte-2cqt6s"&&(L.innerHTML=os),nt=i(l),T(K.$$.fragment,l),Mt=i(l),T(P.$$.fragment,l),pt=i(l),O=w(l,"P",{"data-svelte-h":!0}),f(O)!=="svelte-15hujmg"&&(O.innerHTML=Js),it=i(l),T(ll.$$.fragment,l),dt=i(l),T(tl.$$.fragment,l),ct=i(l),sl=w(l,"P",{"data-svelte-h":!0}),f(sl)!=="svelte-13qbpuw"&&(sl.innerHTML=ms),ot=i(l),T(el.$$.fragment,l),Jt=i(l),al=w(l,"P",{"data-svelte-h":!0}),f(al)!=="svelte-1y6s0lg"&&(al.innerHTML=rs),mt=i(l),T(nl.$$.fragment,l),rt=i(l),T(Ml.$$.fragment,l),Tt=i(l),pl=w(l,"P",{"data-svelte-h":!0}),f(pl)!=="svelte-62usvk"&&(pl.innerHTML=Ts),yt=i(l),T(il.$$.fragment,l),ut=i(l),R=w(l,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),f(R)!=="svelte-1g5whzd"&&(R.innerHTML=ys),Ut=i(l),dl=w(l,"P",{"data-svelte-h":!0}),f(dl)!=="svelte-axvn69"&&(dl.innerHTML=us),bt=i(l),T(cl.$$.fragment,l),wt=i(l),T(ol.$$.fragment,l),ht=i(l),Jl=w(l,"P",{"data-svelte-h":!0}),f(Jl)!=="svelte-x6393a"&&(Jl.textContent=Us),jt=i(l),T(z.$$.fragment,l),ft=i(l),ml=w(l,"P",{"data-svelte-h":!0}),f(ml)!=="svelte-vg61zh"&&(ml.innerHTML=bs),Zt=i(l),T(rl.$$.fragment,l),gt=i(l),Tl=w(l,"P",{"data-svelte-h":!0}),f(Tl)!=="svelte-1v6qqei"&&(Tl.textContent=ws),Gt=i(l),T(yl.$$.fragment,l),Nt=i(l),T(ul.$$.fragment,l),It=i(l),Ul=w(l,"P",{"data-svelte-h":!0}),f(Ul)!=="svelte-s6nife"&&(Ul.innerHTML=hs),Ct=i(l),T(bl.$$.fragment,l),Qt=i(l),wl=w(l,"P",{"data-svelte-h":!0}),f(wl)!=="svelte-lpyv6q"&&(wl.textContent=js),$t=i(l),T(hl.$$.fragment,l),kt=i(l),jl=w(l,"P",{"data-svelte-h":!0}),f(jl)!=="svelte-1ou84a4"&&(jl.innerHTML=fs),Rt=i(l),_.l(l),vl=i(l),fl=w(l,"P",{"data-svelte-h":!0}),f(fl)!=="svelte-1o32zfz"&&(fl.innerHTML=Zs),Bt=i(l),T(Zl.$$.fragment,l),_t=i(l),gl=w(l,"P",{"data-svelte-h":!0}),f(gl)!=="svelte-d2x713"&&(gl.textContent=gs),Xt=i(l),x.l(l),Hl=i(l),Gl=w(l,"P",{"data-svelte-h":!0}),f(Gl)!=="svelte-6mj4g9"&&(Gl.textContent=Gs),xt=i(l),T(Nl.$$.fragment,l),Vt=i(l),Il=w(l,"P",{"data-svelte-h":!0}),f(Il)!=="svelte-cma3ou"&&(Il.innerHTML=Ns),Wt=i(l),Cl=w(l,"P",{"data-svelte-h":!0}),f(Cl)!=="svelte-1wc0p1"&&(Cl.innerHTML=Is),Et=i(l),T(Ql.$$.fragment,l),zt=i(l),$l=w(l,"P",{"data-svelte-h":!0}),f($l)!=="svelte-xjel5k"&&($l.innerHTML=Cs),Yt=i(l),W.l(l),Al=i(l),kl=w(l,"P",{"data-svelte-h":!0}),f(kl)!=="svelte-iayzgi"&&(kl.textContent=Qs),Ft=i(l),T(Rl.$$.fragment,l),St=i(l),Bl=w(l,"P",{"data-svelte-h":!0}),f(Bl)!=="svelte-11tm5f0"&&(Bl.innerHTML=$s),vt=i(l),T(_l.$$.fragment,l),Ht=i(l),Xl=w(l,"P",{"data-svelte-h":!0}),f(Xl)!=="svelte-1v4c8w0"&&(Xl.textContent=ks),At=i(l),T(xl.$$.fragment,l),Dt=i(l),T(Vl.$$.fragment,l),qt=i(l),Wl=w(l,"P",{"data-svelte-h":!0}),f(Wl)!=="svelte-1l7ida9"&&(Wl.textContent=Rs),Lt=i(l),T(Y.$$.fragment,l),Kt=i(l),T(El.$$.fragment,l),Pt=i(l),Dl=w(l,"P",{}),vs(Dl).forEach(s),this.h()},h(){ql(a,"name","hf:doc:metadata"),ql(a,"content",Te),ql(E,"class","flex justify-center"),ql(R,"border","1"),ql(R,"class","dataframe"),Ms(R,"table-layout","fixed"),Ms(R,"word-wrap","break-word"),Ms(R,"width","100%")},m(l,t){le(document.head,a),e(l,J,t),e(l,n,t),e(l,j,t),y(d,l,t),e(l,m,t),y(N,l,t),e(l,U,t),zl[g].m(l,t),e(l,k,t),e(l,Q,t),e(l,$,t),y(M,l,t),e(l,Z,t),y(F,l,t),e(l,Kl,t),e(l,S,t),e(l,Pl,t),e(l,v,t),e(l,Ol,t),e(l,E,t),e(l,lt,t),y(H,l,t),e(l,tt,t),e(l,A,t),e(l,st,t),y(D,l,t),e(l,et,t),y(q,l,t),e(l,at,t),e(l,L,t),e(l,nt,t),y(K,l,t),e(l,Mt,t),y(P,l,t),e(l,pt,t),e(l,O,t),e(l,it,t),y(ll,l,t),e(l,dt,t),y(tl,l,t),e(l,ct,t),e(l,sl,t),e(l,ot,t),y(el,l,t),e(l,Jt,t),e(l,al,t),e(l,mt,t),y(nl,l,t),e(l,rt,t),y(Ml,l,t),e(l,Tt,t),e(l,pl,t),e(l,yt,t),y(il,l,t),e(l,ut,t),e(l,R,t),e(l,Ut,t),e(l,dl,t),e(l,bt,t),y(cl,l,t),e(l,wt,t),y(ol,l,t),e(l,ht,t),e(l,Jl,t),e(l,jt,t),y(z,l,t),e(l,ft,t),e(l,ml,t),e(l,Zt,t),y(rl,l,t),e(l,gt,t),e(l,Tl,t),e(l,Gt,t),y(yl,l,t),e(l,Nt,t),y(ul,l,t),e(l,It,t),e(l,Ul,t),e(l,Ct,t),y(bl,l,t),e(l,Qt,t),e(l,wl,t),e(l,$t,t),y(hl,l,t),e(l,kt,t),e(l,jl,t),e(l,Rt,t),Yl[B].m(l,t),e(l,vl,t),e(l,fl,t),e(l,Bt,t),y(Zl,l,t),e(l,_t,t),e(l,gl,t),e(l,Xt,t),Fl[X].m(l,t),e(l,Hl,t),e(l,Gl,t),e(l,xt,t),y(Nl,l,t),e(l,Vt,t),e(l,Il,t),e(l,Wt,t),e(l,Cl,t),e(l,Et,t),y(Ql,l,t),e(l,zt,t),e(l,$l,t),e(l,Yt,t),Sl[V].m(l,t),e(l,Al,t),e(l,kl,t),e(l,Ft,t),y(Rl,l,t),e(l,St,t),e(l,Bl,t),e(l,vt,t),y(_l,l,t),e(l,Ht,t),e(l,Xl,t),e(l,At,t),y(xl,l,t),e(l,Dt,t),y(Vl,l,t),e(l,qt,t),e(l,Wl,t),e(l,Lt,t),y(Y,l,t),e(l,Kt,t),y(El,l,t),e(l,Pt,t),e(l,Dl,t),Ot=!0},p(l,[t]){const Ys={};t&1&&(Ys.fw=l[0]),d.$set(Ys);let ss=g;g=_s(l),g!==ss&&(ts(),c(zl[ss],1,1,()=>{zl[ss]=null}),ls(),G=zl[g],G||(G=zl[g]=Bs[g](l),G.c()),o(G,1),G.m(k.parentNode,k));const Fs={};t&2&&(Fs.$$scope={dirty:t,ctx:l}),z.$set(Fs);let es=B;B=xs(l),B!==es&&(ts(),c(Yl[es],1,1,()=>{Yl[es]=null}),ls(),_=Yl[B],_||(_=Yl[B]=Xs[B](l),_.c()),o(_,1),_.m(vl.parentNode,vl));let as=X;X=Ws(l),X!==as&&(ts(),c(Fl[as],1,1,()=>{Fl[as]=null}),ls(),x=Fl[X],x||(x=Fl[X]=Vs[X](l),x.c()),o(x,1),x.m(Hl.parentNode,Hl));let ns=V;V=zs(l),V!==ns&&(ts(),c(Sl[ns],1,1,()=>{Sl[ns]=null}),ls(),W=Sl[V],W||(W=Sl[V]=Es[V](l),W.c()),o(W,1),W.m(Al.parentNode,Al));const Ss={};t&2&&(Ss.$$scope={dirty:t,ctx:l}),Y.$set(Ss)},i(l){Ot||(o(d.$$.fragment,l),o(N.$$.fragment,l),o(G),o(M.$$.fragment,l),o(F.$$.fragment,l),o(H.$$.fragment,l),o(D.$$.fragment,l),o(q.$$.fragment,l),o(K.$$.fragment,l),o(P.$$.fragment,l),o(ll.$$.fragment,l),o(tl.$$.fragment,l),o(el.$$.fragment,l),o(nl.$$.fragment,l),o(Ml.$$.fragment,l),o(il.$$.fragment,l),o(cl.$$.fragment,l),o(ol.$$.fragment,l),o(z.$$.fragment,l),o(rl.$$.fragment,l),o(yl.$$.fragment,l),o(ul.$$.fragment,l),o(bl.$$.fragment,l),o(hl.$$.fragment,l),o(_),o(Zl.$$.fragment,l),o(x),o(Nl.$$.fragment,l),o(Ql.$$.fragment,l),o(W),o(Rl.$$.fragment,l),o(_l.$$.fragment,l),o(xl.$$.fragment,l),o(Vl.$$.fragment,l),o(Y.$$.fragment,l),o(El.$$.fragment,l),Ot=!0)},o(l){c(d.$$.fragment,l),c(N.$$.fragment,l),c(G),c(M.$$.fragment,l),c(F.$$.fragment,l),c(H.$$.fragment,l),c(D.$$.fragment,l),c(q.$$.fragment,l),c(K.$$.fragment,l),c(P.$$.fragment,l),c(ll.$$.fragment,l),c(tl.$$.fragment,l),c(el.$$.fragment,l),c(nl.$$.fragment,l),c(Ml.$$.fragment,l),c(il.$$.fragment,l),c(cl.$$.fragment,l),c(ol.$$.fragment,l),c(z.$$.fragment,l),c(rl.$$.fragment,l),c(yl.$$.fragment,l),c(ul.$$.fragment,l),c(bl.$$.fragment,l),c(hl.$$.fragment,l),c(_),c(Zl.$$.fragment,l),c(x),c(Nl.$$.fragment,l),c(Ql.$$.fragment,l),c(W),c(Rl.$$.fragment,l),c(_l.$$.fragment,l),c(xl.$$.fragment,l),c(Vl.$$.fragment,l),c(Y.$$.fragment,l),c(El.$$.fragment,l),Ot=!1},d(l){l&&(s(J),s(n),s(j),s(m),s(U),s(k),s(Q),s($),s(Z),s(Kl),s(S),s(Pl),s(v),s(Ol),s(E),s(lt),s(tt),s(A),s(st),s(et),s(at),s(L),s(nt),s(Mt),s(pt),s(O),s(it),s(dt),s(ct),s(sl),s(ot),s(Jt),s(al),s(mt),s(rt),s(Tt),s(pl),s(yt),s(ut),s(R),s(Ut),s(dl),s(bt),s(wt),s(ht),s(Jl),s(jt),s(ft),s(ml),s(Zt),s(gt),s(Tl),s(Gt),s(Nt),s(It),s(Ul),s(Ct),s(Qt),s(wl),s($t),s(kt),s(jl),s(Rt),s(vl),s(fl),s(Bt),s(_t),s(gl),s(Xt),s(Hl),s(Gl),s(xt),s(Vt),s(Il),s(Wt),s(Cl),s(Et),s(zt),s($l),s(Yt),s(Al),s(kl),s(Ft),s(St),s(Bl),s(vt),s(Ht),s(Xl),s(At),s(Dt),s(qt),s(Wl),s(Lt),s(Kt),s(Pt),s(Dl)),s(a),u(d,l),u(N,l),zl[g].d(l),u(M,l),u(F,l),u(H,l),u(D,l),u(q,l),u(K,l),u(P,l),u(ll,l),u(tl,l),u(el,l),u(nl,l),u(Ml,l),u(il,l),u(cl,l),u(ol,l),u(z,l),u(rl,l),u(yl,l),u(ul,l),u(bl,l),u(hl,l),Yl[B].d(l),u(Zl,l),Fl[X].d(l),u(Nl,l),u(Ql,l),Sl[V].d(l),u(Rl,l),u(_l,l),u(xl,l),u(Vl,l),u(Y,l),u(El,l)}}}const Te='{"title":"使用 FAISS 进行语义搜索","local":"使用 FAISS 进行语义搜索","sections":[{"title":"使用文本嵌入进行语义搜索","local":"使用文本嵌入进行语义搜索","sections":[],"depth":2},{"title":"加载和准备数据集","local":"加载和准备数据集","sections":[],"depth":2},{"title":"创建文本嵌入","local":"创建文本嵌入","sections":[],"depth":2},{"title":"使用 FAISS 进行高效的相似性搜索","local":"使用 FAISS 进行高效的相似性搜索","sections":[],"depth":2}],"depth":1}';function ye(I,a,J){let n="pt";return Ls(()=>{const j=new URLSearchParams(window.location.search);J(0,n=j.get("fw")||"pt")}),[n]}class ge extends Ks{constructor(a){super(),Ps(this,a,ye,re,qs,{})}}export{ge as component};
