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

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

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

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

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

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

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

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

----------

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

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

----------

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

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


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

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

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