import{s as Ks,o as Ps,n as qs}from"../chunks/scheduler.cc52f4b9.js";import{S as Os,i as le,e as b,s as p,c as r,h as te,a as w,d as s,b as i,f as As,g as T,j as f,k as Ll,w as is,l as se,m as e,n as y,o as c,u as ss,t as o,p as u,v as es}from"../chunks/index.9480bb2b.js";import{T as Ds}from"../chunks/Tip.f7b80743.js";import{C as ee,H as Kl,E as ae}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.009dc98d.js";import{Y as ne}from"../chunks/Youtube.7b12d9e8.js";import{C as h}from"../chunks/CodeBlock.184aadb6.js";import{C as Ls}from"../chunks/CourseFloatingBanner.6488bde3.js";import{F as Me}from"../chunks/FrameworkSwitchCourse.42d12053.js";function pe(G){let a,J;return a=new Ls({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 ie(G){let a,J;return a=new Ls({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 de(G){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:qs,d(n){n&&s(a)}}}function ce(G){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,g){y(a,m,g),e(m,J,g),e(m,n,g),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 oe(G){let a,J,n,j="将模型和输入的文本放到 GPU 上会加速嵌入过程，所以让我们现在就这么做：",d,m,g;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,N){y(a,U,N),e(U,J,N),e(U,n,N),e(U,d,N),y(m,U,N),g=!0},i(U){g||(o(a.$$.fragment,U),o(m.$$.fragment,U),g=!0)},o(U){c(a.$$.fragment,U),c(m.$$.fragment,U),g=!1},d(U){U&&(s(J),s(n),s(d)),u(a,U),u(m,U)}}}function Je(G){let a,J,n,j="我们可以将第一个文本条目喂给它并检查输出的形状来测试这个函数是否正常工作：",d,m,g,U,N,Q,$="太好了，我们已经将语料库中的第一个条目转换为了一个 768 维向量！我们可以用 <code>Dataset.map()</code> 将我们的 <code>get_embeddings()</code> 函数应用到我们语料库中的每一行，然后创建一个新的 <code>embeddings</code> 列：",C,I,k;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}}),I=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),g=p(),r(U.$$.fragment),N=p(),Q=b("p"),Q.innerHTML=$,C=p(),r(I.$$.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),g=i(M),T(U.$$.fragment,M),N=i(M),Q=w(M,"P",{"data-svelte-h":!0}),f(Q)!=="svelte-17bz3th"&&(Q.innerHTML=$),C=i(M),T(I.$$.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,g,Z),y(U,M,Z),e(M,N,Z),e(M,Q,Z),e(M,C,Z),y(I,M,Z),k=!0},i(M){k||(o(a.$$.fragment,M),o(m.$$.fragment,M),o(U.$$.fragment,M),o(I.$$.fragment,M),k=!0)},o(M){c(a.$$.fragment,M),c(m.$$.fragment,M),c(U.$$.fragment,M),c(I.$$.fragment,M),k=!1},d(M){M&&(s(J),s(n),s(d),s(g),s(N),s(Q),s(C)),u(a,M),u(m,M),u(U,M),u(I,M)}}}function me(G){let a,J,n,j="我们可以将第一条数据喂给它并检查输出的形状来测试这个函数是否正常工作：",d,m,g,U,N,Q,$="太好了，我们已经将语料库中的第一个条目转换为了一个 768 维向量！我们可以用 <code>Dataset.map()</code> 将我们的 <code>get_embeddings()</code> 函数应用到我们语料库中的每一行，然后创建一个新的 <code>embeddings</code> 列：",C,I,k;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}}),I=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),g=p(),r(U.$$.fragment),N=p(),Q=b("p"),Q.innerHTML=$,C=p(),r(I.$$.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),g=i(M),T(U.$$.fragment,M),N=i(M),Q=w(M,"P",{"data-svelte-h":!0}),f(Q)!=="svelte-17bz3th"&&(Q.innerHTML=$),C=i(M),T(I.$$.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,g,Z),y(U,M,Z),e(M,N,Z),e(M,Q,Z),e(M,C,Z),y(I,M,Z),k=!0},i(M){k||(o(a.$$.fragment,M),o(m.$$.fragment,M),o(U.$$.fragment,M),o(I.$$.fragment,M),k=!0)},o(M){c(a.$$.fragment,M),c(m.$$.fragment,M),c(U.$$.fragment,M),c(I.$$.fragment,M),k=!1},d(M){M&&(s(J),s(n),s(d),s(g),s(N),s(Q),s(C)),u(a,M),u(m,M),u(U,M),u(I,M)}}}function re(G){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 Te(G){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 ye(G){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:qs,d(n){n&&s(a)}}}function ue(G){let a,J,n,j,d,m,g,U,N,Q,$,C,I,k,M='在 <a href="/course/chapter5/5">第5小节</a> ，我们创建了一个 🤗 Datasets 仓库的 GitHub issues 和评论组成的数据集。在本节，我们将使用这些信息构建一个搜索引擎，帮助我们找到关于该库的最相关的 issue 的答案！',Z,F,Pl,S,Ol,v,ds='正如我们在 <a href="/course/chapter1">第一章</a> ，学习的，基于 Transformer 的语言模型会将文本中的每个 token 转换为嵌入向量。事实证明，我们可以 “池化（pool）” 嵌入向量以创建整个句子、段落或（在某些情况下）文档的向量表示。然后，通过计算每个嵌入之间的点积相似度（或其他一些相似度度量）并返回相似度最大的文档，这些嵌入可用于在语料库中找到相似的文档。',lt,H,cs="在本节中，我们将使用文本嵌入向量来开发语义搜索引擎。与基于将查询中的关键字的传统方法相比，这些搜索引擎具有多种优势。",tt,E,os='<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."/>',st,A,et,D,Js="首先，我们需要下载我们的 GitHub issues 数据集，所以让我们像往常那样使用 <code>load_dataset()</code> 函数：",at,q,nt,L,Mt,K,ms="在此，我们在 <code>load_dataset()</code> 中指定了默认的 <code>train（训练集）</code> 部分，因此它返回一个 <code>Dataset</code> 而不是 <code>DatasetDict</code> 。首要任务是排除掉拉取请求（pull），因为这些请求往往很少用于回答提出的 issue，会为我们的搜索引擎引入干扰。正如我们现在熟悉的那样，我们可以使用 <code>Dataset.filter()</code> 函数来排除数据集中的这些行。与此同时，让我们也筛选掉没有评论的行，因为这些行没有为用户提问提供回答：",pt,P,it,O,dt,ll,rs="我们可以看到，我们的数据集中有很多列，其中大部分在构建我们的搜索引擎都不会使用。从搜索的角度来看，信息量最大的列是 <code>title</code> ， <code>body</code> ，和 <code>comments</code> ，而 <code>html_url</code> 为我们提供了一个回到原 issue 的链接。让我们使用 <code>Dataset.remove_columns()</code> 删除其余的列：",ct,tl,ot,sl,Jt,el,Ts='为了创建我们的文本嵌入数据集，我们将用 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> 格式：',mt,al,rt,nl,ys="如果我们检查这个 <code>DataFrame</code> 的第一行，我们可以看到这个 issue 有四个相关评论：",Tt,Ml,yt,pl,ut,il,us="我们希望使用 <code>explode()</code> 将这些评论中的每一条都展开成为一行。让我们看看是否可以做到：",Ut,dl,bt,R,Us='<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>',wt,cl,bs="非常好，我们可以看到其他三列已经被复制了，并且 <code>comments</code> 列里存放着单独的评论！现在我们已经完成了 Pandas 要完成的部分功能，我们可以通过加载内存中的 <code>DataFrame</code> 快速切换回 <code>Dataset</code> ：",ht,ol,jt,Jl,ft,ml,ws="太好了，我们获取到了几千条的评论！",Zt,z,gt,rl,hs="既然我们每行有一个评论，让我们创建一个新的 <code>comments_length</code> 列来存放每条评论的字数：",Gt,Tl,Nt,yl,js="我们可以使用这个新列来过滤掉简短的评论，其中通常包括“cc @lewtun”或“谢谢！”之类与我们的搜索引擎无关的内容。筛选的精确数字没有硬性规定，但大约大于 15 个单词似乎是一个不错的选择：",It,ul,Ct,Ul,Qt,bl,fs="稍微清理了我们的数据集后，让我们使用 issue 标题、描述和评论构建一个新的 <code>text</code> 列。像往常一样，我们可以编写一个简单的函数，并将其传递给 <code>Dataset.map()</code> 来完成这些操作",$t,wl,kt,hl,Zs="我们终于准备好创建一些文本嵌入了！让我们继续。",Rt,jl,Bt,fl,gs='正如我们在 <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 ：',_t,B,_,Hl,Zl,Gs="根据我们之前的想法，我们希望将我们的 GitHub issue 中的每一条记录转化为一个单一的向量，所以我们需要以某种方式“池化（pool）”或平均每个词的嵌入向量。一种流行的方法是在我们模型的输出上进行 <code>CLS 池化</code> ，我们只需要收集 <code>[CLS]</code> token 的的最后一个隐藏状态。以下函数实现了这个功能：",xt,gl,Xt,Gl,Ns="接下来，我们将创建一个辅助函数，它将对一组文档进行 tokenize，然后将张量放在 GPU 上，接着将它们喂给模型，最后对输出进行 CLS 池化：",Vt,x,X,Al,Nl,Is="请注意，在上面的代码中我们已经将文本嵌入转换为 NumPy 数组——这是因为当我们尝试使用 FAISS 搜索它们时，🤗 Datasets 需要这种格式，让我们继续吧。",Wt,Il,Et,Cl,Cs='现在我们有了一个文本嵌入数据集，我们需要一些方法来搜索它们。为此，我们将使用🤗 Datasets 中一种特殊的数据结构，称为 FAISS 指数。 <a href="https://faiss.ai/" rel="nofollow">FAISS</a> （Facebook AI Similarity Search 的缩写）是一个库，提供了用于快速搜索和聚类嵌入向量的高效算法。',zt,Ql,Qs="FAISS 背后的基本思想是创建一个特殊的数据结构，称为 <code>index（索引）</code> 它可以找到哪些嵌入与输入嵌入相似。在 🤗 Datasets 中创建一个 FAISS index（索引）很简单——我们使用 <code>Dataset.add_faiss_index()</code> 函数并指定我们要索引的数据集的哪一列：",Yt,$l,Ft,kl,$s="现在，我们可以使用 <code>Dataset.get_nearest_examples()</code> 函数进行最近邻居查找。让我们通过首先嵌入一个 issue 来测试这一点，如下所示：",St,V,W,Dl,Rl,ks="就像对文档进行嵌入一样，我们现在有一个表示查询的 768 维向量，我们可以将其与整个语料库进行比较以找到最相似的嵌入：",vt,Bl,Ht,_l,Rs="<code>Dataset.get_nearest_examples()</code> 函数返回一个元组，包括评分（评价查询和文档之间的相似程度）和对应的样本（这里是 5 个最佳匹配）。让我们把这些收集到一个 <code>pandas.DataFrame</code> ，这样我们就可以轻松地对它们进行排序：",At,xl,Dt,Xl,Bs="现在我们可以遍历前几行来查看我们的查询与评论的匹配程度如何：",qt,Vl,Lt,Wl,Kt,El,_s="不错！我们的输出的第 2 个结果似乎与查询匹配。",Pt,Y,Ot,zl,ls,ql,ts;d=new Me({props:{fw:G[0]}}),g=new ee({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),N=new Kl({props:{title:"使用 FAISS 进行语义搜索",local:"使用 FAISS 进行语义搜索",headingTag:"h1"}});const xs=[ie,pe],Yl=[];function Xs(l,t){return l[0]==="pt"?0:1}$=Xs(G),C=Yl[$]=xs[$](G),F=new ne({props:{id:"OATCgQtNX2o"}}),S=new Kl({props:{title:"使用文本嵌入进行语义搜索",local:"使用文本嵌入进行语义搜索",headingTag:"h2"}}),A=new Kl({props:{title:"加载和准备数据集",local:"加载和准备数据集",headingTag:"h2"}}),q=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}}),L=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}}),P=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}}),O=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}}),tl=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}}),sl=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}}),al=new h({props:{code:"aXNzdWVzX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJwYW5kYXMlMjIpJTBBZGYlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldCU1QiUzQSU1RA==",highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`,wrap:!1}}),Ml=new h({props:{code:"ZGYlNUIlMjJjb21tZW50cyUyMiU1RCU1QjAlNUQudG9saXN0KCk=",highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()',wrap:!1}}),pl=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}}),dl=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}}),ol=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}}),Jl=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 Ds({props:{$$slots:{default:[de]},$$scope:{ctx:G}}}),Tl=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}}),ul=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}}),wl=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}}),jl=new Kl({props:{title:"创建文本嵌入",local:"创建文本嵌入",headingTag:"h2"}});const Vs=[oe,ce],Fl=[];function Ws(l,t){return l[0]==="pt"?0:1}B=Ws(G),_=Fl[B]=Vs[B](G),gl=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 Es=[me,Je],Sl=[];function zs(l,t){return l[0]==="pt"?0:1}x=zs(G),X=Sl[x]=Es[x](G),Il=new Kl({props:{title:"使用 FAISS 进行高效的相似性搜索",local:"使用 FAISS 进行高效的相似性搜索",headingTag:"h2"}}),$l=new h({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0LmFkZF9mYWlzc19pbmRleChjb2x1bW4lM0QlMjJlbWJlZGRpbmdzJTIyKQ==",highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)',wrap:!1}});const Ys=[Te,re],vl=[];function Fs(l,t){return l[0]==="pt"?0:1}return V=Fs(G),W=vl[V]=Ys[V](G),Bl=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}}),xl=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}}),Vl=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}}),Wl=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 Ds({props:{$$slots:{default:[ye]},$$scope:{ctx:G}}}),zl=new ae({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(g.$$.fragment),U=p(),r(N.$$.fragment),Q=p(),C.c(),I=p(),k=b("p"),k.innerHTML=M,Z=p(),r(F.$$.fragment),Pl=p(),r(S.$$.fragment),Ol=p(),v=b("p"),v.innerHTML=ds,lt=p(),H=b("p"),H.textContent=cs,tt=p(),E=b("div"),E.innerHTML=os,st=p(),r(A.$$.fragment),et=p(),D=b("p"),D.innerHTML=Js,at=p(),r(q.$$.fragment),nt=p(),r(L.$$.fragment),Mt=p(),K=b("p"),K.innerHTML=ms,pt=p(),r(P.$$.fragment),it=p(),r(O.$$.fragment),dt=p(),ll=b("p"),ll.innerHTML=rs,ct=p(),r(tl.$$.fragment),ot=p(),r(sl.$$.fragment),Jt=p(),el=b("p"),el.innerHTML=Ts,mt=p(),r(al.$$.fragment),rt=p(),nl=b("p"),nl.innerHTML=ys,Tt=p(),r(Ml.$$.fragment),yt=p(),r(pl.$$.fragment),ut=p(),il=b("p"),il.innerHTML=us,Ut=p(),r(dl.$$.fragment),bt=p(),R=b("table"),R.innerHTML=Us,wt=p(),cl=b("p"),cl.innerHTML=bs,ht=p(),r(ol.$$.fragment),jt=p(),r(Jl.$$.fragment),ft=p(),ml=b("p"),ml.textContent=ws,Zt=p(),r(z.$$.fragment),gt=p(),rl=b("p"),rl.innerHTML=hs,Gt=p(),r(Tl.$$.fragment),Nt=p(),yl=b("p"),yl.textContent=js,It=p(),r(ul.$$.fragment),Ct=p(),r(Ul.$$.fragment),Qt=p(),bl=b("p"),bl.innerHTML=fs,$t=p(),r(wl.$$.fragment),kt=p(),hl=b("p"),hl.textContent=Zs,Rt=p(),r(jl.$$.fragment),Bt=p(),fl=b("p"),fl.innerHTML=gs,_t=p(),_.c(),Hl=p(),Zl=b("p"),Zl.innerHTML=Gs,xt=p(),r(gl.$$.fragment),Xt=p(),Gl=b("p"),Gl.textContent=Ns,Vt=p(),X.c(),Al=p(),Nl=b("p"),Nl.textContent=Is,Wt=p(),r(Il.$$.fragment),Et=p(),Cl=b("p"),Cl.innerHTML=Cs,zt=p(),Ql=b("p"),Ql.innerHTML=Qs,Yt=p(),r($l.$$.fragment),Ft=p(),kl=b("p"),kl.innerHTML=$s,St=p(),W.c(),Dl=p(),Rl=b("p"),Rl.textContent=ks,vt=p(),r(Bl.$$.fragment),Ht=p(),_l=b("p"),_l.innerHTML=Rs,At=p(),r(xl.$$.fragment),Dt=p(),Xl=b("p"),Xl.textContent=Bs,qt=p(),r(Vl.$$.fragment),Lt=p(),r(Wl.$$.fragment),Kt=p(),El=b("p"),El.textContent=_s,Pt=p(),r(Y.$$.fragment),Ot=p(),r(zl.$$.fragment),ls=p(),ql=b("p"),this.h()},l(l){const t=te("svelte-u9bgzb",document.head);a=w(t,"META",{name:!0,content:!0}),t.forEach(s),J=i(l),n=w(l,"P",{}),As(n).forEach(s),j=i(l),T(d.$$.fragment,l),m=i(l),T(g.$$.fragment,l),U=i(l),T(N.$$.fragment,l),Q=i(l),C.l(l),I=i(l),k=w(l,"P",{"data-svelte-h":!0}),f(k)!=="svelte-1k1uitg"&&(k.innerHTML=M),Z=i(l),T(F.$$.fragment,l),Pl=i(l),T(S.$$.fragment,l),Ol=i(l),v=w(l,"P",{"data-svelte-h":!0}),f(v)!=="svelte-1bo3r1m"&&(v.innerHTML=ds),lt=i(l),H=w(l,"P",{"data-svelte-h":!0}),f(H)!=="svelte-17w33xe"&&(H.textContent=cs),tt=i(l),E=w(l,"DIV",{class:!0,"data-svelte-h":!0}),f(E)!=="svelte-yxatr"&&(E.innerHTML=os),st=i(l),T(A.$$.fragment,l),et=i(l),D=w(l,"P",{"data-svelte-h":!0}),f(D)!=="svelte-1j4s9k3"&&(D.innerHTML=Js),at=i(l),T(q.$$.fragment,l),nt=i(l),T(L.$$.fragment,l),Mt=i(l),K=w(l,"P",{"data-svelte-h":!0}),f(K)!=="svelte-2cqt6s"&&(K.innerHTML=ms),pt=i(l),T(P.$$.fragment,l),it=i(l),T(O.$$.fragment,l),dt=i(l),ll=w(l,"P",{"data-svelte-h":!0}),f(ll)!=="svelte-15hujmg"&&(ll.innerHTML=rs),ct=i(l),T(tl.$$.fragment,l),ot=i(l),T(sl.$$.fragment,l),Jt=i(l),el=w(l,"P",{"data-svelte-h":!0}),f(el)!=="svelte-13qbpuw"&&(el.innerHTML=Ts),mt=i(l),T(al.$$.fragment,l),rt=i(l),nl=w(l,"P",{"data-svelte-h":!0}),f(nl)!=="svelte-1y6s0lg"&&(nl.innerHTML=ys),Tt=i(l),T(Ml.$$.fragment,l),yt=i(l),T(pl.$$.fragment,l),ut=i(l),il=w(l,"P",{"data-svelte-h":!0}),f(il)!=="svelte-62usvk"&&(il.innerHTML=us),Ut=i(l),T(dl.$$.fragment,l),bt=i(l),R=w(l,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),f(R)!=="svelte-1g5whzd"&&(R.innerHTML=Us),wt=i(l),cl=w(l,"P",{"data-svelte-h":!0}),f(cl)!=="svelte-axvn69"&&(cl.innerHTML=bs),ht=i(l),T(ol.$$.fragment,l),jt=i(l),T(Jl.$$.fragment,l),ft=i(l),ml=w(l,"P",{"data-svelte-h":!0}),f(ml)!=="svelte-x6393a"&&(ml.textContent=ws),Zt=i(l),T(z.$$.fragment,l),gt=i(l),rl=w(l,"P",{"data-svelte-h":!0}),f(rl)!=="svelte-vg61zh"&&(rl.innerHTML=hs),Gt=i(l),T(Tl.$$.fragment,l),Nt=i(l),yl=w(l,"P",{"data-svelte-h":!0}),f(yl)!=="svelte-1v6qqei"&&(yl.textContent=js),It=i(l),T(ul.$$.fragment,l),Ct=i(l),T(Ul.$$.fragment,l),Qt=i(l),bl=w(l,"P",{"data-svelte-h":!0}),f(bl)!=="svelte-s6nife"&&(bl.innerHTML=fs),$t=i(l),T(wl.$$.fragment,l),kt=i(l),hl=w(l,"P",{"data-svelte-h":!0}),f(hl)!=="svelte-lpyv6q"&&(hl.textContent=Zs),Rt=i(l),T(jl.$$.fragment,l),Bt=i(l),fl=w(l,"P",{"data-svelte-h":!0}),f(fl)!=="svelte-1ou84a4"&&(fl.innerHTML=gs),_t=i(l),_.l(l),Hl=i(l),Zl=w(l,"P",{"data-svelte-h":!0}),f(Zl)!=="svelte-1o32zfz"&&(Zl.innerHTML=Gs),xt=i(l),T(gl.$$.fragment,l),Xt=i(l),Gl=w(l,"P",{"data-svelte-h":!0}),f(Gl)!=="svelte-d2x713"&&(Gl.textContent=Ns),Vt=i(l),X.l(l),Al=i(l),Nl=w(l,"P",{"data-svelte-h":!0}),f(Nl)!=="svelte-6mj4g9"&&(Nl.textContent=Is),Wt=i(l),T(Il.$$.fragment,l),Et=i(l),Cl=w(l,"P",{"data-svelte-h":!0}),f(Cl)!=="svelte-cma3ou"&&(Cl.innerHTML=Cs),zt=i(l),Ql=w(l,"P",{"data-svelte-h":!0}),f(Ql)!=="svelte-1wc0p1"&&(Ql.innerHTML=Qs),Yt=i(l),T($l.$$.fragment,l),Ft=i(l),kl=w(l,"P",{"data-svelte-h":!0}),f(kl)!=="svelte-xjel5k"&&(kl.innerHTML=$s),St=i(l),W.l(l),Dl=i(l),Rl=w(l,"P",{"data-svelte-h":!0}),f(Rl)!=="svelte-iayzgi"&&(Rl.textContent=ks),vt=i(l),T(Bl.$$.fragment,l),Ht=i(l),_l=w(l,"P",{"data-svelte-h":!0}),f(_l)!=="svelte-11tm5f0"&&(_l.innerHTML=Rs),At=i(l),T(xl.$$.fragment,l),Dt=i(l),Xl=w(l,"P",{"data-svelte-h":!0}),f(Xl)!=="svelte-1v4c8w0"&&(Xl.textContent=Bs),qt=i(l),T(Vl.$$.fragment,l),Lt=i(l),T(Wl.$$.fragment,l),Kt=i(l),El=w(l,"P",{"data-svelte-h":!0}),f(El)!=="svelte-1l7ida9"&&(El.textContent=_s),Pt=i(l),T(Y.$$.fragment,l),Ot=i(l),T(zl.$$.fragment,l),ls=i(l),ql=w(l,"P",{}),As(ql).forEach(s),this.h()},h(){Ll(a,"name","hf:doc:metadata"),Ll(a,"content",Ue),Ll(E,"class","flex justify-center"),Ll(R,"border","1"),Ll(R,"class","dataframe"),is(R,"table-layout","fixed"),is(R,"word-wrap","break-word"),is(R,"width","100%")},m(l,t){se(document.head,a),e(l,J,t),e(l,n,t),e(l,j,t),y(d,l,t),e(l,m,t),y(g,l,t),e(l,U,t),y(N,l,t),e(l,Q,t),Yl[$].m(l,t),e(l,I,t),e(l,k,t),e(l,Z,t),y(F,l,t),e(l,Pl,t),y(S,l,t),e(l,Ol,t),e(l,v,t),e(l,lt,t),e(l,H,t),e(l,tt,t),e(l,E,t),e(l,st,t),y(A,l,t),e(l,et,t),e(l,D,t),e(l,at,t),y(q,l,t),e(l,nt,t),y(L,l,t),e(l,Mt,t),e(l,K,t),e(l,pt,t),y(P,l,t),e(l,it,t),y(O,l,t),e(l,dt,t),e(l,ll,t),e(l,ct,t),y(tl,l,t),e(l,ot,t),y(sl,l,t),e(l,Jt,t),e(l,el,t),e(l,mt,t),y(al,l,t),e(l,rt,t),e(l,nl,t),e(l,Tt,t),y(Ml,l,t),e(l,yt,t),y(pl,l,t),e(l,ut,t),e(l,il,t),e(l,Ut,t),y(dl,l,t),e(l,bt,t),e(l,R,t),e(l,wt,t),e(l,cl,t),e(l,ht,t),y(ol,l,t),e(l,jt,t),y(Jl,l,t),e(l,ft,t),e(l,ml,t),e(l,Zt,t),y(z,l,t),e(l,gt,t),e(l,rl,t),e(l,Gt,t),y(Tl,l,t),e(l,Nt,t),e(l,yl,t),e(l,It,t),y(ul,l,t),e(l,Ct,t),y(Ul,l,t),e(l,Qt,t),e(l,bl,t),e(l,$t,t),y(wl,l,t),e(l,kt,t),e(l,hl,t),e(l,Rt,t),y(jl,l,t),e(l,Bt,t),e(l,fl,t),e(l,_t,t),Fl[B].m(l,t),e(l,Hl,t),e(l,Zl,t),e(l,xt,t),y(gl,l,t),e(l,Xt,t),e(l,Gl,t),e(l,Vt,t),Sl[x].m(l,t),e(l,Al,t),e(l,Nl,t),e(l,Wt,t),y(Il,l,t),e(l,Et,t),e(l,Cl,t),e(l,zt,t),e(l,Ql,t),e(l,Yt,t),y($l,l,t),e(l,Ft,t),e(l,kl,t),e(l,St,t),vl[V].m(l,t),e(l,Dl,t),e(l,Rl,t),e(l,vt,t),y(Bl,l,t),e(l,Ht,t),e(l,_l,t),e(l,At,t),y(xl,l,t),e(l,Dt,t),e(l,Xl,t),e(l,qt,t),y(Vl,l,t),e(l,Lt,t),y(Wl,l,t),e(l,Kt,t),e(l,El,t),e(l,Pt,t),y(Y,l,t),e(l,Ot,t),y(zl,l,t),e(l,ls,t),e(l,ql,t),ts=!0},p(l,[t]){const Ss={};t&1&&(Ss.fw=l[0]),d.$set(Ss);let as=$;$=Xs(l),$!==as&&(es(),c(Yl[as],1,1,()=>{Yl[as]=null}),ss(),C=Yl[$],C||(C=Yl[$]=xs[$](l),C.c()),o(C,1),C.m(I.parentNode,I));const vs={};t&2&&(vs.$$scope={dirty:t,ctx:l}),z.$set(vs);let ns=B;B=Ws(l),B!==ns&&(es(),c(Fl[ns],1,1,()=>{Fl[ns]=null}),ss(),_=Fl[B],_||(_=Fl[B]=Vs[B](l),_.c()),o(_,1),_.m(Hl.parentNode,Hl));let Ms=x;x=zs(l),x!==Ms&&(es(),c(Sl[Ms],1,1,()=>{Sl[Ms]=null}),ss(),X=Sl[x],X||(X=Sl[x]=Es[x](l),X.c()),o(X,1),X.m(Al.parentNode,Al));let ps=V;V=Fs(l),V!==ps&&(es(),c(vl[ps],1,1,()=>{vl[ps]=null}),ss(),W=vl[V],W||(W=vl[V]=Ys[V](l),W.c()),o(W,1),W.m(Dl.parentNode,Dl));const Hs={};t&2&&(Hs.$$scope={dirty:t,ctx:l}),Y.$set(Hs)},i(l){ts||(o(d.$$.fragment,l),o(g.$$.fragment,l),o(N.$$.fragment,l),o(C),o(F.$$.fragment,l),o(S.$$.fragment,l),o(A.$$.fragment,l),o(q.$$.fragment,l),o(L.$$.fragment,l),o(P.$$.fragment,l),o(O.$$.fragment,l),o(tl.$$.fragment,l),o(sl.$$.fragment,l),o(al.$$.fragment,l),o(Ml.$$.fragment,l),o(pl.$$.fragment,l),o(dl.$$.fragment,l),o(ol.$$.fragment,l),o(Jl.$$.fragment,l),o(z.$$.fragment,l),o(Tl.$$.fragment,l),o(ul.$$.fragment,l),o(Ul.$$.fragment,l),o(wl.$$.fragment,l),o(jl.$$.fragment,l),o(_),o(gl.$$.fragment,l),o(X),o(Il.$$.fragment,l),o($l.$$.fragment,l),o(W),o(Bl.$$.fragment,l),o(xl.$$.fragment,l),o(Vl.$$.fragment,l),o(Wl.$$.fragment,l),o(Y.$$.fragment,l),o(zl.$$.fragment,l),ts=!0)},o(l){c(d.$$.fragment,l),c(g.$$.fragment,l),c(N.$$.fragment,l),c(C),c(F.$$.fragment,l),c(S.$$.fragment,l),c(A.$$.fragment,l),c(q.$$.fragment,l),c(L.$$.fragment,l),c(P.$$.fragment,l),c(O.$$.fragment,l),c(tl.$$.fragment,l),c(sl.$$.fragment,l),c(al.$$.fragment,l),c(Ml.$$.fragment,l),c(pl.$$.fragment,l),c(dl.$$.fragment,l),c(ol.$$.fragment,l),c(Jl.$$.fragment,l),c(z.$$.fragment,l),c(Tl.$$.fragment,l),c(ul.$$.fragment,l),c(Ul.$$.fragment,l),c(wl.$$.fragment,l),c(jl.$$.fragment,l),c(_),c(gl.$$.fragment,l),c(X),c(Il.$$.fragment,l),c($l.$$.fragment,l),c(W),c(Bl.$$.fragment,l),c(xl.$$.fragment,l),c(Vl.$$.fragment,l),c(Wl.$$.fragment,l),c(Y.$$.fragment,l),c(zl.$$.fragment,l),ts=!1},d(l){l&&(s(J),s(n),s(j),s(m),s(U),s(Q),s(I),s(k),s(Z),s(Pl),s(Ol),s(v),s(lt),s(H),s(tt),s(E),s(st),s(et),s(D),s(at),s(nt),s(Mt),s(K),s(pt),s(it),s(dt),s(ll),s(ct),s(ot),s(Jt),s(el),s(mt),s(rt),s(nl),s(Tt),s(yt),s(ut),s(il),s(Ut),s(bt),s(R),s(wt),s(cl),s(ht),s(jt),s(ft),s(ml),s(Zt),s(gt),s(rl),s(Gt),s(Nt),s(yl),s(It),s(Ct),s(Qt),s(bl),s($t),s(kt),s(hl),s(Rt),s(Bt),s(fl),s(_t),s(Hl),s(Zl),s(xt),s(Xt),s(Gl),s(Vt),s(Al),s(Nl),s(Wt),s(Et),s(Cl),s(zt),s(Ql),s(Yt),s(Ft),s(kl),s(St),s(Dl),s(Rl),s(vt),s(Ht),s(_l),s(At),s(Dt),s(Xl),s(qt),s(Lt),s(Kt),s(El),s(Pt),s(Ot),s(ls),s(ql)),s(a),u(d,l),u(g,l),u(N,l),Yl[$].d(l),u(F,l),u(S,l),u(A,l),u(q,l),u(L,l),u(P,l),u(O,l),u(tl,l),u(sl,l),u(al,l),u(Ml,l),u(pl,l),u(dl,l),u(ol,l),u(Jl,l),u(z,l),u(Tl,l),u(ul,l),u(Ul,l),u(wl,l),u(jl,l),Fl[B].d(l),u(gl,l),Sl[x].d(l),u(Il,l),u($l,l),vl[V].d(l),u(Bl,l),u(xl,l),u(Vl,l),u(Wl,l),u(Y,l),u(zl,l)}}}const Ue='{"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 be(G,a,J){let n="pt";return Ps(()=>{const j=new URLSearchParams(window.location.search);J(0,n=j.get("fw")||"pt")}),[n]}class Ie extends Os{constructor(a){super(),le(this,a,be,ue,Ks,{})}}export{Ie as component};
