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

comments_dataset = Dataset.from_pandas(comments_df)
comments_dataset`,wrap:!1}}),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}}),Y=new Es({props:{$$slots:{default:[ne]},$$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 Ll({props:{title:"創建文本嵌入",local:"創建文本嵌入",headingTag:"h2"}});const Bs=[pe,Me],Sl=[];function Xs(l,t){return l[0]==="pt"?0:1}N=Xs(C),B=Sl[N]=Bs[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 xs=[re,ie],Fl=[];function Vs(l,t){return l[0]==="pt"?0:1}X=Vs(C),x=Fl[X]=xs[X](C),Cl=new Ll({props:{title:"使用 FAISS 進行高效的相似性搜索",local:"使用-faiss-進行高效的相似性搜索",headingTag:"h2"}}),$l=new h({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0LmFkZF9mYWlzc19pbmRleChjb2x1bW4lM0QlMjJlbWJlZGRpbmdzJTIyKQ==",highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)',wrap:!1}});const Ws=[oe,me],vl=[];function zs(l,t){return l[0]==="pt"?0:1}return V=zs(C),W=vl[V]=Ws[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 Es({props:{$$slots:{default:[de]},$$scope:{ctx:C}}}),zl=new se({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter5/6.mdx"}}),{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(),$=j("p"),$.innerHTML=I,k=p(),U(M.$$.fragment),g=p(),U(F.$$.fragment),Kl=p(),v=j("p"),v.innerHTML=ps,Pl=p(),z=j("div"),z.innerHTML=is,Ol=p(),U(E.$$.fragment),lt=p(),A=j("p"),A.textContent=rs,tt=p(),U(H.$$.fragment),st=p(),q=j("p"),q.innerHTML=ms,et=p(),U(D.$$.fragment),at=p(),U(L.$$.fragment),nt=p(),K=j("p"),K.textContent=os,Mt=p(),U(P.$$.fragment),pt=p(),U(O.$$.fragment),it=p(),ll=j("p"),ll.innerHTML=ds,rt=p(),U(tl.$$.fragment),mt=p(),U(sl.$$.fragment),ot=p(),el=j("p"),el.innerHTML=cs,dt=p(),U(al.$$.fragment),ct=p(),nl=j("p"),nl.innerHTML=Us,Ut=p(),U(Ml.$$.fragment),yt=p(),U(pl.$$.fragment),ut=p(),il=j("p"),il.textContent=ys,Jt=p(),U(rl.$$.fragment),bt=p(),_=j("table"),_.innerHTML=us,jt=p(),ml=j("p"),ml.innerHTML=Js,Tt=p(),U(ol.$$.fragment),ht=p(),U(dl.$$.fragment),wt=p(),cl=j("p"),cl.textContent=bs,ft=p(),U(Y.$$.fragment),gt=p(),Ul=j("p"),Ul.innerHTML=js,Qt=p(),U(yl.$$.fragment),Zt=p(),ul=j("p"),ul.textContent=Ts,Gt=p(),U(Jl.$$.fragment),Ct=p(),U(bl.$$.fragment),It=p(),jl=j("p"),jl.innerHTML=hs,$t=p(),U(Tl.$$.fragment),kt=p(),hl=j("p"),hl.textContent=ws,Rt=p(),U(wl.$$.fragment),_t=p(),fl=j("p"),fl.innerHTML=fs,Nt=p(),B.c(),El=p(),gl=j("p"),gl.innerHTML=gs,Bt=p(),U(Ql.$$.fragment),Xt=p(),Zl=j("p"),Zl.textContent=Qs,xt=p(),x.c(),Al=p(),Gl=j("p"),Gl.textContent=Zs,Vt=p(),U(Cl.$$.fragment),Wt=p(),Il=j("p"),Il.innerHTML=Gs,zt=p(),U($l.$$.fragment),Yt=p(),kl=j("p"),kl.innerHTML=Cs,St=p(),W.c(),Hl=p(),Rl=j("p"),Rl.textContent=Is,Ft=p(),U(_l.$$.fragment),vt=p(),Nl=j("p"),Nl.innerHTML=$s,Et=p(),U(Bl.$$.fragment),At=p(),Xl=j("p"),Xl.textContent=ks,Ht=p(),U(xl.$$.fragment),qt=p(),U(Vl.$$.fragment),Dt=p(),Wl=j("p"),Wl.textContent=Rs,Lt=p(),U(S.$$.fragment),Kt=p(),U(zl.$$.fragment),Pt=p(),ql=j("p"),this.h()},l(l){const t=Ps("svelte-u9bgzb",document.head);a=T(t,"META",{name:!0,content:!0}),t.forEach(s),d=i(l),n=T(l,"P",{}),vs(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),$=T(l,"P",{"data-svelte-h":!0}),f($)!=="svelte-16td694"&&($.innerHTML=I),k=i(l),y(M.$$.fragment,l),g=i(l),y(F.$$.fragment,l),Kl=i(l),v=T(l,"P",{"data-svelte-h":!0}),f(v)!=="svelte-1ouft5c"&&(v.innerHTML=ps),Pl=i(l),z=T(l,"DIV",{class:!0,"data-svelte-h":!0}),f(z)!=="svelte-yxatr"&&(z.innerHTML=is),Ol=i(l),y(E.$$.fragment,l),lt=i(l),A=T(l,"P",{"data-svelte-h":!0}),f(A)!=="svelte-1h82ukm"&&(A.textContent=rs),tt=i(l),y(H.$$.fragment,l),st=i(l),q=T(l,"P",{"data-svelte-h":!0}),f(q)!=="svelte-zhf6a8"&&(q.innerHTML=ms),et=i(l),y(D.$$.fragment,l),at=i(l),y(L.$$.fragment,l),nt=i(l),K=T(l,"P",{"data-svelte-h":!0}),f(K)!=="svelte-1php4kr"&&(K.textContent=os),Mt=i(l),y(P.$$.fragment,l),pt=i(l),y(O.$$.fragment,l),it=i(l),ll=T(l,"P",{"data-svelte-h":!0}),f(ll)!=="svelte-1q1cceu"&&(ll.innerHTML=ds),rt=i(l),y(tl.$$.fragment,l),mt=i(l),y(sl.$$.fragment,l),ot=i(l),el=T(l,"P",{"data-svelte-h":!0}),f(el)!=="svelte-14sury5"&&(el.innerHTML=cs),dt=i(l),y(al.$$.fragment,l),ct=i(l),nl=T(l,"P",{"data-svelte-h":!0}),f(nl)!=="svelte-iga3vw"&&(nl.innerHTML=Us),Ut=i(l),y(Ml.$$.fragment,l),yt=i(l),y(pl.$$.fragment,l),ut=i(l),il=T(l,"P",{"data-svelte-h":!0}),f(il)!=="svelte-1pb3joc"&&(il.textContent=ys),Jt=i(l),y(rl.$$.fragment,l),bt=i(l),_=T(l,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),f(_)!=="svelte-1g5whzd"&&(_.innerHTML=us),jt=i(l),ml=T(l,"P",{"data-svelte-h":!0}),f(ml)!=="svelte-1xrq2dz"&&(ml.innerHTML=Js),Tt=i(l),y(ol.$$.fragment,l),ht=i(l),y(dl.$$.fragment,l),wt=i(l),cl=T(l,"P",{"data-svelte-h":!0}),f(cl)!=="svelte-6emjl9"&&(cl.textContent=bs),ft=i(l),y(Y.$$.fragment,l),gt=i(l),Ul=T(l,"P",{"data-svelte-h":!0}),f(Ul)!=="svelte-1yzzxu8"&&(Ul.innerHTML=js),Qt=i(l),y(yl.$$.fragment,l),Zt=i(l),ul=T(l,"P",{"data-svelte-h":!0}),f(ul)!=="svelte-tcffwa"&&(ul.textContent=Ts),Gt=i(l),y(Jl.$$.fragment,l),Ct=i(l),y(bl.$$.fragment,l),It=i(l),jl=T(l,"P",{"data-svelte-h":!0}),f(jl)!=="svelte-buzo4l"&&(jl.innerHTML=hs),$t=i(l),y(Tl.$$.fragment,l),kt=i(l),hl=T(l,"P",{"data-svelte-h":!0}),f(hl)!=="svelte-1y63gjj"&&(hl.textContent=ws),Rt=i(l),y(wl.$$.fragment,l),_t=i(l),fl=T(l,"P",{"data-svelte-h":!0}),f(fl)!=="svelte-upj4ig"&&(fl.innerHTML=fs),Nt=i(l),B.l(l),El=i(l),gl=T(l,"P",{"data-svelte-h":!0}),f(gl)!=="svelte-1b0ajk1"&&(gl.innerHTML=gs),Bt=i(l),y(Ql.$$.fragment,l),Xt=i(l),Zl=T(l,"P",{"data-svelte-h":!0}),f(Zl)!=="svelte-1t3irc7"&&(Zl.textContent=Qs),xt=i(l),x.l(l),Al=i(l),Gl=T(l,"P",{"data-svelte-h":!0}),f(Gl)!=="svelte-1h428t9"&&(Gl.textContent=Zs),Vt=i(l),y(Cl.$$.fragment,l),Wt=i(l),Il=T(l,"P",{"data-svelte-h":!0}),f(Il)!=="svelte-wi1ka2"&&(Il.innerHTML=Gs),zt=i(l),y($l.$$.fragment,l),Yt=i(l),kl=T(l,"P",{"data-svelte-h":!0}),f(kl)!=="svelte-xc3fim"&&(kl.innerHTML=Cs),St=i(l),W.l(l),Hl=i(l),Rl=T(l,"P",{"data-svelte-h":!0}),f(Rl)!=="svelte-uh106h"&&(Rl.textContent=Is),Ft=i(l),y(_l.$$.fragment,l),vt=i(l),Nl=T(l,"P",{"data-svelte-h":!0}),f(Nl)!=="svelte-1jt92rg"&&(Nl.innerHTML=$s),Et=i(l),y(Bl.$$.fragment,l),At=i(l),Xl=T(l,"P",{"data-svelte-h":!0}),f(Xl)!=="svelte-1shxrgp"&&(Xl.textContent=ks),Ht=i(l),y(xl.$$.fragment,l),qt=i(l),y(Vl.$$.fragment,l),Dt=i(l),Wl=T(l,"P",{"data-svelte-h":!0}),f(Wl)!=="svelte-1wb9z77"&&(Wl.textContent=Rs),Lt=i(l),y(S.$$.fragment,l),Kt=i(l),y(zl.$$.fragment,l),Pt=i(l),ql=T(l,"P",{}),vs(ql).forEach(s),this.h()},h(){Dl(a,"name","hf:doc:metadata"),Dl(a,"content",Ue),Dl(z,"class","flex justify-center"),Dl(_,"border","1"),Dl(_,"class","dataframe"),Ms(_,"table-layout","fixed"),Ms(_,"word-wrap","break-word"),Ms(_,"width","100%")},m(l,t){Os(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,$,t),e(l,k,t),u(M,l,t),e(l,g,t),u(F,l,t),e(l,Kl,t),e(l,v,t),e(l,Pl,t),e(l,z,t),e(l,Ol,t),u(E,l,t),e(l,lt,t),e(l,A,t),e(l,tt,t),u(H,l,t),e(l,st,t),e(l,q,t),e(l,et,t),u(D,l,t),e(l,at,t),u(L,l,t),e(l,nt,t),e(l,K,t),e(l,Mt,t),u(P,l,t),e(l,pt,t),u(O,l,t),e(l,it,t),e(l,ll,t),e(l,rt,t),u(tl,l,t),e(l,mt,t),u(sl,l,t),e(l,ot,t),e(l,el,t),e(l,dt,t),u(al,l,t),e(l,ct,t),e(l,nl,t),e(l,Ut,t),u(Ml,l,t),e(l,yt,t),u(pl,l,t),e(l,ut,t),e(l,il,t),e(l,Jt,t),u(rl,l,t),e(l,bt,t),e(l,_,t),e(l,jt,t),e(l,ml,t),e(l,Tt,t),u(ol,l,t),e(l,ht,t),u(dl,l,t),e(l,wt,t),e(l,cl,t),e(l,ft,t),u(Y,l,t),e(l,gt,t),e(l,Ul,t),e(l,Qt,t),u(yl,l,t),e(l,Zt,t),e(l,ul,t),e(l,Gt,t),u(Jl,l,t),e(l,Ct,t),u(bl,l,t),e(l,It,t),e(l,jl,t),e(l,$t,t),u(Tl,l,t),e(l,kt,t),e(l,hl,t),e(l,Rt,t),u(wl,l,t),e(l,_t,t),e(l,fl,t),e(l,Nt,t),Sl[N].m(l,t),e(l,El,t),e(l,gl,t),e(l,Bt,t),u(Ql,l,t),e(l,Xt,t),e(l,Zl,t),e(l,xt,t),Fl[X].m(l,t),e(l,Al,t),e(l,Gl,t),e(l,Vt,t),u(Cl,l,t),e(l,Wt,t),e(l,Il,t),e(l,zt,t),u($l,l,t),e(l,Yt,t),e(l,kl,t),e(l,St,t),vl[V].m(l,t),e(l,Hl,t),e(l,Rl,t),e(l,Ft,t),u(_l,l,t),e(l,vt,t),e(l,Nl,t),e(l,Et,t),u(Bl,l,t),e(l,At,t),e(l,Xl,t),e(l,Ht,t),u(xl,l,t),e(l,qt,t),u(Vl,l,t),e(l,Dt,t),e(l,Wl,t),e(l,Lt,t),u(S,l,t),e(l,Kt,t),u(zl,l,t),e(l,Pt,t),e(l,ql,t),Ot=!0},p(l,[t]){const Ys={};t&1&&(Ys.fw=l[0]),r.$set(Ys);let ss=Q;Q=Ns(l),Q!==ss&&(ts(),m(Yl[ss],1,1,()=>{Yl[ss]=null}),ls(),Z=Yl[Q],Z||(Z=Yl[Q]=_s[Q](l),Z.c()),o(Z,1),Z.m(R.parentNode,R));const Ss={};t&2&&(Ss.$$scope={dirty:t,ctx:l}),Y.$set(Ss);let es=N;N=Xs(l),N!==es&&(ts(),m(Sl[es],1,1,()=>{Sl[es]=null}),ls(),B=Sl[N],B||(B=Sl[N]=Bs[N](l),B.c()),o(B,1),B.m(El.parentNode,El));let as=X;X=Vs(l),X!==as&&(ts(),m(Fl[as],1,1,()=>{Fl[as]=null}),ls(),x=Fl[X],x||(x=Fl[X]=xs[X](l),x.c()),o(x,1),x.m(Al.parentNode,Al));let ns=V;V=zs(l),V!==ns&&(ts(),m(vl[ns],1,1,()=>{vl[ns]=null}),ls(),W=vl[V],W||(W=vl[V]=Ws[V](l),W.c()),o(W,1),W.m(Hl.parentNode,Hl));const Fs={};t&2&&(Fs.$$scope={dirty:t,ctx:l}),S.$set(Fs)},i(l){Ot||(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(ol.$$.fragment,l),o(dl.$$.fragment,l),o(Y.$$.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($l.$$.fragment,l),o(W),o(_l.$$.fragment,l),o(Bl.$$.fragment,l),o(xl.$$.fragment,l),o(Vl.$$.fragment,l),o(S.$$.fragment,l),o(zl.$$.fragment,l),Ot=!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(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(ol.$$.fragment,l),m(dl.$$.fragment,l),m(Y.$$.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($l.$$.fragment,l),m(W),m(_l.$$.fragment,l),m(Bl.$$.fragment,l),m(xl.$$.fragment,l),m(Vl.$$.fragment,l),m(S.$$.fragment,l),m(zl.$$.fragment,l),Ot=!1},d(l){l&&(s(d),s(n),s(w),s(c),s(b),s(R),s($),s(k),s(g),s(Kl),s(v),s(Pl),s(z),s(Ol),s(lt),s(A),s(tt),s(st),s(q),s(et),s(at),s(nt),s(K),s(Mt),s(pt),s(it),s(ll),s(rt),s(mt),s(ot),s(el),s(dt),s(ct),s(nl),s(Ut),s(yt),s(ut),s(il),s(Jt),s(bt),s(_),s(jt),s(ml),s(Tt),s(ht),s(wt),s(cl),s(ft),s(gt),s(Ul),s(Qt),s(Zt),s(ul),s(Gt),s(Ct),s(It),s(jl),s($t),s(kt),s(hl),s(Rt),s(_t),s(fl),s(Nt),s(El),s(gl),s(Bt),s(Xt),s(Zl),s(xt),s(Al),s(Gl),s(Vt),s(Wt),s(Il),s(zt),s(Yt),s(kl),s(St),s(Hl),s(Rl),s(Ft),s(vt),s(Nl),s(Et),s(At),s(Xl),s(Ht),s(qt),s(Dt),s(Wl),s(Lt),s(Kt),s(Pt),s(ql)),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(ol,l),J(dl,l),J(Y,l),J(yl,l),J(Jl,l),J(bl,l),J(Tl,l),J(wl,l),Sl[N].d(l),J(Ql,l),Fl[X].d(l),J(Cl,l),J($l,l),vl[V].d(l),J(_l,l),J(Bl,l),J(xl,l),J(Vl,l),J(S,l),J(zl,l)}}}const Ue='{"title":"使用 FAISS 進行語義搜索","local":"使用-faiss-進行語義搜索","sections":[{"title":"使用嵌入進行語義搜索","local":"使用嵌入進行語義搜索","sections":[],"depth":2},{"title":"## 加載和準備數據集","local":"-加載和準備數據集","sections":[],"depth":2},{"title":"創建文本嵌入","local":"創建文本嵌入","sections":[],"depth":2},{"title":"使用 FAISS 進行高效的相似性搜索","local":"使用-faiss-進行高效的相似性搜索","sections":[],"depth":2}],"depth":1}';function ye(C,a,d){let n="pt";return Ds(()=>{const w=new URLSearchParams(window.location.search);d(0,n=w.get("fw")||"pt")}),[n]}class ge extends Ls{constructor(a){super(),Ks(this,a,ye,ce,qs,{})}}export{ge as component};
