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