import{s as Ss,o as Ys,n as Ws}from"../chunks/scheduler.37c15a92.js";import{S as Fs,i as vs,g as T,s as p,r as U,A as Es,h as j,f as s,c as i,j as Xs,u as y,x as f,k as Al,l as ls,y as As,a as e,v as u,t as o,b as qt,d as m,w as J,p as Dt}from"../chunks/index.2bf4358c.js";import{T as Vs}from"../chunks/Tip.363c041f.js";import{Y as Hs}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as zs}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as qs}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Hl}from"../chunks/Heading.8ada512a.js";function Ds(C){let a,d;return a=new zs({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(){U(a.$$.fragment)},l(n){y(a.$$.fragment,n)},m(n,w){u(a,n,w),d=!0},i(n){d||(m(a.$$.fragment,n),d=!0)},o(n){o(a.$$.fragment,n),d=!1},d(n){J(a,n)}}}function Ls(C){let a,d;return a=new zs({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(){U(a.$$.fragment)},l(n){y(a.$$.fragment,n)},m(n,w){u(a,n,w),d=!0},i(n){d||(m(a.$$.fragment,n),d=!0)},o(n){o(a.$$.fragment,n),d=!1},d(n){J(a,n)}}}function Ks(C){let a,d='✏️ <strong>Try it out!</strong> 看看能不能不用pandas就可以完成列的扩充； 这有点棘手； 你可能会发现 🤗 Datasets 文档的 <a href="https://huggingface.co/docs/datasets/about_map_batch#batch-mapping" rel="nofollow">“Batch mapping”</a> 对这个任务很有用。';return{c(){a=T("p"),a.innerHTML=d},l(n){a=j(n,"P",{"data-svelte-h":!0}),f(a)!=="svelte-vyj3mk"&&(a.innerHTML=d)},m(n,w){e(n,a,w)},p:Ws,d(n){n&&s(a)}}}function Ps(C){let a,d,n,w="请注意，我们已将 from_pt=True 设置为  from_pretrained（） 方法的参数。这是因为 multi-qa-mpnet-base-dot-v1 检查点只有PyTorch权重，因此设置 from_pt=True 会自动将它们转换为TensorFlow格式。如您所见，在Transformers中的🤗框架之间切换非常简单！",r;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(){U(a.$$.fragment),d=p(),n=T("p"),n.textContent=w},l(c){y(a.$$.fragment,c),d=i(c),n=j(c,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1hp9rr8"&&(n.textContent=w)},m(c,G){u(a,c,G),e(c,d,G),e(c,n,G),r=!0},i(c){r||(m(a.$$.fragment,c),r=!0)},o(c){o(a.$$.fragment,c),r=!1},d(c){c&&(s(d),s(n)),J(a,c)}}}function Os(C){let a,d,n,w="为了加快嵌入过程，将模型和输入放在 GPU 设备上，所以现在让我们这样做：",r,c,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}}),c=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(){U(a.$$.fragment),d=p(),n=T("p"),n.textContent=w,r=p(),U(c.$$.fragment)},l(b){y(a.$$.fragment,b),d=i(b),n=j(b,"P",{"data-svelte-h":!0}),f(n)!=="svelte-oqsifu"&&(n.textContent=w),r=i(b),y(c.$$.fragment,b)},m(b,Q){u(a,b,Q),e(b,d,Q),e(b,n,Q),e(b,r,Q),u(c,b,Q),G=!0},i(b){G||(m(a.$$.fragment,b),m(c.$$.fragment,b),G=!0)},o(b){o(a.$$.fragment,b),o(c.$$.fragment,b),G=!1},d(b){b&&(s(d),s(n),s(r)),J(a,b),J(c,b)}}}function le(C){let a,d,n,w="我们可以通过在我们的语料库中输入第一个文本条目并检查输出维度来测试该函数是否有效：",r,c,G,b,Q,Z,R="太好了，我们已经将语料库中的第一个条目转换为 768 维向量！我们可以用 <strong>Dataset.map()</strong> 应用我们的 <strong>get_embeddings()</strong> 函数到我们语料库中的每一行，所以让我们创建一个新的 <strong>embeddings</strong> 列如下：",k,I,$;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}}),c=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}}),b=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(){U(a.$$.fragment),d=p(),n=T("p"),n.textContent=w,r=p(),U(c.$$.fragment),G=p(),U(b.$$.fragment),Q=p(),Z=T("p"),Z.innerHTML=R,k=p(),U(I.$$.fragment)},l(M){y(a.$$.fragment,M),d=i(M),n=j(M,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1kbu3gy"&&(n.textContent=w),r=i(M),y(c.$$.fragment,M),G=i(M),y(b.$$.fragment,M),Q=i(M),Z=j(M,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-ffa6kf"&&(Z.innerHTML=R),k=i(M),y(I.$$.fragment,M)},m(M,g){u(a,M,g),e(M,d,g),e(M,n,g),e(M,r,g),u(c,M,g),e(M,G,g),u(b,M,g),e(M,Q,g),e(M,Z,g),e(M,k,g),u(I,M,g),$=!0},i(M){$||(m(a.$$.fragment,M),m(c.$$.fragment,M),m(b.$$.fragment,M),m(I.$$.fragment,M),$=!0)},o(M){o(a.$$.fragment,M),o(c.$$.fragment,M),o(b.$$.fragment,M),o(I.$$.fragment,M),$=!1},d(M){M&&(s(d),s(n),s(r),s(G),s(Q),s(Z),s(k)),J(a,M),J(c,M),J(b,M),J(I,M)}}}function te(C){let a,d,n,w="我们可以通过在我们的语料库中输入第一个文本条目并检查输出维度来测试该函数是否有效：",r,c,G,b,Q,Z,R="太好了，我们已经将语料库中的第一个条目转换为 768 维向量！我们可以用 <strong>Dataset.map()</strong> 应用我们的 <strong>get_embeddings()</strong> 函数到我们语料库中的每一行，所以让我们创建一个新的 <strong>embeddings</strong> 列如下：",k,I,$;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}}),c=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}}),b=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(){U(a.$$.fragment),d=p(),n=T("p"),n.textContent=w,r=p(),U(c.$$.fragment),G=p(),U(b.$$.fragment),Q=p(),Z=T("p"),Z.innerHTML=R,k=p(),U(I.$$.fragment)},l(M){y(a.$$.fragment,M),d=i(M),n=j(M,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1kbu3gy"&&(n.textContent=w),r=i(M),y(c.$$.fragment,M),G=i(M),y(b.$$.fragment,M),Q=i(M),Z=j(M,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-ffa6kf"&&(Z.innerHTML=R),k=i(M),y(I.$$.fragment,M)},m(M,g){u(a,M,g),e(M,d,g),e(M,n,g),e(M,r,g),u(c,M,g),e(M,G,g),u(b,M,g),e(M,Q,g),e(M,Z,g),e(M,k,g),u(I,M,g),$=!0},i(M){$||(m(a.$$.fragment,M),m(c.$$.fragment,M),m(b.$$.fragment,M),m(I.$$.fragment,M),$=!0)},o(M){o(a.$$.fragment,M),o(c.$$.fragment,M),o(b.$$.fragment,M),o(I.$$.fragment,M),$=!1},d(M){M&&(s(d),s(n),s(r),s(G),s(Q),s(Z),s(k)),J(a,M),J(c,M),J(b,M),J(I,M)}}}function se(C){let a,d,n,w;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(){U(a.$$.fragment),d=p(),U(n.$$.fragment)},l(r){y(a.$$.fragment,r),d=i(r),y(n.$$.fragment,r)},m(r,c){u(a,r,c),e(r,d,c),u(n,r,c),w=!0},i(r){w||(m(a.$$.fragment,r),m(n.$$.fragment,r),w=!0)},o(r){o(a.$$.fragment,r),o(n.$$.fragment,r),w=!1},d(r){r&&s(d),J(a,r),J(n,r)}}}function ee(C){let a,d,n,w;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(){U(a.$$.fragment),d=p(),U(n.$$.fragment)},l(r){y(a.$$.fragment,r),d=i(r),y(n.$$.fragment,r)},m(r,c){u(a,r,c),e(r,d,c),u(n,r,c),w=!0},i(r){w||(m(a.$$.fragment,r),m(n.$$.fragment,r),w=!0)},o(r){o(a.$$.fragment,r),o(n.$$.fragment,r),w=!1},d(r){r&&s(d),J(a,r),J(n,r)}}}function ae(C){let a,d="✏️  试试看！创建您自己的查询并查看您是否可以在检索到的文档中找到答案。您可能需要增加参数k以扩大搜索范围。";return{c(){a=T("p"),a.textContent=d},l(n){a=j(n,"P",{"data-svelte-h":!0}),f(a)!=="svelte-hdmxaj"&&(a.textContent=d)},m(n,w){e(n,a,w)},p:Ws,d(n){n&&s(a)}}}function ne(C){let a,d,n,w,r,c,G,b,Q,Z,R,k,I='在<a href="/course/chapter5/5">第五小节</a>, 我们从 🤗 Datasets 存储库创建了一个包含 GitHub 问题和评论的数据集。在本节中，我们将使用这些信息来构建一个搜索引擎，它可以帮助我们找到这个库最紧迫问题的答案！',$,M,g,F,ql,v,ts='正如我们在<a href="/course/chapter1">第一章</a>,学习的, 基于 Transformer 的语言模型会将文本中的每个标记转换为嵌入向量.事实证明，可以“汇集”各个嵌入向量来创建整个句子、段落或文档（在某些情况下）的向量表示。然后，通过计算每个嵌入之间的点积相似度（或其他一些相似度度量）并返回相似度最大的文档，这些嵌入可用于在语料库中找到相似的文档。在本节中，我们将使用嵌入来开发语义搜索引擎。与基于将查询中的关键字的传统方法相比，这些搜索引擎具有多种优势。',Dl,z,ss='<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."/>',Ll,E,Kl,A,es="我们需要做的第一件事是下载我们的 GitHub issues 数据集，所以让我们像往常那样使用 <code>load_dataset()</code>函数：",Pl,H,Ol,q,lt,D,as="这里我们在load_dataset()中使用了默认的训练集分割，所以它返回一个数据集而不是数据集字典。第一项任务是过滤掉pull请求，因为这些请求很少用于回答用户提出的问题，而且会给我们的搜索引擎带来噪声。现在应该很熟悉了，我们可以使用dataset.filter()函数来排除数据集中的这些行。同时，让我们也过滤掉没有注释的行，因为这些行不会是用户提问的答案:",tt,L,st,K,et,P,ns="我们可以看到我们的数据集中有很多列，其中大部分我们不需要构建我们的搜索引擎。从搜索的角度来看，信息量最大的列是 <strong>title</strong> , <strong>body</strong> ， 和 <strong>comments</strong> ，而 <strong>html_url</strong> 为我们提供了一个回到源问题的链接。让我们使用 <strong>Dataset.remove_columns()</strong> 删除其余部分的功能：",at,O,nt,ll,Mt,tl,Ms='为了创建我们的嵌入，我们将用问题的标题和正文来扩充每条评论，因为这些字段通常包含有用的上下文信息。因为我们的 <strong>comments</strong> 列当前是每个问题的评论列表，我们需要“重新组合”列，以便每一条评论都包含一个 <strong>(html_url, title, body, comment)</strong> 元组。在 Pandas 中，我们可以使用 <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.explode.html" rel="nofollow">DataFrame.explode() 函数</a>, 它为类似列表的列中的每个元素创建一个新行，同时复制所有其他列值。为了看到它的实际效果，让我们首先切换到 Pandas的<strong>DataFrame</strong> 格式：',pt,sl,it,el,ps="如果我们检查这里的第一行 <strong>DataFrame</strong> 我们可以看到有四个评论与这个问题相关：",rt,al,ot,nl,mt,Ml,is="我们希望这些评论中的每一条都得到一行。让我们检查是否是这种情况：",dt,pl,ct,N,rs='<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,il,os="太好了，我们可以看到评论成功被扩充， <strong>comments</strong> 是包含个人评论的列！现在我们已经完成了 Pandas要完成的部分功能，我们可以快速切换回 <strong>Dataset</strong> 通过加载 <strong>DataFrame</strong> 在内存中：",yt,rl,ut,ol,Jt,ml,ms="太好了，我们获取到了几千条的评论！",bt,S,Tt,dl,ds="现在我们每行有一个评论，让我们创建一个新的 <strong>comments_length</strong> 列来存放每条评论的字数：",jt,cl,ht,Ul,cs="我们可以使用这个新列来过滤掉简短的评论，其中通常包括“cc @lewtun”或“谢谢！”之类与我们的搜索引擎无关的内容。虽然无法为过滤器选择的精确数字，但大约大于15 个单词似乎是一个不错的选择：",wt,yl,ft,ul,gt,Jl,Us="稍微清理了我们的数据集后，让我们将问题标题、描述和评论连接到一个新的 <strong>text</strong> 列。像往常一样，我们可以编写一个简单的函数，并将其传递给 <strong>Dataset.map()</strong>来做到这些 ：",Qt,bl,Zt,Tl,ys="我们终于准备好创建一些嵌入了！让我们来看看。",Gt,jl,Ct,hl,us='我们在<a href="/course/chapter2">第二章</a> 学过，我们可以通过使用 <strong>AutoModel</strong> 类来完成词嵌入。我们需要做的就是选择一个合适的检查点来加载模型。幸运的是，有一个名为 <strong>sentence-transformers</strong> 专门用于创建词嵌入。如库中<a href="https://www.sbert.net/examples/applications/semantic-search/README.html#symmetric-vs-asymmetric-semantic-search" rel="nofollow">文档</a>, 所述的，我们这次要实现的是非对称语义搜索，因为我们有一个简短的查询，我们希望在比如问题评论等更长的文档中找到其答案。通过查看<a href="https://www.sbert.net/docs/pretrained_models.html#model-overview" rel="nofollow">模型概述表</a> 我们可以发现 <strong>multi-qa-mpnet-base-dot-v1</strong> 检查点在语义搜索方面具有最佳性能，因此我们将在我们的应用程序中使用它。我们还将使用相同的检查点加载标记器：',It,_,B,Yl,wl,Js="正如我们之前提到的，我们希望将 GitHub 问题语料库中的每个条目表示为单个向量，因此我们需要以某种方式“池化”或平均化我们的标记嵌入。一种流行的方法是在我们模型的输出上执行CLS 池化，我们只获取<strong>[CLS]</strong> 令牌的最后一个隐藏状态。以下函数为我们提供了这样的方法：",kt,fl,$t,gl,bs="接下来，我们将创建一个辅助函数，该函数将标记文档列表，将tensor放在 GPU 上，然后提供给模型，最后对输出使用CLS 池化：",Rt,x,X,Fl,Ql,Ts="请注意，我们已经将嵌入转换为 NumPy 数组——这是因为当我们尝试使用 FAISS 索引它们时，🤗 Datasets需要这种格式，我们接下来会这样做。",Nt,Zl,_t,Gl,js='现在我们有了一个词嵌入数据集，我们需要一些方法来搜索它们。为此，我们将在 🤗 Datasets中使用一种特殊的数据结构，称为 FAISS指数.<a href="https://faiss.ai/" rel="nofollow">FAISS</a> (short for Facebook AI Similarity Search) （Facebook AI Similarity Search 的缩写）是一个提供高效算法来快速搜索和聚类嵌入向量的库。FAISS 背后的基本思想是创建一个特殊的数据结构，称为指数。这允许人们找到哪些嵌入词与输入的词嵌入相似。在 🤗 Datasets中创建一个 FAISS 索引很简单——我们使用 <strong>Dataset.add_faiss_index()</strong> 函数并指定我们要索引的数据集的哪一列：',Bt,Cl,xt,Il,hs="现在，我们可以使用<strong>Dataset.get_nearest_examples()</strong>函数进行最近邻居查找。让我们通过首先嵌入一个问题来测试这一点，如下所示：",Xt,V,W,vl,kl,ws="就像文档一样，我们现在有一个 768 维向量表示查询，我们可以将其与整个语料库进行比较以找到最相似的嵌入：",Vt,$l,Wt,Rl,fs="<strong>Dataset.get_nearest_examples()</strong> 函数返回一个分数元组，对查询和文档之间的相似度进行排序，以及一组最佳匹配的结果（这里是 5 个）。让我们把这些收集到一个 <strong>pandas.DataFrame</strong> 以便我们可以轻松地对它们进行排序：",zt,Nl,St,_l,gs="现在我们可以遍历前几行来查看我们的查询与评论的匹配程度：",Yt,Bl,Ft,xl,vt,Xl,Qs="我们的第二个搜索结果似乎与查询相符。",Et,Y,At,El,Ht;r=new qs({props:{fw:C[0]}}),G=new Hl({props:{title:"使用 FAISS 进行语义搜索",local:"使用 FAISS 进行语义搜索",headingTag:"h1"}});const Zs=[Ls,Ds],Vl=[];function Gs(l,t){return l[0]==="pt"?0:1}Q=Gs(C),Z=Vl[Q]=Zs[Q](C),M=new Hs({props:{id:"OATCgQtNX2o"}}),F=new Hl({props:{title:"使用嵌入进行语义搜索",local:"使用嵌入进行语义搜索",headingTag:"h2"}}),E=new Hl({props:{title:"加载和准备数据集",local:"加载和准备数据集",headingTag:"h2"}}),H=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}}),L=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}}),K=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}}),O=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}}),ll=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}}),sl=new h({props:{code:"aXNzdWVzX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJwYW5kYXMlMjIpJTBBZGYlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldCU1QiUzQSU1RA==",highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`,wrap:!1}}),al=new h({props:{code:"ZGYlNUIlMjJjb21tZW50cyUyMiU1RCU1QjAlNUQudG9saXN0KCk=",highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()',wrap:!1}}),nl=new h({props:{code:"JTVCJ3RoZSUyMGJ1ZyUyMGNvZGUlMjBsb2NhdGUlMjBpbiUyMCVFRiVCQyU5QSU1Q3IlNUNuJTIwJTIwJTIwJTIwaWYlMjBkYXRhX2FyZ3MudGFza19uYW1lJTIwaXMlMjBub3QlMjBOb25lJTNBJTVDciU1Q24lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBEb3dubG9hZGluZyUyMGFuZCUyMGxvYWRpbmclMjBhJTIwZGF0YXNldCUyMGZyb20lMjB0aGUlMjBodWIuJTVDciU1Q24lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkYXRhc2V0cyUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJnbHVlJTIyJTJDJTIwZGF0YV9hcmdzLnRhc2tfbmFtZSUyQyUyMGNhY2hlX2RpciUzRG1vZGVsX2FyZ3MuY2FjaGVfZGlyKSclMkMlMEElMjAnSGklMjAlNDBqaW5lYyUyQyU1Q3IlNUNuJTVDciU1Q25Gcm9tJTIwdGltZSUyMHRvJTIwdGltZSUyMHdlJTIwZ2V0JTIwdGhpcyUyMGtpbmQlMjBvZiUyMCU2MENvbm5lY3Rpb25FcnJvciU2MCUyMGNvbWluZyUyMGZyb20lMjB0aGUlMjBnaXRodWIuY29tJTIwd2Vic2l0ZSUzQSUyMGh0dHBzJTNBJTJGJTJGcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSU1Q3IlNUNuJTVDciU1Q25Ob3JtYWxseSUyQyUyMGl0JTIwc2hvdWxkJTIwd29yayUyMGlmJTIweW91JTIwd2FpdCUyMGElMjBsaXR0bGUlMjBhbmQlMjB0aGVuJTIwcmV0cnkuJTVDciU1Q24lNUNyJTVDbkNvdWxkJTIweW91JTIwcGxlYXNlJTIwY29uZmlybSUyMGlmJTIwdGhlJTIwcHJvYmxlbSUyMHBlcnNpc3RzJTNGJyUyQyUwQSUyMCdjYW5ub3QlMjBjb25uZWN0JUVGJUJDJThDZXZlbiUyMGJ5JTIwV2ViJTIwYnJvd3NlciVFRiVCQyU4Q3BsZWFzZSUyMGNoZWNrJTIwdGhhdCUyMCUyMHRoZXJlJTIwaXMlMjBzb21lJTIwJTIwcHJvYmxlbXMlRTMlODAlODInJTJDJTBBJTIwJ0klMjBjYW4lMjBhY2Nlc3MlMjBodHRwcyUzQSUyRiUyRnJhdy5naXRodWJ1c2VyY29udGVudC5jb20lMkZodWdnaW5nZmFjZSUyRmRhdGFzZXRzJTJGMS43LjAlMkZkYXRhc2V0cyUyRmdsdWUlMkZnbHVlLnB5JTIwd2l0aG91dCUyMHByb2JsZW0uLi4nJTVE",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}}),pl=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}}),rl=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}}),S=new Vs({props:{$$slots:{default:[Ks]},$$scope:{ctx:C}}}),cl=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}}),jl=new Hl({props:{title:"创建文本嵌入",local:"创建文本嵌入",headingTag:"h2"}});const Cs=[Os,Ps],Wl=[];function Is(l,t){return l[0]==="pt"?0:1}_=Is(C),B=Wl[_]=Cs[_](C),fl=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 ks=[te,le],zl=[];function $s(l,t){return l[0]==="pt"?0:1}x=$s(C),X=zl[x]=ks[x](C),Zl=new Hl({props:{title:"使用 FAISS 进行高效的相似性搜索",local:"使用 FAISS 进行高效的相似性搜索",headingTag:"h2"}}),Cl=new h({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0LmFkZF9mYWlzc19pbmRleChjb2x1bW4lM0QlMjJlbWJlZGRpbmdzJTIyKQ==",highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)',wrap:!1}});const Rs=[ee,se],Sl=[];function Ns(l,t){return l[0]==="pt"?0:1}return V=Ns(C),W=Sl[V]=Rs[V](C),$l=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}}),Nl=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}}),Bl=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}}),xl=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 Vs({props:{$$slots:{default:[ae]},$$scope:{ctx:C}}}),{c(){a=T("meta"),d=p(),n=T("p"),w=p(),U(r.$$.fragment),c=p(),U(G.$$.fragment),b=p(),Z.c(),R=p(),k=T("p"),k.innerHTML=I,$=p(),U(M.$$.fragment),g=p(),U(F.$$.fragment),ql=p(),v=T("p"),v.innerHTML=ts,Dl=p(),z=T("div"),z.innerHTML=ss,Ll=p(),U(E.$$.fragment),Kl=p(),A=T("p"),A.innerHTML=es,Pl=p(),U(H.$$.fragment),Ol=p(),U(q.$$.fragment),lt=p(),D=T("p"),D.textContent=as,tt=p(),U(L.$$.fragment),st=p(),U(K.$$.fragment),et=p(),P=T("p"),P.innerHTML=ns,at=p(),U(O.$$.fragment),nt=p(),U(ll.$$.fragment),Mt=p(),tl=T("p"),tl.innerHTML=Ms,pt=p(),U(sl.$$.fragment),it=p(),el=T("p"),el.innerHTML=ps,rt=p(),U(al.$$.fragment),ot=p(),U(nl.$$.fragment),mt=p(),Ml=T("p"),Ml.textContent=is,dt=p(),U(pl.$$.fragment),ct=p(),N=T("table"),N.innerHTML=rs,Ut=p(),il=T("p"),il.innerHTML=os,yt=p(),U(rl.$$.fragment),ut=p(),U(ol.$$.fragment),Jt=p(),ml=T("p"),ml.textContent=ms,bt=p(),U(S.$$.fragment),Tt=p(),dl=T("p"),dl.innerHTML=ds,jt=p(),U(cl.$$.fragment),ht=p(),Ul=T("p"),Ul.textContent=cs,wt=p(),U(yl.$$.fragment),ft=p(),U(ul.$$.fragment),gt=p(),Jl=T("p"),Jl.innerHTML=Us,Qt=p(),U(bl.$$.fragment),Zt=p(),Tl=T("p"),Tl.textContent=ys,Gt=p(),U(jl.$$.fragment),Ct=p(),hl=T("p"),hl.innerHTML=us,It=p(),B.c(),Yl=p(),wl=T("p"),wl.innerHTML=Js,kt=p(),U(fl.$$.fragment),$t=p(),gl=T("p"),gl.textContent=bs,Rt=p(),X.c(),Fl=p(),Ql=T("p"),Ql.textContent=Ts,Nt=p(),U(Zl.$$.fragment),_t=p(),Gl=T("p"),Gl.innerHTML=js,Bt=p(),U(Cl.$$.fragment),xt=p(),Il=T("p"),Il.innerHTML=hs,Xt=p(),W.c(),vl=p(),kl=T("p"),kl.textContent=ws,Vt=p(),U($l.$$.fragment),Wt=p(),Rl=T("p"),Rl.innerHTML=fs,zt=p(),U(Nl.$$.fragment),St=p(),_l=T("p"),_l.textContent=gs,Yt=p(),U(Bl.$$.fragment),Ft=p(),U(xl.$$.fragment),vt=p(),Xl=T("p"),Xl.textContent=Qs,Et=p(),U(Y.$$.fragment),At=p(),El=T("p"),this.h()},l(l){const t=Es("svelte-u9bgzb",document.head);a=j(t,"META",{name:!0,content:!0}),t.forEach(s),d=i(l),n=j(l,"P",{}),Xs(n).forEach(s),w=i(l),y(r.$$.fragment,l),c=i(l),y(G.$$.fragment,l),b=i(l),Z.l(l),R=i(l),k=j(l,"P",{"data-svelte-h":!0}),f(k)!=="svelte-1d4pcg4"&&(k.innerHTML=I),$=i(l),y(M.$$.fragment,l),g=i(l),y(F.$$.fragment,l),ql=i(l),v=j(l,"P",{"data-svelte-h":!0}),f(v)!=="svelte-q3vd5o"&&(v.innerHTML=ts),Dl=i(l),z=j(l,"DIV",{class:!0,"data-svelte-h":!0}),f(z)!=="svelte-yxatr"&&(z.innerHTML=ss),Ll=i(l),y(E.$$.fragment,l),Kl=i(l),A=j(l,"P",{"data-svelte-h":!0}),f(A)!=="svelte-1phxcv1"&&(A.innerHTML=es),Pl=i(l),y(H.$$.fragment,l),Ol=i(l),y(q.$$.fragment,l),lt=i(l),D=j(l,"P",{"data-svelte-h":!0}),f(D)!=="svelte-m2i4kf"&&(D.textContent=as),tt=i(l),y(L.$$.fragment,l),st=i(l),y(K.$$.fragment,l),et=i(l),P=j(l,"P",{"data-svelte-h":!0}),f(P)!=="svelte-ug1lb"&&(P.innerHTML=ns),at=i(l),y(O.$$.fragment,l),nt=i(l),y(ll.$$.fragment,l),Mt=i(l),tl=j(l,"P",{"data-svelte-h":!0}),f(tl)!=="svelte-1kg1745"&&(tl.innerHTML=Ms),pt=i(l),y(sl.$$.fragment,l),it=i(l),el=j(l,"P",{"data-svelte-h":!0}),f(el)!=="svelte-1xp1kx9"&&(el.innerHTML=ps),rt=i(l),y(al.$$.fragment,l),ot=i(l),y(nl.$$.fragment,l),mt=i(l),Ml=j(l,"P",{"data-svelte-h":!0}),f(Ml)!=="svelte-g547na"&&(Ml.textContent=is),dt=i(l),y(pl.$$.fragment,l),ct=i(l),N=j(l,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),f(N)!=="svelte-1g5whzd"&&(N.innerHTML=rs),Ut=i(l),il=j(l,"P",{"data-svelte-h":!0}),f(il)!=="svelte-dm5yb0"&&(il.innerHTML=os),yt=i(l),y(rl.$$.fragment,l),ut=i(l),y(ol.$$.fragment,l),Jt=i(l),ml=j(l,"P",{"data-svelte-h":!0}),f(ml)!=="svelte-x6393a"&&(ml.textContent=ms),bt=i(l),y(S.$$.fragment,l),Tt=i(l),dl=j(l,"P",{"data-svelte-h":!0}),f(dl)!=="svelte-1fe9yq1"&&(dl.innerHTML=ds),jt=i(l),y(cl.$$.fragment,l),ht=i(l),Ul=j(l,"P",{"data-svelte-h":!0}),f(Ul)!=="svelte-1865jni"&&(Ul.textContent=cs),wt=i(l),y(yl.$$.fragment,l),ft=i(l),y(ul.$$.fragment,l),gt=i(l),Jl=j(l,"P",{"data-svelte-h":!0}),f(Jl)!=="svelte-1pdubg8"&&(Jl.innerHTML=Us),Qt=i(l),y(bl.$$.fragment,l),Zt=i(l),Tl=j(l,"P",{"data-svelte-h":!0}),f(Tl)!=="svelte-u2hf4k"&&(Tl.textContent=ys),Gt=i(l),y(jl.$$.fragment,l),Ct=i(l),hl=j(l,"P",{"data-svelte-h":!0}),f(hl)!=="svelte-q2i5ks"&&(hl.innerHTML=us),It=i(l),B.l(l),Yl=i(l),wl=j(l,"P",{"data-svelte-h":!0}),f(wl)!=="svelte-1rzckei"&&(wl.innerHTML=Js),kt=i(l),y(fl.$$.fragment,l),$t=i(l),gl=j(l,"P",{"data-svelte-h":!0}),f(gl)!=="svelte-n4f3bu"&&(gl.textContent=bs),Rt=i(l),X.l(l),Fl=i(l),Ql=j(l,"P",{"data-svelte-h":!0}),f(Ql)!=="svelte-krb0ln"&&(Ql.textContent=Ts),Nt=i(l),y(Zl.$$.fragment,l),_t=i(l),Gl=j(l,"P",{"data-svelte-h":!0}),f(Gl)!=="svelte-m6vxkh"&&(Gl.innerHTML=js),Bt=i(l),y(Cl.$$.fragment,l),xt=i(l),Il=j(l,"P",{"data-svelte-h":!0}),f(Il)!=="svelte-1miy94d"&&(Il.innerHTML=hs),Xt=i(l),W.l(l),vl=i(l),kl=j(l,"P",{"data-svelte-h":!0}),f(kl)!=="svelte-1u3htcl"&&(kl.textContent=ws),Vt=i(l),y($l.$$.fragment,l),Wt=i(l),Rl=j(l,"P",{"data-svelte-h":!0}),f(Rl)!=="svelte-pn5dck"&&(Rl.innerHTML=fs),zt=i(l),y(Nl.$$.fragment,l),St=i(l),_l=j(l,"P",{"data-svelte-h":!0}),f(_l)!=="svelte-7650ah"&&(_l.textContent=gs),Yt=i(l),y(Bl.$$.fragment,l),Ft=i(l),y(xl.$$.fragment,l),vt=i(l),Xl=j(l,"P",{"data-svelte-h":!0}),f(Xl)!=="svelte-53boip"&&(Xl.textContent=Qs),Et=i(l),y(Y.$$.fragment,l),At=i(l),El=j(l,"P",{}),Xs(El).forEach(s),this.h()},h(){Al(a,"name","hf:doc:metadata"),Al(a,"content",Me),Al(z,"class","flex justify-center"),Al(N,"border","1"),Al(N,"class","dataframe"),ls(N,"table-layout","fixed"),ls(N,"word-wrap","break-word"),ls(N,"width","100%")},m(l,t){As(document.head,a),e(l,d,t),e(l,n,t),e(l,w,t),u(r,l,t),e(l,c,t),u(G,l,t),e(l,b,t),Vl[Q].m(l,t),e(l,R,t),e(l,k,t),e(l,$,t),u(M,l,t),e(l,g,t),u(F,l,t),e(l,ql,t),e(l,v,t),e(l,Dl,t),e(l,z,t),e(l,Ll,t),u(E,l,t),e(l,Kl,t),e(l,A,t),e(l,Pl,t),u(H,l,t),e(l,Ol,t),u(q,l,t),e(l,lt,t),e(l,D,t),e(l,tt,t),u(L,l,t),e(l,st,t),u(K,l,t),e(l,et,t),e(l,P,t),e(l,at,t),u(O,l,t),e(l,nt,t),u(ll,l,t),e(l,Mt,t),e(l,tl,t),e(l,pt,t),u(sl,l,t),e(l,it,t),e(l,el,t),e(l,rt,t),u(al,l,t),e(l,ot,t),u(nl,l,t),e(l,mt,t),e(l,Ml,t),e(l,dt,t),u(pl,l,t),e(l,ct,t),e(l,N,t),e(l,Ut,t),e(l,il,t),e(l,yt,t),u(rl,l,t),e(l,ut,t),u(ol,l,t),e(l,Jt,t),e(l,ml,t),e(l,bt,t),u(S,l,t),e(l,Tt,t),e(l,dl,t),e(l,jt,t),u(cl,l,t),e(l,ht,t),e(l,Ul,t),e(l,wt,t),u(yl,l,t),e(l,ft,t),u(ul,l,t),e(l,gt,t),e(l,Jl,t),e(l,Qt,t),u(bl,l,t),e(l,Zt,t),e(l,Tl,t),e(l,Gt,t),u(jl,l,t),e(l,Ct,t),e(l,hl,t),e(l,It,t),Wl[_].m(l,t),e(l,Yl,t),e(l,wl,t),e(l,kt,t),u(fl,l,t),e(l,$t,t),e(l,gl,t),e(l,Rt,t),zl[x].m(l,t),e(l,Fl,t),e(l,Ql,t),e(l,Nt,t),u(Zl,l,t),e(l,_t,t),e(l,Gl,t),e(l,Bt,t),u(Cl,l,t),e(l,xt,t),e(l,Il,t),e(l,Xt,t),Sl[V].m(l,t),e(l,vl,t),e(l,kl,t),e(l,Vt,t),u($l,l,t),e(l,Wt,t),e(l,Rl,t),e(l,zt,t),u(Nl,l,t),e(l,St,t),e(l,_l,t),e(l,Yt,t),u(Bl,l,t),e(l,Ft,t),u(xl,l,t),e(l,vt,t),e(l,Xl,t),e(l,Et,t),u(Y,l,t),e(l,At,t),e(l,El,t),Ht=!0},p(l,[t]){const _s={};t&1&&(_s.fw=l[0]),r.$set(_s);let Lt=Q;Q=Gs(l),Q!==Lt&&(Dt(),o(Vl[Lt],1,1,()=>{Vl[Lt]=null}),qt(),Z=Vl[Q],Z||(Z=Vl[Q]=Zs[Q](l),Z.c()),m(Z,1),Z.m(R.parentNode,R));const Bs={};t&2&&(Bs.$$scope={dirty:t,ctx:l}),S.$set(Bs);let Kt=_;_=Is(l),_!==Kt&&(Dt(),o(Wl[Kt],1,1,()=>{Wl[Kt]=null}),qt(),B=Wl[_],B||(B=Wl[_]=Cs[_](l),B.c()),m(B,1),B.m(Yl.parentNode,Yl));let Pt=x;x=$s(l),x!==Pt&&(Dt(),o(zl[Pt],1,1,()=>{zl[Pt]=null}),qt(),X=zl[x],X||(X=zl[x]=ks[x](l),X.c()),m(X,1),X.m(Fl.parentNode,Fl));let Ot=V;V=Ns(l),V!==Ot&&(Dt(),o(Sl[Ot],1,1,()=>{Sl[Ot]=null}),qt(),W=Sl[V],W||(W=Sl[V]=Rs[V](l),W.c()),m(W,1),W.m(vl.parentNode,vl));const xs={};t&2&&(xs.$$scope={dirty:t,ctx:l}),Y.$set(xs)},i(l){Ht||(m(r.$$.fragment,l),m(G.$$.fragment,l),m(Z),m(M.$$.fragment,l),m(F.$$.fragment,l),m(E.$$.fragment,l),m(H.$$.fragment,l),m(q.$$.fragment,l),m(L.$$.fragment,l),m(K.$$.fragment,l),m(O.$$.fragment,l),m(ll.$$.fragment,l),m(sl.$$.fragment,l),m(al.$$.fragment,l),m(nl.$$.fragment,l),m(pl.$$.fragment,l),m(rl.$$.fragment,l),m(ol.$$.fragment,l),m(S.$$.fragment,l),m(cl.$$.fragment,l),m(yl.$$.fragment,l),m(ul.$$.fragment,l),m(bl.$$.fragment,l),m(jl.$$.fragment,l),m(B),m(fl.$$.fragment,l),m(X),m(Zl.$$.fragment,l),m(Cl.$$.fragment,l),m(W),m($l.$$.fragment,l),m(Nl.$$.fragment,l),m(Bl.$$.fragment,l),m(xl.$$.fragment,l),m(Y.$$.fragment,l),Ht=!0)},o(l){o(r.$$.fragment,l),o(G.$$.fragment,l),o(Z),o(M.$$.fragment,l),o(F.$$.fragment,l),o(E.$$.fragment,l),o(H.$$.fragment,l),o(q.$$.fragment,l),o(L.$$.fragment,l),o(K.$$.fragment,l),o(O.$$.fragment,l),o(ll.$$.fragment,l),o(sl.$$.fragment,l),o(al.$$.fragment,l),o(nl.$$.fragment,l),o(pl.$$.fragment,l),o(rl.$$.fragment,l),o(ol.$$.fragment,l),o(S.$$.fragment,l),o(cl.$$.fragment,l),o(yl.$$.fragment,l),o(ul.$$.fragment,l),o(bl.$$.fragment,l),o(jl.$$.fragment,l),o(B),o(fl.$$.fragment,l),o(X),o(Zl.$$.fragment,l),o(Cl.$$.fragment,l),o(W),o($l.$$.fragment,l),o(Nl.$$.fragment,l),o(Bl.$$.fragment,l),o(xl.$$.fragment,l),o(Y.$$.fragment,l),Ht=!1},d(l){l&&(s(d),s(n),s(w),s(c),s(b),s(R),s(k),s($),s(g),s(ql),s(v),s(Dl),s(z),s(Ll),s(Kl),s(A),s(Pl),s(Ol),s(lt),s(D),s(tt),s(st),s(et),s(P),s(at),s(nt),s(Mt),s(tl),s(pt),s(it),s(el),s(rt),s(ot),s(mt),s(Ml),s(dt),s(ct),s(N),s(Ut),s(il),s(yt),s(ut),s(Jt),s(ml),s(bt),s(Tt),s(dl),s(jt),s(ht),s(Ul),s(wt),s(ft),s(gt),s(Jl),s(Qt),s(Zt),s(Tl),s(Gt),s(Ct),s(hl),s(It),s(Yl),s(wl),s(kt),s($t),s(gl),s(Rt),s(Fl),s(Ql),s(Nt),s(_t),s(Gl),s(Bt),s(xt),s(Il),s(Xt),s(vl),s(kl),s(Vt),s(Wt),s(Rl),s(zt),s(St),s(_l),s(Yt),s(Ft),s(vt),s(Xl),s(Et),s(At),s(El)),s(a),J(r,l),J(G,l),Vl[Q].d(l),J(M,l),J(F,l),J(E,l),J(H,l),J(q,l),J(L,l),J(K,l),J(O,l),J(ll,l),J(sl,l),J(al,l),J(nl,l),J(pl,l),J(rl,l),J(ol,l),J(S,l),J(cl,l),J(yl,l),J(ul,l),J(bl,l),J(jl,l),Wl[_].d(l),J(fl,l),zl[x].d(l),J(Zl,l),J(Cl,l),Sl[V].d(l),J($l,l),J(Nl,l),J(Bl,l),J(xl,l),J(Y,l)}}}const Me='{"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 pe(C,a,d){let n="pt";return Ys(()=>{const w=new URLSearchParams(window.location.search);d(0,n=w.get("fw")||"pt")}),[n]}class ue extends Fs{constructor(a){super(),vs(this,a,pe,ne,Ss,{})}}export{ue as component};
