import{s as As,o as Hs,n as vs}from"../chunks/scheduler.37c15a92.js";import{S as qs,i as Ds,g as j,s as p,r as U,A as Ls,h as T,f as s,c as i,j as Ss,u as y,x as f,k as ql,l as as,y as Ks,a as e,v as u,t as o,b as Pt,d as m,w as J,p as Ot}from"../chunks/index.2bf4358c.js";import{T as Fs}from"../chunks/Tip.363c041f.js";import{Y as Ps}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as Es}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as Os}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Dl}from"../chunks/Heading.8ada512a.js";function le(C){let a,d;return a=new Es({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 te(C){let a,d;return a=new Es({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 se(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=j("p"),a.innerHTML=d},l(n){a=T(n,"P",{"data-svelte-h":!0}),f(a)!=="svelte-2evovk"&&(a.innerHTML=d)},m(n,w){e(n,a,w)},p:vs,d(n){n&&s(a)}}}function ee(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=j("p"),n.textContent=w},l(c){y(a.$$.fragment,c),d=i(c),n=T(c,"P",{"data-svelte-h":!0}),f(n)!=="svelte-nhla5d"&&(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 ae(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=j("p"),n.textContent=w,r=p(),U(c.$$.fragment)},l(b){y(a.$$.fragment,b),d=i(b),n=T(b,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1d2qysf"&&(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 ne(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=j("p"),n.textContent=w,r=p(),U(c.$$.fragment),G=p(),U(b.$$.fragment),Q=p(),Z=j("p"),Z.innerHTML=R,k=p(),U(I.$$.fragment)},l(M){y(a.$$.fragment,M),d=i(M),n=T(M,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1b6r3em"&&(n.textContent=w),r=i(M),y(c.$$.fragment,M),G=i(M),y(b.$$.fragment,M),Q=i(M),Z=T(M,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-1cy919j"&&(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 Me(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=j("p"),n.textContent=w,r=p(),U(c.$$.fragment),G=p(),U(b.$$.fragment),Q=p(),Z=j("p"),Z.innerHTML=R,k=p(),U(I.$$.fragment)},l(M){y(a.$$.fragment,M),d=i(M),n=T(M,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1b6r3em"&&(n.textContent=w),r=i(M),y(c.$$.fragment,M),G=i(M),y(b.$$.fragment,M),Q=i(M),Z=T(M,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-1cy919j"&&(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 pe(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 ie(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 re(C){let a,d="✏️  試試看！創建您自己的查詢並查看您是否可以在檢索到的文檔中找到答案。您可能需要增加參數k以擴大搜索範圍。";return{c(){a=j("p"),a.textContent=d},l(n){a=T(n,"P",{"data-svelte-h":!0}),f(a)!=="svelte-q313zk"&&(a.textContent=d)},m(n,w){e(n,a,w)},p:vs,d(n){n&&s(a)}}}function oe(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,Ll,v,ns='正如我們在<a href="/course/chapter1">第一章</a>,學習的, 基於 Transformer 的語言模型會將文本中的每個標記轉換為嵌入向量.事實證明，可以“彙集”各個嵌入向量來創建整個句子、段落或文檔（在某些情況下）的向量表示。然後，通過計算每個嵌入之間的點積相似度（或其他一些相似度度量）並返回相似度最大的文檔，這些嵌入可用於在語料庫中找到相似的文檔。在本節中，我們將使用嵌入來開發語義搜索引擎。與基於將查詢中的關鍵字的傳統方法相比，這些搜索引擎具有多種優勢。',Kl,Y,Ms='<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."/>',Pl,E,Ol,A,ps="我們需要做的第一件事是下載我們的 GitHub 問題數據集，所以讓我們使用 🤗 Hub 庫來解析我們的文件在 Hugging Face Hub 上存儲的數據：",lt,H,tt,q,is='將 URL 存儲在 <strong>data_files</strong> ，然後我們可以使用<a href="/course/chapter5/2">第二小節</a>介紹的方法加載遠程數據集:',st,D,et,L,at,K,rs="這裡我們在load_dataset()中使用了默認的訓練集分割，所以它返回一個數據集而不是數據集字典。第一項任務是過濾掉pull請求，因為這些請求很少用於回答用戶提出的問題，而且會給我們的搜索引擎帶來噪聲。現在應該很熟悉了，我們可以使用dataset.filter()函數來排除數據集中的這些行。同時，讓我們也過濾掉沒有註釋的行，因為這些行不會是用戶提問的答案:",nt,P,Mt,O,pt,ll,os="我們可以看到我們的數據集中有很多列，其中大部分我們不需要構建我們的搜索引擎。從搜索的角度來看，信息量最大的列是 <strong>title</strong> , <strong>body</strong> ， 和 <strong>comments</strong> ，而 <strong>html_url</strong> 為我們提供了一個回到源問題的鏈接。讓我們使用 <strong>Dataset.remove_columns()</strong> 刪除其餘部分的功能：",it,tl,rt,sl,ot,el,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> 格式：',mt,al,dt,nl,ds="如果我們檢查這裡的第一行 <strong>DataFrame</strong> 我們可以看到有四個評論與這個問題相關：",ct,Ml,Ut,pl,yt,il,cs="我們希望這些評論中的每一條都得到一行。讓我們檢查是否是這種情況：",ut,rl,Jt,_,Us='<thead><tr style="text-align: right;"><th></th> <th>html_url</th> <th>title</th> <th>comments</th> <th>body</th></tr></thead> <tbody><tr><th>0</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>the bug code locate in ：\\r\\n    if data_args.task_name is not None...</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr> <tr><th>1</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>Hi @jinec,\\r\\n\\r\\nFrom time to time we get this kind of `ConnectionError` coming from the github.com website: https://raw.githubusercontent.com...</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr> <tr><th>2</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>cannot connect，even by Web browser，please check that  there is some  problems。</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr> <tr><th>3</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>I can access https://raw.githubusercontent.com/huggingface/datasets/1.7.0/datasets/glue/glue.py without problem...</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr></tbody>',bt,ol,ys="太好了，我們可以看到評論成功被擴充， <strong>comments</strong> 是包含個人評論的列！現在我們已經完成了 Pandas要完成的部分功能，我們可以快速切換回 <strong>Dataset</strong> 通過加載 <strong>DataFrame</strong> 在內存中：",jt,ml,Tt,dl,ht,cl,us="太好了，我們獲取到了幾千條的評論！",wt,z,ft,Ul,Js="現在我們每行有一個評論，讓我們創建一個新的 <strong>comments_length</strong> 列來存放每條評論的字數：",gt,yl,Qt,ul,bs="我們可以使用這個新列來過濾掉簡短的評論，其中通常包括“cc @lewtun”或“謝謝！”之類與我們的搜索引擎無關的內容。雖然無法為過濾器選擇的精確數字，但大約大於15 個單詞似乎是一個不錯的選擇：",Zt,Jl,Gt,bl,Ct,jl,js="稍微清理了我們的數據集後，讓我們將問題標題、描述和評論連接到一個新的 <strong>text</strong> 列。像往常一樣，我們可以編寫一個簡單的函數，並將其傳遞給 <strong>Dataset.map()</strong>來做到這些 ：",It,Tl,kt,hl,Ts="我們終於準備好創建一些嵌入了！讓我們來看看。",$t,wl,Rt,fl,hs='我們在<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> 檢查點在語義搜索方面具有最佳性能，因此我們將在我們的應用程序中使用它。我們還將使用相同的檢查點加載標記器：',_t,N,B,vl,gl,ws="正如我們之前提到的，我們希望將 GitHub 問題語料庫中的每個條目表示為單個向量，因此我們需要以某種方式“池化”或平均化我們的標記嵌入。一種流行的方法是在我們模型的輸出上執行CLS 池化，我們只獲取<strong>[CLS]</strong> 令牌的最後一個隱藏狀態。以下函數為我們提供了這樣的方法：",Nt,Ql,Bt,Zl,fs="接下來，我們將創建一個輔助函數，該函數將標記文檔列表，將tensor放在 GPU 上，然後提供給模型，最後對輸出使用CLS 池化：",Xt,X,x,El,Gl,gs="請注意，我們已經將嵌入轉換為 NumPy 數組——這是因為當我們嘗試使用 FAISS 索引它們時，🤗 Datasets需要這種格式，我們接下來會這樣做。",xt,Cl,Vt,Il,Qs='現在我們有了一個詞嵌入數據集，我們需要一些方法來搜索它們。為此，我們將在 🤗 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> 函數並指定我們要索引的數據集的哪一列：',Wt,kl,Yt,$l,Zs="現在，我們可以使用<strong>Dataset.get_nearest_examples()</strong>函數進行最近鄰居查找。讓我們通過首先嵌入一個問題來測試這一點，如下所示：",zt,V,W,Al,Rl,Gs="就像文檔一樣，我們現在有一個 768 維向量表示查詢，我們可以將其與整個語料庫進行比較以找到最相似的嵌入：",St,_l,Ft,Nl,Cs="<strong>Dataset.get_nearest_examples()</strong> 函數返回一個分數元組，對查詢和文檔之間的相似度進行排序，以及一組最佳匹配的結果（這裡是 5 個）。讓我們把這些收集到一個 <strong>pandas.DataFrame</strong> 以便我們可以輕鬆地對它們進行排序：",vt,Bl,Et,Xl,Is="現在我們可以遍歷前幾行來查看我們的查詢與評論的匹配程度：",At,xl,Ht,Vl,qt,Wl,ks="我們的第二個搜索結果似乎與查詢相符。",Dt,S,Lt,Hl,Kt;r=new Os({props:{fw:C[0]}}),G=new Dl({props:{title:"使用 FAISS 進行語義搜索",local:"使用-faiss-進行語義搜索",headingTag:"h1"}});const $s=[te,le],Yl=[];function Rs(l,t){return l[0]==="pt"?0:1}Q=Rs(C),Z=Yl[Q]=$s[Q](C),M=new Ps({props:{id:"OATCgQtNX2o"}}),F=new Dl({props:{title:"使用嵌入進行語義搜索",local:"使用嵌入進行語義搜索",headingTag:"h2"}}),E=new Dl({props:{title:"## 加載和準備數據集",local:"-加載和準備數據集",headingTag:"h2"}}),H=new h({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGhmX2h1Yl91cmwlMEElMEFkYXRhX2ZpbGVzJTIwJTNEJTIwaGZfaHViX3VybCglMEElMjAlMjAlMjAlMjByZXBvX2lkJTNEJTIybGV3dHVuJTJGZ2l0aHViLWlzc3VlcyUyMiUyQyUwQSUyMCUyMCUyMCUyMGZpbGVuYW1lJTNEJTIyZGF0YXNldHMtaXNzdWVzLXdpdGgtY29tbWVudHMuanNvbmwlMjIlMkMlMEElMjAlMjAlMjAlMjByZXBvX3R5cGUlM0QlMjJkYXRhc2V0JTIyJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> hf_hub_url

data_files = hf_hub_url(
    repo_id=<span class="hljs-string">&quot;lewtun/github-issues&quot;</span>,
    filename=<span class="hljs-string">&quot;datasets-issues-with-comments.jsonl&quot;</span>,
    repo_type=<span class="hljs-string">&quot;dataset&quot;</span>,
)`,wrap:!1}}),D=new h({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBaXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyanNvbiUyMiUyQyUyMGRhdGFfZmlsZXMlM0RkYXRhX2ZpbGVzJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiUyMiklMEFpc3N1ZXNfZGF0YXNldA==",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;json&quot;</span>, data_files=data_files, split=<span class="hljs-string">&quot;train&quot;</span>)
issues_dataset`,wrap:!1}}),L=new h({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1Qid1cmwnJTJDJTIwJ3JlcG9zaXRvcnlfdXJsJyUyQyUyMCdsYWJlbHNfdXJsJyUyQyUyMCdjb21tZW50c191cmwnJTJDJTIwJ2V2ZW50c191cmwnJTJDJTIwJ2h0bWxfdXJsJyUyQyUyMCdpZCclMkMlMjAnbm9kZV9pZCclMkMlMjAnbnVtYmVyJyUyQyUyMCd0aXRsZSclMkMlMjAndXNlciclMkMlMjAnbGFiZWxzJyUyQyUyMCdzdGF0ZSclMkMlMjAnbG9ja2VkJyUyQyUyMCdhc3NpZ25lZSclMkMlMjAnYXNzaWduZWVzJyUyQyUyMCdtaWxlc3RvbmUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdjcmVhdGVkX2F0JyUyQyUyMCd1cGRhdGVkX2F0JyUyQyUyMCdjbG9zZWRfYXQnJTJDJTIwJ2F1dGhvcl9hc3NvY2lhdGlvbiclMkMlMjAnYWN0aXZlX2xvY2tfcmVhc29uJyUyQyUyMCdwdWxsX3JlcXVlc3QnJTJDJTIwJ2JvZHknJTJDJTIwJ3BlcmZvcm1lZF92aWFfZ2l0aHViX2FwcCclMkMlMjAnaXNfcHVsbF9yZXF1ZXN0JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMjg1NSUwQSU3RCk=",highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;url&#x27;</span>, <span class="hljs-string">&#x27;repository_url&#x27;</span>, <span class="hljs-string">&#x27;labels_url&#x27;</span>, <span class="hljs-string">&#x27;comments_url&#x27;</span>, <span class="hljs-string">&#x27;events_url&#x27;</span>, <span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;node_id&#x27;</span>, <span class="hljs-string">&#x27;number&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;user&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;state&#x27;</span>, <span class="hljs-string">&#x27;locked&#x27;</span>, <span class="hljs-string">&#x27;assignee&#x27;</span>, <span class="hljs-string">&#x27;assignees&#x27;</span>, <span class="hljs-string">&#x27;milestone&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;created_at&#x27;</span>, <span class="hljs-string">&#x27;updated_at&#x27;</span>, <span class="hljs-string">&#x27;closed_at&#x27;</span>, <span class="hljs-string">&#x27;author_association&#x27;</span>, <span class="hljs-string">&#x27;active_lock_reason&#x27;</span>, <span class="hljs-string">&#x27;pull_request&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>, <span class="hljs-string">&#x27;performed_via_github_app&#x27;</span>, <span class="hljs-string">&#x27;is_pull_request&#x27;</span>],
    num_rows: <span class="hljs-number">2855</span>
})`,wrap:!1}}),P=new h({props:{code:"aXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldC5maWx0ZXIoJTBBJTIwJTIwJTIwJTIwbGFtYmRhJTIweCUzQSUyMCh4JTVCJTIyaXNfcHVsbF9yZXF1ZXN0JTIyJTVEJTIwJTNEJTNEJTIwRmFsc2UlMjBhbmQlMjBsZW4oeCU1QiUyMmNvbW1lbnRzJTIyJTVEKSUyMCUzRSUyMDApJTBBKSUwQWlzc3Vlc19kYXRhc2V0",highlighted:`issues_dataset = issues_dataset.<span class="hljs-built_in">filter</span>(
    <span class="hljs-keyword">lambda</span> x: (x[<span class="hljs-string">&quot;is_pull_request&quot;</span>] == <span class="hljs-literal">False</span> <span class="hljs-keyword">and</span> <span class="hljs-built_in">len</span>(x[<span class="hljs-string">&quot;comments&quot;</span>]) &gt; <span class="hljs-number">0</span>)
)
issues_dataset`,wrap:!1}}),O=new h({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1Qid1cmwnJTJDJTIwJ3JlcG9zaXRvcnlfdXJsJyUyQyUyMCdsYWJlbHNfdXJsJyUyQyUyMCdjb21tZW50c191cmwnJTJDJTIwJ2V2ZW50c191cmwnJTJDJTIwJ2h0bWxfdXJsJyUyQyUyMCdpZCclMkMlMjAnbm9kZV9pZCclMkMlMjAnbnVtYmVyJyUyQyUyMCd0aXRsZSclMkMlMjAndXNlciclMkMlMjAnbGFiZWxzJyUyQyUyMCdzdGF0ZSclMkMlMjAnbG9ja2VkJyUyQyUyMCdhc3NpZ25lZSclMkMlMjAnYXNzaWduZWVzJyUyQyUyMCdtaWxlc3RvbmUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdjcmVhdGVkX2F0JyUyQyUyMCd1cGRhdGVkX2F0JyUyQyUyMCdjbG9zZWRfYXQnJTJDJTIwJ2F1dGhvcl9hc3NvY2lhdGlvbiclMkMlMjAnYWN0aXZlX2xvY2tfcmVhc29uJyUyQyUyMCdwdWxsX3JlcXVlc3QnJTJDJTIwJ2JvZHknJTJDJTIwJ3BlcmZvcm1lZF92aWFfZ2l0aHViX2FwcCclMkMlMjAnaXNfcHVsbF9yZXF1ZXN0JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNzcxJTBBJTdEKQ==",highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;url&#x27;</span>, <span class="hljs-string">&#x27;repository_url&#x27;</span>, <span class="hljs-string">&#x27;labels_url&#x27;</span>, <span class="hljs-string">&#x27;comments_url&#x27;</span>, <span class="hljs-string">&#x27;events_url&#x27;</span>, <span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;node_id&#x27;</span>, <span class="hljs-string">&#x27;number&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;user&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;state&#x27;</span>, <span class="hljs-string">&#x27;locked&#x27;</span>, <span class="hljs-string">&#x27;assignee&#x27;</span>, <span class="hljs-string">&#x27;assignees&#x27;</span>, <span class="hljs-string">&#x27;milestone&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;created_at&#x27;</span>, <span class="hljs-string">&#x27;updated_at&#x27;</span>, <span class="hljs-string">&#x27;closed_at&#x27;</span>, <span class="hljs-string">&#x27;author_association&#x27;</span>, <span class="hljs-string">&#x27;active_lock_reason&#x27;</span>, <span class="hljs-string">&#x27;pull_request&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>, <span class="hljs-string">&#x27;performed_via_github_app&#x27;</span>, <span class="hljs-string">&#x27;is_pull_request&#x27;</span>],
    num_rows: <span class="hljs-number">771</span>
})`,wrap:!1}}),tl=new h({props:{code:"Y29sdW1ucyUyMCUzRCUyMGlzc3Vlc19kYXRhc2V0LmNvbHVtbl9uYW1lcyUwQWNvbHVtbnNfdG9fa2VlcCUyMCUzRCUyMCU1QiUyMnRpdGxlJTIyJTJDJTIwJTIyYm9keSUyMiUyQyUyMCUyMmh0bWxfdXJsJTIyJTJDJTIwJTIyY29tbWVudHMlMjIlNUQlMEFjb2x1bW5zX3RvX3JlbW92ZSUyMCUzRCUyMHNldChjb2x1bW5zX3RvX2tlZXApLnN5bW1ldHJpY19kaWZmZXJlbmNlKGNvbHVtbnMpJTBBaXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldC5yZW1vdmVfY29sdW1ucyhjb2x1bW5zX3RvX3JlbW92ZSklMEFpc3N1ZXNfZGF0YXNldA==",highlighted:`columns = issues_dataset.column_names
columns_to_keep = [<span class="hljs-string">&quot;title&quot;</span>, <span class="hljs-string">&quot;body&quot;</span>, <span class="hljs-string">&quot;html_url&quot;</span>, <span class="hljs-string">&quot;comments&quot;</span>]
columns_to_remove = <span class="hljs-built_in">set</span>(columns_to_keep).symmetric_difference(columns)
issues_dataset = issues_dataset.remove_columns(columns_to_remove)
issues_dataset`,wrap:!1}}),sl=new h({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidodG1sX3VybCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdib2R5JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNzcxJTBBJTdEKQ==",highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>],
    num_rows: <span class="hljs-number">771</span>
})`,wrap:!1}}),al=new h({props:{code:"aXNzdWVzX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJwYW5kYXMlMjIpJTBBZGYlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldCU1QiUzQSU1RA==",highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`,wrap:!1}}),Ml=new h({props:{code:"ZGYlNUIlMjJjb21tZW50cyUyMiU1RCU1QjAlNUQudG9saXN0KCk=",highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()',wrap:!1}}),pl=new h({props:{code:"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}}),rl=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}}),ml=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}}),dl=new h({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidodG1sX3VybCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdib2R5JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMjg0MiUwQSU3RCk=",highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>],
    num_rows: <span class="hljs-number">2842</span>
})`,wrap:!1}}),z=new Fs({props:{$$slots:{default:[se]},$$scope:{ctx:C}}}),yl=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}}),Jl=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}}),bl=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}}),Tl=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}}),wl=new Dl({props:{title:"創建文本嵌入",local:"創建文本嵌入",headingTag:"h2"}});const _s=[ae,ee],zl=[];function Ns(l,t){return l[0]==="pt"?0:1}N=Ns(C),B=zl[N]=_s[N](C),Ql=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 Bs=[Me,ne],Sl=[];function Xs(l,t){return l[0]==="pt"?0:1}X=Xs(C),x=Sl[X]=Bs[X](C),Cl=new Dl({props:{title:"使用 FAISS 進行高效的相似性搜索",local:"使用-faiss-進行高效的相似性搜索",headingTag:"h2"}}),kl=new h({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0LmFkZF9mYWlzc19pbmRleChjb2x1bW4lM0QlMjJlbWJlZGRpbmdzJTIyKQ==",highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)',wrap:!1}});const xs=[ie,pe],Fl=[];function Vs(l,t){return l[0]==="pt"?0:1}return V=Vs(C),W=Fl[V]=xs[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}}),Bl=new h({props:{code:"aW1wb3J0JTIwcGFuZGFzJTIwYXMlMjBwZCUwQSUwQXNhbXBsZXNfZGYlMjAlM0QlMjBwZC5EYXRhRnJhbWUuZnJvbV9kaWN0KHNhbXBsZXMpJTBBc2FtcGxlc19kZiU1QiUyMnNjb3JlcyUyMiU1RCUyMCUzRCUyMHNjb3JlcyUwQXNhbXBsZXNfZGYuc29ydF92YWx1ZXMoJTIyc2NvcmVzJTIyJTJDJTIwYXNjZW5kaW5nJTNERmFsc2UlMkMlMjBpbnBsYWNlJTNEVHJ1ZSk=",highlighted:`<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd

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

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

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

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

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

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

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

----------

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

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

----------

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

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


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

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

HTH.
SCORE: 22.406635284423828
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================
&quot;&quot;&quot;</span>`,wrap:!1}}),S=new Fs({props:{$$slots:{default:[re]},$$scope:{ctx:C}}}),{c(){a=j("meta"),d=p(),n=j("p"),w=p(),U(r.$$.fragment),c=p(),U(G.$$.fragment),b=p(),Z.c(),R=p(),k=j("p"),k.innerHTML=I,$=p(),U(M.$$.fragment),g=p(),U(F.$$.fragment),Ll=p(),v=j("p"),v.innerHTML=ns,Kl=p(),Y=j("div"),Y.innerHTML=Ms,Pl=p(),U(E.$$.fragment),Ol=p(),A=j("p"),A.textContent=ps,lt=p(),U(H.$$.fragment),tt=p(),q=j("p"),q.innerHTML=is,st=p(),U(D.$$.fragment),et=p(),U(L.$$.fragment),at=p(),K=j("p"),K.textContent=rs,nt=p(),U(P.$$.fragment),Mt=p(),U(O.$$.fragment),pt=p(),ll=j("p"),ll.innerHTML=os,it=p(),U(tl.$$.fragment),rt=p(),U(sl.$$.fragment),ot=p(),el=j("p"),el.innerHTML=ms,mt=p(),U(al.$$.fragment),dt=p(),nl=j("p"),nl.innerHTML=ds,ct=p(),U(Ml.$$.fragment),Ut=p(),U(pl.$$.fragment),yt=p(),il=j("p"),il.textContent=cs,ut=p(),U(rl.$$.fragment),Jt=p(),_=j("table"),_.innerHTML=Us,bt=p(),ol=j("p"),ol.innerHTML=ys,jt=p(),U(ml.$$.fragment),Tt=p(),U(dl.$$.fragment),ht=p(),cl=j("p"),cl.textContent=us,wt=p(),U(z.$$.fragment),ft=p(),Ul=j("p"),Ul.innerHTML=Js,gt=p(),U(yl.$$.fragment),Qt=p(),ul=j("p"),ul.textContent=bs,Zt=p(),U(Jl.$$.fragment),Gt=p(),U(bl.$$.fragment),Ct=p(),jl=j("p"),jl.innerHTML=js,It=p(),U(Tl.$$.fragment),kt=p(),hl=j("p"),hl.textContent=Ts,$t=p(),U(wl.$$.fragment),Rt=p(),fl=j("p"),fl.innerHTML=hs,_t=p(),B.c(),vl=p(),gl=j("p"),gl.innerHTML=ws,Nt=p(),U(Ql.$$.fragment),Bt=p(),Zl=j("p"),Zl.textContent=fs,Xt=p(),x.c(),El=p(),Gl=j("p"),Gl.textContent=gs,xt=p(),U(Cl.$$.fragment),Vt=p(),Il=j("p"),Il.innerHTML=Qs,Wt=p(),U(kl.$$.fragment),Yt=p(),$l=j("p"),$l.innerHTML=Zs,zt=p(),W.c(),Al=p(),Rl=j("p"),Rl.textContent=Gs,St=p(),U(_l.$$.fragment),Ft=p(),Nl=j("p"),Nl.innerHTML=Cs,vt=p(),U(Bl.$$.fragment),Et=p(),Xl=j("p"),Xl.textContent=Is,At=p(),U(xl.$$.fragment),Ht=p(),U(Vl.$$.fragment),qt=p(),Wl=j("p"),Wl.textContent=ks,Dt=p(),U(S.$$.fragment),Lt=p(),Hl=j("p"),this.h()},l(l){const t=Ls("svelte-u9bgzb",document.head);a=T(t,"META",{name:!0,content:!0}),t.forEach(s),d=i(l),n=T(l,"P",{}),Ss(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=T(l,"P",{"data-svelte-h":!0}),f(k)!=="svelte-16td694"&&(k.innerHTML=I),$=i(l),y(M.$$.fragment,l),g=i(l),y(F.$$.fragment,l),Ll=i(l),v=T(l,"P",{"data-svelte-h":!0}),f(v)!=="svelte-1ouft5c"&&(v.innerHTML=ns),Kl=i(l),Y=T(l,"DIV",{class:!0,"data-svelte-h":!0}),f(Y)!=="svelte-yxatr"&&(Y.innerHTML=Ms),Pl=i(l),y(E.$$.fragment,l),Ol=i(l),A=T(l,"P",{"data-svelte-h":!0}),f(A)!=="svelte-1h82ukm"&&(A.textContent=ps),lt=i(l),y(H.$$.fragment,l),tt=i(l),q=T(l,"P",{"data-svelte-h":!0}),f(q)!=="svelte-zhf6a8"&&(q.innerHTML=is),st=i(l),y(D.$$.fragment,l),et=i(l),y(L.$$.fragment,l),at=i(l),K=T(l,"P",{"data-svelte-h":!0}),f(K)!=="svelte-1php4kr"&&(K.textContent=rs),nt=i(l),y(P.$$.fragment,l),Mt=i(l),y(O.$$.fragment,l),pt=i(l),ll=T(l,"P",{"data-svelte-h":!0}),f(ll)!=="svelte-1q1cceu"&&(ll.innerHTML=os),it=i(l),y(tl.$$.fragment,l),rt=i(l),y(sl.$$.fragment,l),ot=i(l),el=T(l,"P",{"data-svelte-h":!0}),f(el)!=="svelte-14sury5"&&(el.innerHTML=ms),mt=i(l),y(al.$$.fragment,l),dt=i(l),nl=T(l,"P",{"data-svelte-h":!0}),f(nl)!=="svelte-iga3vw"&&(nl.innerHTML=ds),ct=i(l),y(Ml.$$.fragment,l),Ut=i(l),y(pl.$$.fragment,l),yt=i(l),il=T(l,"P",{"data-svelte-h":!0}),f(il)!=="svelte-1pb3joc"&&(il.textContent=cs),ut=i(l),y(rl.$$.fragment,l),Jt=i(l),_=T(l,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),f(_)!=="svelte-1g5whzd"&&(_.innerHTML=Us),bt=i(l),ol=T(l,"P",{"data-svelte-h":!0}),f(ol)!=="svelte-1xrq2dz"&&(ol.innerHTML=ys),jt=i(l),y(ml.$$.fragment,l),Tt=i(l),y(dl.$$.fragment,l),ht=i(l),cl=T(l,"P",{"data-svelte-h":!0}),f(cl)!=="svelte-6emjl9"&&(cl.textContent=us),wt=i(l),y(z.$$.fragment,l),ft=i(l),Ul=T(l,"P",{"data-svelte-h":!0}),f(Ul)!=="svelte-1yzzxu8"&&(Ul.innerHTML=Js),gt=i(l),y(yl.$$.fragment,l),Qt=i(l),ul=T(l,"P",{"data-svelte-h":!0}),f(ul)!=="svelte-tcffwa"&&(ul.textContent=bs),Zt=i(l),y(Jl.$$.fragment,l),Gt=i(l),y(bl.$$.fragment,l),Ct=i(l),jl=T(l,"P",{"data-svelte-h":!0}),f(jl)!=="svelte-buzo4l"&&(jl.innerHTML=js),It=i(l),y(Tl.$$.fragment,l),kt=i(l),hl=T(l,"P",{"data-svelte-h":!0}),f(hl)!=="svelte-1y63gjj"&&(hl.textContent=Ts),$t=i(l),y(wl.$$.fragment,l),Rt=i(l),fl=T(l,"P",{"data-svelte-h":!0}),f(fl)!=="svelte-upj4ig"&&(fl.innerHTML=hs),_t=i(l),B.l(l),vl=i(l),gl=T(l,"P",{"data-svelte-h":!0}),f(gl)!=="svelte-1b0ajk1"&&(gl.innerHTML=ws),Nt=i(l),y(Ql.$$.fragment,l),Bt=i(l),Zl=T(l,"P",{"data-svelte-h":!0}),f(Zl)!=="svelte-1t3irc7"&&(Zl.textContent=fs),Xt=i(l),x.l(l),El=i(l),Gl=T(l,"P",{"data-svelte-h":!0}),f(Gl)!=="svelte-1h428t9"&&(Gl.textContent=gs),xt=i(l),y(Cl.$$.fragment,l),Vt=i(l),Il=T(l,"P",{"data-svelte-h":!0}),f(Il)!=="svelte-wi1ka2"&&(Il.innerHTML=Qs),Wt=i(l),y(kl.$$.fragment,l),Yt=i(l),$l=T(l,"P",{"data-svelte-h":!0}),f($l)!=="svelte-xc3fim"&&($l.innerHTML=Zs),zt=i(l),W.l(l),Al=i(l),Rl=T(l,"P",{"data-svelte-h":!0}),f(Rl)!=="svelte-uh106h"&&(Rl.textContent=Gs),St=i(l),y(_l.$$.fragment,l),Ft=i(l),Nl=T(l,"P",{"data-svelte-h":!0}),f(Nl)!=="svelte-1jt92rg"&&(Nl.innerHTML=Cs),vt=i(l),y(Bl.$$.fragment,l),Et=i(l),Xl=T(l,"P",{"data-svelte-h":!0}),f(Xl)!=="svelte-1shxrgp"&&(Xl.textContent=Is),At=i(l),y(xl.$$.fragment,l),Ht=i(l),y(Vl.$$.fragment,l),qt=i(l),Wl=T(l,"P",{"data-svelte-h":!0}),f(Wl)!=="svelte-1wb9z77"&&(Wl.textContent=ks),Dt=i(l),y(S.$$.fragment,l),Lt=i(l),Hl=T(l,"P",{}),Ss(Hl).forEach(s),this.h()},h(){ql(a,"name","hf:doc:metadata"),ql(a,"content",me),ql(Y,"class","flex justify-center"),ql(_,"border","1"),ql(_,"class","dataframe"),as(_,"table-layout","fixed"),as(_,"word-wrap","break-word"),as(_,"width","100%")},m(l,t){Ks(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),Yl[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,Ll,t),e(l,v,t),e(l,Kl,t),e(l,Y,t),e(l,Pl,t),u(E,l,t),e(l,Ol,t),e(l,A,t),e(l,lt,t),u(H,l,t),e(l,tt,t),e(l,q,t),e(l,st,t),u(D,l,t),e(l,et,t),u(L,l,t),e(l,at,t),e(l,K,t),e(l,nt,t),u(P,l,t),e(l,Mt,t),u(O,l,t),e(l,pt,t),e(l,ll,t),e(l,it,t),u(tl,l,t),e(l,rt,t),u(sl,l,t),e(l,ot,t),e(l,el,t),e(l,mt,t),u(al,l,t),e(l,dt,t),e(l,nl,t),e(l,ct,t),u(Ml,l,t),e(l,Ut,t),u(pl,l,t),e(l,yt,t),e(l,il,t),e(l,ut,t),u(rl,l,t),e(l,Jt,t),e(l,_,t),e(l,bt,t),e(l,ol,t),e(l,jt,t),u(ml,l,t),e(l,Tt,t),u(dl,l,t),e(l,ht,t),e(l,cl,t),e(l,wt,t),u(z,l,t),e(l,ft,t),e(l,Ul,t),e(l,gt,t),u(yl,l,t),e(l,Qt,t),e(l,ul,t),e(l,Zt,t),u(Jl,l,t),e(l,Gt,t),u(bl,l,t),e(l,Ct,t),e(l,jl,t),e(l,It,t),u(Tl,l,t),e(l,kt,t),e(l,hl,t),e(l,$t,t),u(wl,l,t),e(l,Rt,t),e(l,fl,t),e(l,_t,t),zl[N].m(l,t),e(l,vl,t),e(l,gl,t),e(l,Nt,t),u(Ql,l,t),e(l,Bt,t),e(l,Zl,t),e(l,Xt,t),Sl[X].m(l,t),e(l,El,t),e(l,Gl,t),e(l,xt,t),u(Cl,l,t),e(l,Vt,t),e(l,Il,t),e(l,Wt,t),u(kl,l,t),e(l,Yt,t),e(l,$l,t),e(l,zt,t),Fl[V].m(l,t),e(l,Al,t),e(l,Rl,t),e(l,St,t),u(_l,l,t),e(l,Ft,t),e(l,Nl,t),e(l,vt,t),u(Bl,l,t),e(l,Et,t),e(l,Xl,t),e(l,At,t),u(xl,l,t),e(l,Ht,t),u(Vl,l,t),e(l,qt,t),e(l,Wl,t),e(l,Dt,t),u(S,l,t),e(l,Lt,t),e(l,Hl,t),Kt=!0},p(l,[t]){const Ws={};t&1&&(Ws.fw=l[0]),r.$set(Ws);let ls=Q;Q=Rs(l),Q!==ls&&(Ot(),o(Yl[ls],1,1,()=>{Yl[ls]=null}),Pt(),Z=Yl[Q],Z||(Z=Yl[Q]=$s[Q](l),Z.c()),m(Z,1),Z.m(R.parentNode,R));const Ys={};t&2&&(Ys.$$scope={dirty:t,ctx:l}),z.$set(Ys);let ts=N;N=Ns(l),N!==ts&&(Ot(),o(zl[ts],1,1,()=>{zl[ts]=null}),Pt(),B=zl[N],B||(B=zl[N]=_s[N](l),B.c()),m(B,1),B.m(vl.parentNode,vl));let ss=X;X=Xs(l),X!==ss&&(Ot(),o(Sl[ss],1,1,()=>{Sl[ss]=null}),Pt(),x=Sl[X],x||(x=Sl[X]=Bs[X](l),x.c()),m(x,1),x.m(El.parentNode,El));let es=V;V=Vs(l),V!==es&&(Ot(),o(Fl[es],1,1,()=>{Fl[es]=null}),Pt(),W=Fl[V],W||(W=Fl[V]=xs[V](l),W.c()),m(W,1),W.m(Al.parentNode,Al));const zs={};t&2&&(zs.$$scope={dirty:t,ctx:l}),S.$set(zs)},i(l){Kt||(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(D.$$.fragment,l),m(L.$$.fragment,l),m(P.$$.fragment,l),m(O.$$.fragment,l),m(tl.$$.fragment,l),m(sl.$$.fragment,l),m(al.$$.fragment,l),m(Ml.$$.fragment,l),m(pl.$$.fragment,l),m(rl.$$.fragment,l),m(ml.$$.fragment,l),m(dl.$$.fragment,l),m(z.$$.fragment,l),m(yl.$$.fragment,l),m(Jl.$$.fragment,l),m(bl.$$.fragment,l),m(Tl.$$.fragment,l),m(wl.$$.fragment,l),m(B),m(Ql.$$.fragment,l),m(x),m(Cl.$$.fragment,l),m(kl.$$.fragment,l),m(W),m(_l.$$.fragment,l),m(Bl.$$.fragment,l),m(xl.$$.fragment,l),m(Vl.$$.fragment,l),m(S.$$.fragment,l),Kt=!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(D.$$.fragment,l),o(L.$$.fragment,l),o(P.$$.fragment,l),o(O.$$.fragment,l),o(tl.$$.fragment,l),o(sl.$$.fragment,l),o(al.$$.fragment,l),o(Ml.$$.fragment,l),o(pl.$$.fragment,l),o(rl.$$.fragment,l),o(ml.$$.fragment,l),o(dl.$$.fragment,l),o(z.$$.fragment,l),o(yl.$$.fragment,l),o(Jl.$$.fragment,l),o(bl.$$.fragment,l),o(Tl.$$.fragment,l),o(wl.$$.fragment,l),o(B),o(Ql.$$.fragment,l),o(x),o(Cl.$$.fragment,l),o(kl.$$.fragment,l),o(W),o(_l.$$.fragment,l),o(Bl.$$.fragment,l),o(xl.$$.fragment,l),o(Vl.$$.fragment,l),o(S.$$.fragment,l),Kt=!1},d(l){l&&(s(d),s(n),s(w),s(c),s(b),s(R),s(k),s($),s(g),s(Ll),s(v),s(Kl),s(Y),s(Pl),s(Ol),s(A),s(lt),s(tt),s(q),s(st),s(et),s(at),s(K),s(nt),s(Mt),s(pt),s(ll),s(it),s(rt),s(ot),s(el),s(mt),s(dt),s(nl),s(ct),s(Ut),s(yt),s(il),s(ut),s(Jt),s(_),s(bt),s(ol),s(jt),s(Tt),s(ht),s(cl),s(wt),s(ft),s(Ul),s(gt),s(Qt),s(ul),s(Zt),s(Gt),s(Ct),s(jl),s(It),s(kt),s(hl),s($t),s(Rt),s(fl),s(_t),s(vl),s(gl),s(Nt),s(Bt),s(Zl),s(Xt),s(El),s(Gl),s(xt),s(Vt),s(Il),s(Wt),s(Yt),s($l),s(zt),s(Al),s(Rl),s(St),s(Ft),s(Nl),s(vt),s(Et),s(Xl),s(At),s(Ht),s(qt),s(Wl),s(Dt),s(Lt),s(Hl)),s(a),J(r,l),J(G,l),Yl[Q].d(l),J(M,l),J(F,l),J(E,l),J(H,l),J(D,l),J(L,l),J(P,l),J(O,l),J(tl,l),J(sl,l),J(al,l),J(Ml,l),J(pl,l),J(rl,l),J(ml,l),J(dl,l),J(z,l),J(yl,l),J(Jl,l),J(bl,l),J(Tl,l),J(wl,l),zl[N].d(l),J(Ql,l),Sl[X].d(l),J(Cl,l),J(kl,l),Fl[V].d(l),J(_l,l),J(Bl,l),J(xl,l),J(Vl,l),J(S,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 de(C,a,d){let n="pt";return Hs(()=>{const w=new URLSearchParams(window.location.search);d(0,n=w.get("fw")||"pt")}),[n]}class he extends qs{constructor(a){super(),Ds(this,a,de,oe,As,{})}}export{he as component};
