{"id":10279,"date":"2024-06-14T17:19:37","date_gmt":"2024-06-14T17:19:37","guid":{"rendered":"https:\/\/www.aihello.com\/resources\/?p=10279"},"modified":"2026-09-23T03:20:19","modified_gmt":"2026-09-23T03:20:19","slug":"fine-tuning-sentence-transformers-for-embedding-search","status":"publish","type":"post","link":"https:\/\/www.aihello.com\/resources\/blog\/fine-tuning-sentence-transformers-for-embedding-search\/","title":{"rendered":"Fine-Tuning Sentence Transformers for Embedding Search"},"content":{"rendered":"<div class=\"wp-block-group ah-reading-guide ah-compact-toc\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\"><style>\n.ah-reading-guide{max-width:820px;margin:0 auto;color:#26364a;font-size:18px;line-height:1.8;counter-reset:ah-section}.ah-reading-guide *{box-sizing:border-box}.ah-reading-guide p{margin:0 0 22px;line-height:1.8}.ah-reading-guide strong{color:#142d48}.ah-reading-guide h2{position:relative;margin:56px 0 24px;padding-top:24px;border-top:1px solid #dce7ef;font-size:29px;line-height:1.35;letter-spacing:-.4px;color:#142d48}.ah-reading-guide h2.ah-numbered{padding-left:54px;counter-increment:ah-section}.ah-reading-guide h2.ah-numbered:before{content:counter(ah-section,decimal-leading-zero);position:absolute;left:0;top:26px;display:flex;align-items:center;justify-content:center;width:38px;height:38px;background:#eaf4fc;color:#216faf;border-radius:10px;font-size:15px;font-weight:700;letter-spacing:0}.ah-reading-guide h3{position:relative;margin:34px 0 16px;font-size:23px;line-height:1.4;color:#163f65}.ah-reading-guide h4{position:relative;margin:28px 0 14px;font-size:20px;line-height:1.45;color:#163f65}.ah-reading-guide .ah-lead{margin:0 0 28px;padding:24px 28px;border-left:4px solid #2479ba;border-radius:0 12px 12px 0;background:#eef6fc;font-size:20px;line-height:1.75}.ah-reading-guide .ah-callout,.ah-reading-guide .ah-formula{margin:28px 0;padding:24px 26px;border:1px solid #d7e5f1;border-left:4px solid #2479ba;border-radius:0 12px 12px 0;background:#f5f9fd}.ah-reading-guide .ah-formula{font-size:20px;font-weight:600;font-variant-numeric:tabular-nums;line-height:1.9;overflow-wrap:anywhere}.ah-reading-guide ul,.ah-reading-guide ol{margin:24px 0 30px;padding-left:28px}.ah-reading-guide li{margin:0 0 12px;padding-left:7px;line-height:1.75}.ah-reading-guide li::marker{color:#2479ba;font-weight:700}.ah-reading-guide ol.ah-steps{list-style:none;counter-reset:ah-step;padding:0;display:grid;gap:14px}.ah-reading-guide ol.ah-steps>li{position:relative;counter-increment:ah-step;margin:0;padding:22px 24px 22px 64px;border:1px solid #dbe7f1;border-radius:12px;background:#f6fafd}.ah-reading-guide ol.ah-steps>li:before{content:counter(ah-step);position:absolute;top:23px;left:20px;display:flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:50%;background:#2378b9;color:white;font-size:14px;font-weight:700}.ah-reading-guide ul.ah-cards{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px;padding:0;list-style:none}.ah-reading-guide ul.ah-cards>li{margin:0;padding:20px 22px;border:1px solid #dbe8f2;background:#f7fbfe;border-radius:12px;font-size:17px;line-height:1.7}.ah-reading-guide ul.ah-cards>li:last-child:nth-child(odd){grid-column:1\/-1}.ah-reading-guide .ah-cards>li>strong:first-child{display:block;margin-bottom:8px;color:#19598d}.ah-reading-guide .ah-step-panel{margin:22px 0;padding:24px 28px;border-left:4px solid #2479ba;border-radius:0 12px 12px 0;background:#f5f9fd}.ah-reading-guide .ah-step-panel h3{margin-top:0}.ah-reading-guide .ah-step-panel p:last-child{margin-bottom:0}.ah-reading-guide figure{max-width:100%;margin:30px 0}.ah-reading-guide figure.wp-block-image{padding:7px;border:1px solid #e0e8ef;border-radius:12px;background:white;box-shadow:0 5px 18px rgba(20,45,72,.06)}.ah-reading-guide img{max-width:100%;height:auto}.ah-reading-guide figure.wp-block-image img{display:block;border-radius:6px}.ah-reading-guide figcaption{font-size:14px;line-height:1.5;color:#587086;margin-top:10px}.ah-reading-guide figure.wp-block-table{overflow-x:auto;border:1px solid #d8e5ef;border-radius:10px}.ah-reading-guide table{width:100%;border-collapse:collapse;font-size:16px;line-height:1.6}.ah-reading-guide th,.ah-reading-guide td{padding:14px 16px;border:1px solid #d8e5ef;text-align:left;vertical-align:top}.ah-reading-guide th{background:#eaf4fc;color:#163f65;font-weight:700}.ah-reading-guide tbody tr:nth-child(even){background:#f6f9fc}.ah-reading-guide blockquote{margin:30px 0;padding:22px 26px;border-left:4px solid #2479ba;background:#f3f8fc;border-radius:0 10px 10px 0}.ah-reading-guide #ez-toc-container{width:100%;margin:32px 0 42px;padding:22px 24px;border:1px solid #cbdfee;border-top:4px solid #2479ba;border-radius:12px;background:#f7fbfe;box-shadow:none}.ah-reading-guide #ez-toc-container .ez-toc-title{margin:0;font-size:20px;font-weight:700;color:#163f65;line-height:1.5}.ah-reading-guide #ez-toc-container .ez-toc-title-container{margin-bottom:14px}.ah-reading-guide #ez-toc-container ul.ez-toc-list-level-1{display:block;column-count:2;column-gap:26px;padding:0;margin:0}.ah-reading-guide #ez-toc-container ul.ez-toc-list-level-1>li{break-inside:avoid;padding:11px 0;margin:0;border-bottom:1px solid #dce7ef;line-height:1.5;font-size:16px}.ah-reading-guide #ez-toc-container ul ul{margin:7px 0 0;padding-left:18px}.ah-reading-guide #ez-toc-container li li{padding:0;margin:5px 0;font-size:14px}.ah-reading-guide #ez-toc-container a{color:#19598d;text-decoration:none}.ah-reading-guide #ez-toc-container a:hover{text-decoration:underline}.ah-reading-guide #ez-toc-container a:focus-visible{outline:3px solid #2479ba;outline-offset:4px;border-radius:3px}.ah-reading-guide :is(h2,h3,h4)>.ez-toc-section{position:absolute;top:-100px;left:0}.ah-reading-guide :is(h2,h3,h4)>.ez-toc-section-end{position:absolute;top:0;left:0}.ah-reading-guide [id]{scroll-margin-top:100px}.ah-reading-guide .gspb_container{min-width:0}@media(max-width:700px){.ah-reading-guide{font-size:17px}.ah-reading-guide h2{font-size:25px;margin-top:44px}.ah-reading-guide h2.ah-numbered{padding-left:43px}.ah-reading-guide h2.ah-numbered:before{width:30px;height:30px;font-size:13px}.ah-reading-guide h3{font-size:21px}.ah-reading-guide ul.ah-cards{grid-template-columns:1fr}.ah-reading-guide .ah-lead,.ah-reading-guide .ah-callout,.ah-reading-guide .ah-formula,.ah-reading-guide .ah-step-panel{padding:20px}.ah-reading-guide .ah-lead,.ah-reading-guide .ah-formula{font-size:18px}.ah-reading-guide #ez-toc-container{padding:18px}.ah-reading-guide #ez-toc-container ul.ez-toc-list-level-1{column-count:1}}@media(prefers-reduced-motion:reduce){.ah-reading-guide [data-aos]{opacity:1!important;visibility:visible!important;transform:none!important;transition:none!important;animation:none!important}}\n\n.ah-reading-guide .ah-process-heading{padding-left:48px;min-height:36px}.ah-reading-guide .ah-process-heading:before{position:absolute;left:0;top:0;width:34px;height:34px;display:flex;align-items:center;justify-content:center;border-radius:9px;background:#eaf4fc;color:#216faf;font-size:15px;font-weight:700}.ah-reading-guide .ah-process-1:before{content:\"01\"}.ah-reading-guide .ah-process-2:before{content:\"02\"}.ah-reading-guide .ah-process-3:before{content:\"03\"}.ah-reading-guide .ah-process-4:before{content:\"04\"}.ah-reading-guide .ah-process-5:before{content:\"05\"}.ah-reading-guide .ah-process-6:before{content:\"06\"}.ah-reading-guide .ah-process-7:before{content:\"07\"}.ah-reading-guide .ah-process-8:before{content:\"08\"}.ah-reading-guide .ah-process-9:before{content:\"09\"}\n.ah-reading-guide .ah-definition{padding:20px 24px;margin:14px 0;border:1px solid #dbe7f1;border-radius:12px;background:#f8fbfe}.ah-reading-guide .ah-definition strong{color:#163f65}\n.ah-reading-guide .ah-long-form-list>li{margin-bottom:28px}.ah-reading-guide .ah-long-form-list>li>strong:first-child{display:block;font-size:22px;line-height:1.4;margin-bottom:16px}.ah-reading-guide .ah-long-form-list li img{display:block;margin:22px auto}.ah-reading-guide .ah-formula-comparison{font-variant-numeric:tabular-nums}\n.ah-reading-guide h5,.ah-reading-guide h6{font-size:18px;line-height:1.5;color:#163f65;margin:26px 0 14px;font-weight:700}\n.ah-reading-guide h2.ah-instruction-heading{font-size:21px;margin:24px 0 18px;padding-top:18px}.ah-reading-guide h2.ah-instruction-heading:before{top:18px}\n.ah-reading-guide ul.ah-stacked-cards{list-style:none;padding:0}.ah-reading-guide .ah-stacked-cards>li{margin:14px 0;padding:20px 24px;border:1px solid #dbe7f1;border-radius:12px;background:#f8fbfe}\n.ah-reading-guide .ah-minor-label{font-weight:700;color:#1e4e64;font-size:18px;margin:20px 0 8px;}\n.ah-reading-guide h3.ah-do,.ah-reading-guide h3.ah-dont{font-size:21px;padding:18px 22px;border-radius:0 10px 10px 0}.ah-reading-guide h3.ah-do{border-left:4px solid #20877e;background:#f0faf8}.ah-reading-guide h3.ah-dont{border-left:4px solid #ae6340;background:#fff7f0}\n.ah-reading-guide p.ah-fact-row{margin:6px 0;padding:12px 18px;background:#f4f8fc;border-left:3px solid #c7dcf0;border-radius:0 8px 8px 0;font-size:17px;line-height:1.65}.ah-reading-guide p.ah-cta a{display:inline-block;padding:12px 20px;border-radius:9px;background:#135faa;color:#fff;text-decoration:none;font-weight:700}.ah-reading-guide p.ah-cta a:hover{background:#104d89}.ah-reading-guide .ah-agency-summary td:first-child{width:38%;color:#184b75}\n.ah-reading-guide details.ah-original-index{padding:16px 20px;border:1px solid #dce7f0;border-radius:10px;margin:24px 0;background:#f8fafc}.ah-reading-guide details.ah-original-index summary{cursor:pointer;font-size:18px;font-weight:700;color:#244f74}.ah-reading-guide details.ah-original-index>ol{margin-top:18px}\n.ah-reading-guide ul.ah-cycle-cards{grid-template-columns:repeat(3,minmax(0,1fr));gap:22px}.ah-reading-guide ul.ah-cycle-cards>li{position:relative;text-align:center;display:flex;align-items:center;justify-content:center;min-height:110px;font-weight:700;color:#20567d}.ah-reading-guide ul.ah-cycle-cards>li:last-child:nth-child(odd){grid-column:auto}.ah-reading-guide ul.ah-cycle-cards>li:not(:last-child)::after{content:\"\u203a\";position:absolute;right:-19px;top:50%;transform:translateY(-50%);font-size:28px;color:#3785b4}@media(max-width:700px){.ah-reading-guide ul.ah-cycle-cards{grid-template-columns:1fr}.ah-reading-guide ul.ah-cycle-cards>li:not(:last-child)::after{right:50%;top:auto;bottom:-25px;transform:rotate(90deg)}}\n.ah-reading-guide .ah-process-10::before{content:\"10\"}\n.ah-reading-guide pre.wp-block-code{background:#122238;color:#eff6ff;border:1px solid #29415f;border-radius:12px;padding:22px 24px;margin:24px 0;overflow-x:auto;font-size:15px;line-height:1.7;white-space:pre;tab-size:4}.ah-reading-guide pre.wp-block-code code{background:transparent;color:inherit;padding:0;white-space:pre;font-family:Consolas,Monaco,monospace}.ah-reading-guide p code{background:#edf3fa;color:#204d78;border-radius:4px;padding:2px 5px}\n.ah-reading-guide ol.ah-steps.ah-start-2{counter-reset:ah-step 1}\n.ah-reading-guide ol.ah-steps.ah-start-3{counter-reset:ah-step 2}\n.ah-reading-guide ol.ah-steps.ah-start-4{counter-reset:ah-step 3}\n.ah-reading-guide ol.ah-steps.ah-start-5{counter-reset:ah-step 4}\n.ah-reading-guide ol.ah-steps.ah-start-6{counter-reset:ah-step 5}\n.ah-reading-guide ol.ah-steps.ah-start-7{counter-reset:ah-step 6}\n.ah-reading-guide ol.ah-steps.ah-start-8{counter-reset:ah-step 7}\n.ah-reading-guide ol.ah-steps.ah-start-9{counter-reset:ah-step 8}\n.ah-reading-guide ol.ah-steps.ah-start-10{counter-reset:ah-step 9}\n.ah-reading-guide ol.ah-steps.ah-start-11{counter-reset:ah-step 10}\n.ah-reading-guide ol.ah-steps.ah-start-12{counter-reset:ah-step 11}\n.ah-reading-guide #ez-toc-container nav{max-height:460px;overflow-y:auto;padding-right:8px}.ah-reading-guide figure.ah-comparison-wide{max-height:650px;overflow:auto;border:1px solid #dae4ee;border-radius:12px}.ah-reading-guide .ah-comparison-wide table{min-width:760px;font-size:15px}.ah-reading-guide .ah-comparison-wide thead th{position:sticky;top:0;background:#183f65;color:#fff;z-index:1}.ah-reading-guide figure.ah-agency-summary tbody th{width:30%;background:#edf4fa;color:#244764;font-weight:700}\n.ah-reading-guide #ez-toc-container a.ez-toc-link::before{content:none!important;display:none!important}\n.ah-reading-guide .ah-comparison-wide thead th,.ah-reading-guide .ah-comparison-wide thead th *{color:#fff!important}\n.ah-reading-guide .ah-equation{display:block;margin:16px 0;padding:16px 20px;border-left:4px solid #2378b9;background:#edf4fa;border-radius:8px;font-size:20px;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}\n.ah-reading-guide .ah-feature-comparison thead th:nth-child(1){width:18%}.ah-reading-guide .ah-feature-comparison thead th:nth-child(2){width:12%;white-space:nowrap}.ah-reading-guide .ah-feature-comparison thead th:nth-child(3){width:48%}.ah-reading-guide .ah-feature-comparison thead th:nth-child(4){width:22%}\n.ah-reading-guide.ah-compact-toc #ez-toc-container ul.ez-toc-list>li>ul>li>ul{display:none}.ah-reading-guide h4.ah-do{color:#276044!important}.ah-reading-guide h4.ah-dont{color:#855218!important}.ah-reading-guide p.ah-tool-bullet{margin:.45em 0!important;padding:.6em 1em;border-radius:8px;background:#f4f7fa;line-height:1.65}\n.ah-reading-guide .ah-glossary-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:20px;margin:30px 0}.ah-reading-guide .ah-glossary-entry{background:#f7f9fc;border:1px solid #dce5ef;border-radius:12px;padding:22px;height:100%;box-sizing:border-box}.ah-reading-guide .ah-glossary-entry h2{font-size:21px!important;margin:0 0 14px!important;line-height:1.4!important;border:0;padding:0}.ah-reading-guide .ah-glossary-entry p{font-size:16px!important;line-height:1.7!important;margin:0!important}@media(max-width:650px){.ah-reading-guide .ah-glossary-grid{grid-template-columns:1fr}}\n.ah-reading-guide .ah-glossary-grid{display:block}.ah-reading-guide .ah-glossary-grid>.wp-block-group__inner-container{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:20px;align-items:stretch}.ah-reading-guide .ah-glossary-entry{height:auto!important;margin:0!important;min-width:0}.ah-reading-guide .ah-glossary-grid>.wp-block-group__inner-container>.wp-block-greenshift-blocks-container{display:flex;min-width:0}.ah-reading-guide .ah-glossary-grid>.wp-block-group__inner-container>.wp-block-greenshift-blocks-container>.ah-glossary-entry{flex:1}@media(max-width:650px){.ah-reading-guide .ah-glossary-grid>.wp-block-group__inner-container{grid-template-columns:1fr}}\n.ah-reading-guide ol.ah-steps.ah-feature-grid{grid-template-columns:repeat(2,minmax(0,1fr))}@media(max-width:700px){.ah-reading-guide ol.ah-steps.ah-feature-grid{grid-template-columns:1fr}}\n.ah-reading-guide pre.wp-block-preformatted{background:#122238;color:#eff6ff;border:1px solid #29415f;border-radius:12px;padding:22px 24px;margin:24px 0;overflow-x:auto;font-size:15px;line-height:1.7;white-space:pre;tab-size:4;font-family:Consolas,Monaco,monospace}.ah-reading-guide pre.wp-block-preformatted code{background:transparent;color:inherit;padding:0;white-space:pre;font:inherit}.ah-reading-guide .ah-output-sample{max-height:360px;overflow:auto;padding:24px;border:1px solid #d7e5f1;border-radius:12px;background:#f5f9fd;font-size:16px;line-height:1.8}\n.ah-reading-guide pre.wp-block-preformatted,.ah-reading-guide pre.wp-block-preformatted code{white-space:pre!important;text-align:left!important}.ah-reading-guide pre br{display:initial!important}\n.ah-reading-guide .wp-block-media-text{display:grid!important;grid-template-columns:minmax(120px,22%) minmax(0,1fr)!important;gap:24px;padding:28px;border:1px solid #d7e5f1;border-radius:14px;background:#f5f9fd;align-items:center!important}.ah-reading-guide .wp-block-media-text__content{min-width:0;max-width:none!important;width:auto!important;padding:0!important}.ah-reading-guide .wp-block-media-text__content p{width:auto!important;max-width:none!important;text-align:left!important}.ah-reading-guide .wp-block-media-text__content p:not(:first-child) strong{font-weight:400}.ah-reading-guide .wp-block-media-text__media{margin:0!important;min-width:0}.ah-reading-guide .wp-block-media-text__media img{width:100%;max-width:160px;height:auto;margin:auto}.ah-reading-guide .wp-block-media-text__content .wp-block-button{max-width:100%}@media(max-width:650px){.ah-reading-guide .wp-block-media-text{grid-template-columns:1fr!important;padding:20px}.ah-reading-guide .wp-block-media-text__media{grid-column:1!important;grid-row:1!important}.ah-reading-guide .wp-block-media-text__content{grid-column:1!important;grid-row:2!important}}<\/style><noscript><style>.ah-reading-guide [data-aos]{opacity:1!important;visibility:visible!important;transform:none!important}<\/style><\/noscript><p class=\"ah-lead wp-block-paragraph\">Discover <a  data-ilj-link-preview=\"true\"  data-featured-image=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2022\/08\/amazon-backend-search-terms-optimization-guide-basics-how-to-300x300.png\"  data-excerpt=\"Unlock Amazon success! Master backend keywords to boost product visibility, improve relevancy, and drive sales without keyword stuffing.\" href=\"https:\/\/www.aihello.com\/resources\/blog\/everything-about-optimizing-amazon-backend-keywords-guide-2022\/\">how to<\/a> fine-tune and train a Sentence Transformers model for sentence similarity search by harnessing the power of <em>vector embeddings<\/em>.<\/p><h2 id=\"introduction\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"wp-block-paragraph\">Sentence Transformers is a widely recognized Python module for training or fine-tuning state-of-the-art text embedding models. In the realm of large language models (LLMs), embedding plays a crucial role, as it significantly enhances the performance of tasks such as similarity search when tailored to specific datasets.<\/p><p class=\"wp-block-paragraph\">Recently, Hugging Face released version 3.0.0 of Sentence Transformers, which simplifies training, logging, and evaluation processes. In this article, we will explore how to train and fine-tune a Sentence Transformer model using our data.<\/p><h2 id=\"embeddings-for-similarity-search\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Embeddings_for_Similarity_Search\"><\/span>Embeddings for Similarity Search<span class=\"ez-toc-section-end\"><\/span><\/h2><p>Embedding is the process of converting text into fixed-size vector representations (floating-point numbers) that capture the semantic meaning of the text in relation to other words. How can this be used for similarity search? In similarity search, we embed queries into a vector database. When a user submits a query, we need to find similar queries in the database.<\/p><div class=\"wp-block-greenshift-blocks-container gspb_container gspb_container-gsbp-f10279-1\" id=\"gspb_container-id-gsbp-f10279-1\" data-aos=\"fade\" data-aos-easing=\"ease\" data-aos-duration=\"500\" data-aos-once=\"true\"><ol class=\"wp-block-list ah-steps\"><li>First, convert all textual data into fixed-size vector embeddings and store them in a vector database. <\/li><li>Next, accept a query from the user and convert it into an embedding as well. <\/li><li>Then, find similar <a  data-ilj-link-preview=\"true\"  data-featured-image=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2021\/11\/amazon-advertising-keyword-search-term-reports-harvesting-300x200.jpg\"  data-excerpt=\"Unlock Amazon Seller success with Amazon Brand Analytics&#039; Search Keywords report. Master finding top search terms to optimize listings and PPC for maximum visibility and sales.\" href=\"https:\/\/www.aihello.com\/resources\/blog\/the-full-amazon-search-terms-report-guide\/\">search terms<\/a> or <a  data-ilj-link-preview=\"true\"  data-featured-image=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2021\/10\/amazon_seo_strategy_amazon_seo_optimization_amazon_search_engine_optimization_5650-300x200.jpg\"  data-excerpt=\"Which SEO strategy is best for your business: Amazon or Google? Explore the distinct approaches to optimize for product searches vs. general queries and drive sales.\" href=\"https:\/\/www.aihello.com\/resources\/blog\/google-seo-vs-amazon-seo-explained\/\">keywords<\/a> from the user query within the vector database and retrieve those embeddings that are closest. <\/li><\/ol><p class=\"ah-callout wp-block-paragraph\">Is it simple? Yes, but to search for the closest embeddings, we need to use distance-based algorithms such as Cosine Similarity, Manhattan Distance, or Euclidean Distance.<\/p><\/div><h2 id=\"what-is-sbert\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_SBERT\"><\/span>What is SBERT?<span class=\"ez-toc-section-end\"><\/span><\/h2><div class=\"wp-block-greenshift-blocks-container gspb_container gspb_container-gsbp-f10279-2\" id=\"gspb_container-id-gsbp-f10279-2\" data-aos=\"fade\" data-aos-easing=\"ease\" data-aos-duration=\"500\" data-aos-once=\"true\"><div class=\"wp-block-group ah-definition\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\"><p><mark class=\"has-inline-color has-theme-color-five-color\">SBERT (Sentence-BERT) is a specialized type of sentence transformer model tailored for efficient sentence processing and comparison.<\/mark> It employs a Siamese <a  data-ilj-link-preview=\"true\"  data-featured-image=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/12\/image-33-300x185.png\"  data-excerpt=\"Unlock the power of knowledge graphs for AI, LLMs &amp; RAG. Discover how to build efficient, cost-effective KGs with SpaCy: entity and relation extraction made easy.\" href=\"https:\/\/www.aihello.com\/resources\/blog\/creating-a-knowledge-graph-without-llms\/\">network<\/a> architecture, utilizing identical BERT models to process sentence pairs independently. Additionally, SBERT utilizes mean pooling on the final output layer to generate high-quality sentence embeddings. <\/p><p>For a comprehensive understanding of SBERT, I recommend referring to the detailed <a href=\"https:\/\/towardsdatascience.com\/sbert-deb3d4aef8a4\" target=\"_blank\" rel=\"noreferrer noopener\"><em>article<\/em><\/a>.<\/p><\/div><\/div><\/div><h2 id=\"installation-and-setup\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Installation_and_setup\"><\/span>Installation and setup<span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"wp-block-paragraph\">You can either use online notebooks such as <a  data-ilj-link-preview=\"true\"  data-featured-image=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2022\/02\/boost-sales-300x200.jpg\"  data-excerpt=\"Unlock Amazon&#039;s Brand Referral Bonus! Discover how driving external traffic, especially from Google Ads, boosts your sales, increases organic reach, and earns rewards.\" href=\"https:\/\/www.aihello.com\/resources\/blog\/boost-amazon-sales-using-google-ads\/\">Google<\/a> Colab. I have also covered how to execute training code from script. For Google Colab, set your runtime environment to T4 GPU hardware.<\/p><h3 id=\"install-necessary-dependencies\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Install_necessary_dependencies\"><\/span>Install necessary dependencies.<span class=\"ez-toc-section-end\"><\/span><\/h3><pre class=\"wp-block-code\"><code>!pip install -U \"sentence-transformers&#091;train]\" accelerate datasets<\/code><\/pre><h3 id=\"import-dependencies\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Import_dependencies\"><\/span>Import dependencies<span class=\"ez-toc-section-end\"><\/span><\/h3><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"547\" title=\"how to improve your listing on amazon | how much is advertising on amazon | does amazon ppc divide budget between keywords based on search volume\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_1-3-1024x547.png\" alt=\"\" class=\"wp-image-10325\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_1-3-1024x547.png 1024w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_1-3-300x160.png 300w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_1-3-768x410.png 768w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_1-3-1250x668.png 1250w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_1-3.png 1400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><p class=\"wp-block-paragraph\">For this blog post, I am using <a href=\"https:\/\/huggingface.co\/datasets\/SetFit\/stsb\" target=\"_blank\" rel=\"noreferrer noopener\">Glue STS-B<\/a> data and model <a href=\"https:\/\/huggingface.co\/sentence-transformers\/all-MiniLM-L6-v2\" target=\"_blank\" rel=\"noreferrer noopener\">sentence-transformers\/all-MiniLM-L6-v2<\/a><\/p><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"290\" title=\"how can i earn money from amazon | how to make money selling books | what is sponsored brands in amazon\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_2-3-1024x290.png\" alt=\"\" class=\"wp-image-10326\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_2-3-1024x290.png 1024w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_2-3-300x85.png 300w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_2-3-768x217.png 768w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_2-3-1250x354.png 1250w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_2-3.png 1400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><p class=\"ah-step-panel wp-block-paragraph\">Let&#8217;s see random sample data from train data<\/p><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"290\" title=\"how do people make money on amazon | how to advertise products on amazon | what is acos\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_3-1-1024x290.png\" alt=\"\" class=\"wp-image-10327\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_3-1-1024x290.png 1024w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_3-1-300x85.png 300w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_3-1-768x217.png 768w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_3-1-1250x354.png 1250w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_3-1.png 1400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><h4 id=\"output\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output:<span class=\"ez-toc-section-end\"><\/span><\/h4><pre class=\"wp-block-code\"><code>Sentence 1:  Some men are fighting. Sentence 2:  Two men are fighting. Score:  0.85<\/code><\/pre><p class=\"ah-callout wp-block-paragraph\">This will be the format of our data: \u2018sentence1\u2019, \u2018sentence2\u2019, and \u2018score\u2019. The \u2018score\u2019 represents the degree of closeness or similarity between the two sentences. In cases where a label score is unavailable, you simply need to modify the loss function and evaluator accordingly.<\/p><h2 id=\"training-sbert\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Training_SBERT\"><\/span>Training SBERT<span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"wp-block-paragraph\">This is recommended way to train SBERT model form <a href=\"https:\/\/www.sbert.net\/\" target=\"_blank\" rel=\"noreferrer noopener\">SBERT official site.<\/a><\/p><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"149\" title=\"what is brand analytics | what is sponsored ads | how amazon advertising works\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/image.png\" alt=\"\" class=\"wp-image-10283\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/image.png 1000w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/image-300x45.png 300w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/image-768x114.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure><p class=\"ah-callout wp-block-paragraph\"><em>To train the SBERT model, you need to encapsulate the model building, evaluator, and training processes within the <code>main()<\/code> function, <a href=\"https:\/\/github.com\/UKPLab\/sentence-transformers\/pull\/2449\" data-type=\"link\" data-id=\"https:\/\/github.com\/UKPLab\/sentence-transformers\/pull\/2449\">See this discussion.<\/a><\/em><\/p><h3 id=\"training-code\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Training_Code\"><\/span>Training Code:<span class=\"ez-toc-section-end\"><\/span><\/h3><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"665\" height=\"1024\" title=\"what is fba inventory | how to report fake amazon reviews | what is acos\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_4-4-665x1024.png\" alt=\"\" class=\"wp-image-10329\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_4-4-665x1024.png 665w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_4-4-195x300.png 195w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_4-4-768x1183.png 768w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_4-4-997x1536.png 997w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_4-4-1330x2048.png 1330w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_4-4-1250x1925.png 1250w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_4-4.png 1400w\" sizes=\"auto, (max-width: 665px) 100vw, 665px\" \/><\/figure><p class=\"wp-block-paragraph\">Now, let&#8217;s understand each component inside <code>main()<\/code> function step by step,<\/p><div class=\"wp-block-greenshift-blocks-container gspb_container gspb_container-gsbp-f10279-3\" id=\"gspb_container-id-gsbp-f10279-3\" data-aos=\"fade\" data-aos-easing=\"ease\" data-aos-duration=\"500\" data-aos-once=\"true\"><ol class=\"wp-block-list ah-steps\"><li>Define the <code>Accelerator()<\/code> to determine the number of GPUs available on the current machine.<\/li><li>Load the Sentence Transformers model from the <a href=\"https:\/\/huggingface.co\/sentence-transformers\" target=\"_blank\" rel=\"noreferrer noopener\">HuggingFace repository<\/a> and extract the word embedding dimension using mean pooling. Add a mean pooling layer after the SBERT model as output.<\/li><li>Define the Loss function, such as <code>CoSENTLoss()<\/code>, to calculate the model\u2019s loss based on float similarity scores. Choose the appropriate loss function from SBERT\u2019s options based on your data and labels. Refer to the <a href=\"https:\/\/www.sbert.net\/docs\/sentence_transformer\/loss_overview.html\" target=\"_blank\" rel=\"noreferrer noopener\">Loss Overview<\/a> in the Sentence Transformers documentation.<\/li><li>Use the <code>Evaluator()<\/code> class provided by Sentence Transformers to calculate the evaluation loss during training and obtain specific metrics. Choose the appropriate evaluator, such as <code>EmbeddingSimilarityEvaluator()<\/code>, based on your data and use case. Refer to this <a href=\"https:\/\/www.sbert.net\/docs\/sentence_transformer\/training_overview.html#evaluator\" target=\"_blank\" rel=\"noreferrer noopener\">table<\/a> for available options.<\/li><li>Specify training arguments, such as the output directory for storing checkpoints, batch size per device (CPU\/GPU), number of training epochs, learning rate, float16 precision for model loading, evaluation steps, etc., using the <code>SentenceTransformerTrainer<\/code> class which is indirectly inherited from transformers <code><a href=\"https:\/\/huggingface.co\/docs\/transformers\/v4.26.1\/en\/main_classes\/trainer#transformers.TrainingArguments\" target=\"_blank\" rel=\"noreferrer noopener\">TrainingArguments<\/a><\/code>.<\/li><li>Train the model using the <code>SentenceTransformerTrainer<\/code> class by defining the training and validation data, optionally including an evaluator, specifying training arguments, and defining the loss function. Initiate training by calling the <code>train()<\/code> method. Perform training and save the model further.<\/li><\/ol><\/div><h2 id=\"various-methods-for-training-sbert\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Various_Methods_for_Training_SBERT\"><\/span>Various Methods for Training SBERT<span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"wp-block-paragraph\">After defining the <code>main()<\/code> function, simply call it to initiate the model training process. There are several ways to do this:<\/p><h3 id=\"for-single-gpu\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"For_Single_GPU\"><\/span>For Single GPU:<span class=\"ez-toc-section-end\"><\/span><\/h3><ul class=\"wp-block-list ah-cards\"><li>If you are running code in Google Colab free version with T4 GPU then just create a new cell and call function: <code>main()<\/code><\/li><li>If you are running your code in Python script, then just run a python command in the terminal: <code>python main.py<\/code>.<\/li><\/ul><h3 id=\"for-multi-gpu\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"For_Multi-GPU\"><\/span>For Multi-GPU:<span class=\"ez-toc-section-end\"><\/span><\/h3><p class=\"wp-block-paragraph\">HuggingFace transformer supports DistributedDataParallel (DDP) training to perform distributed parallel training on multiple GPU or in multiple machines. <a href=\"https:\/\/siboehm.com\/articles\/22\/data-parallel-training\" target=\"_blank\" rel=\"noreferrer noopener\">Read this article<\/a> to understand how DDP works.<\/p><p class=\"wp-block-paragraph\">If you are running your code in colab or any notebook which contains multi-gpu, then:<\/p><pre class=\"wp-block-code\"><code>from accelerator import notebook_launcher<br>notebook_launcher(main, num_processes=2)<\/code><\/pre><p class=\"wp-block-paragraph\">By running above code in a separate will run your code in multi-gpu.<\/p><h4 id=\"for-python-script\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"For_Python_Script\"><\/span>For Python Script:<span class=\"ez-toc-section-end\"><\/span><\/h4><pre class=\"wp-block-code\"><code>accelerate launch \u2013multi-gpu \u2013num_processes=2 main.py<\/code><\/pre><p class=\"wp-block-paragraph\">These are some common ways to run a script or notebook for SBERT training.<\/p><h2 id=\"test-the-model\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Test_the_Model\"><\/span>Test the Model<span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"wp-block-paragraph\">After training the model, we can reload it and perform inference testing. For instance, if we have a list of product names and users input search terms, our goal is to identify the most similar product names along with a score.<\/p><p class=\"wp-block-paragraph\">Having trained our embedding model on sentence similarity data using similarity scores as labels, it will now improve the embeddings.<\/p><p class=\"ah-step-panel wp-block-paragraph\">Here is the sample list of product name which we are using for embedding data:<\/p><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"758\" title=\"what is ebc amazon | how to optimize my amazon listing | what does a9 mean\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_5-2-1024x758.png\" alt=\"\" class=\"wp-image-10330\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_5-2-1024x758.png 1024w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_5-2-300x222.png 300w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_5-2-768x568.png 768w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_5-2-1250x925.png 1250w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_5-2.png 1400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><p class=\"ah-step-panel wp-block-paragraph\">Next, load our fine-tuned SBERT model and convert product names into vector embeddings:<\/p><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"275\" title=\"how do i edit the cost per click bid in amazon advertising | how to start selling on amazon | does amazon fba increase sales\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_6-2-1024x275.png\" alt=\"\" class=\"wp-image-10331\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_6-2-1024x275.png 1024w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_6-2-300x81.png 300w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_6-2-768x206.png 768w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_6-2-1250x336.png 1250w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_6-2.png 1400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><p class=\"ah-step-panel wp-block-paragraph\">To convert product names into embeddings, we\u2019ll utilize the GPU and convert them into tensors. You can do so using the following code:<\/p><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"275\" title=\"what are single keyword ad groups | what is amazon vine and how does it work | how to optimize amazon product listing\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/fine-tuning-sentence-transformers-for-embedding-search-1024x275.png\" alt=\"\" class=\"wp-image-10333\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/fine-tuning-sentence-transformers-for-embedding-search-1024x275.png 1024w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/fine-tuning-sentence-transformers-for-embedding-search-300x81.png 300w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/fine-tuning-sentence-transformers-for-embedding-search-768x206.png 768w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/fine-tuning-sentence-transformers-for-embedding-search-1250x336.png 1250w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/fine-tuning-sentence-transformers-for-embedding-search.png 1400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><p class=\"wp-block-paragraph\">By converting embeddings to CUDA, we leverage GPU computational support (dtype=torch.float32); otherwise, if CPU is selected, it defaults to (dtype=float32).<\/p><p class=\"ah-callout wp-block-paragraph\">This \u2018product_data\u2019 serves as our vector database, now stored in memory. Alternatively, you can utilize vector databases like Qdrant, Pinecone, Chroma, etc.<\/p><p class=\"ah-step-panel wp-block-paragraph\">Lastly, create a function that accepts a user query from the terminal or as user input and returns the top products along with their Cosine-Similarity scores.<\/p><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"317\" title=\"can you use brands keywords on amazon marketing | what is amazon lightning deal | how to rank high on amazon search\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_8-2-1024x317.png\" alt=\"\" class=\"wp-image-10332\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_8-2-1024x317.png 1024w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_8-2-300x93.png 300w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_8-2-768x238.png 768w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_8-2-1536x476.png 1536w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_8-2-1250x388.png 1250w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/snippet_8-2.png 2000w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><h3 id=\"test-run\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Test_run\"><\/span>Test run:<span class=\"ez-toc-section-end\"><\/span><\/h3><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"700\" title=\"how to make money in amazon | how much is amazon referral bonus | what does lightning deal mean on amazon\" src=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/screenshot-86-1024x700.png\" alt=\"\" class=\"wp-image-10288\" srcset=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/screenshot-86-1024x700.png 1024w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/screenshot-86-300x205.png 300w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/screenshot-86-768x525.png 768w, https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2024\/06\/screenshot-86.png 1073w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><div class=\"wp-block-greenshift-blocks-container gspb_container gspb_container-gsbp-f10279-4\" id=\"gspb_container-id-gsbp-f10279-4\" data-aos=\"fade\" data-aos-easing=\"ease\" data-aos-duration=\"500\" data-aos-once=\"true\"><p class=\"ah-callout wp-block-paragraph\">You can observe that our model is performing exceptionally well, with satisfactory scores. To further enhance result <a  data-ilj-link-preview=\"true\"  data-featured-image=\"https:\/\/www.aihello.com\/resources\/wp-content\/uploads\/2021\/12\/amazon_ranking_algorithm_amazon_a9_algorithm_amazon_product_ranking_algorithm_6068-300x118.png\"  data-excerpt=\"Boost your Amazon sales! Understand the A9 &amp; A10 algorithms to optimize product rankings. Learn key factors for visibility &amp; higher conversions.\" href=\"https:\/\/www.aihello.com\/resources\/blog\/amazon-a9-and-a10-algorithms-compared-whats-new-and-how-does-it-affect-your-seo-game\/\">relevance<\/a>, consider adding a threshold ratio of 0.5.<\/p><\/div><h2 id=\"conclusion\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2><p>Using SentenceTransformer 3.0.0 makes training or fine-tuning embedding models a breeze. The new version boasts support for multi-GPU utilization via the DDP method and introduces logging and experimentation features through Weights &amp; Biases. By encapsulating our code within a single main function and executing it with a single command, developers can streamline their workflow significantly.<\/p><p class=\"wp-block-paragraph\">The Evaluator functionality aids in evaluating models during the training phase, catering to defined tasks like Embedding Similarity Search in our scenario. Upon loading the model for inference, it delivers as anticipated, yielding a satisfactory similarity score.<\/p><p class=\"wp-block-paragraph\">This process harnesses the potential of vector embeddings to enhance search results, leveraging user queries and database interactions effectively.<\/p><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Discover how to fine-tune and train Sentence Transformers models for powerful sentence similarity search, leveraging vector embeddings for peak performance.<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"image","meta":{"_gspb_post_css":".gspb_container-id-gsbp-f10279-1,.gspb_container-id-gsbp-f10279-2,.gspb_container-id-gsbp-f10279-3,.gspb_container-id-gsbp-f10279-4{flex-direction:column;box-sizing:border-box}#gspb_container-id-gsbp-f10279-1.gspb_container>p:last-of-type,#gspb_container-id-gsbp-f10279-2.gspb_container>p:last-of-type,#gspb_container-id-gsbp-f10279-3.gspb_container>p:last-of-type,#gspb_container-id-gsbp-f10279-4.gspb_container>p:last-of-type{margin-bottom:0}#gspb_container-id-gsbp-f10279-1.gspb_container.aos-animate,#gspb_container-id-gsbp-f10279-1.gspb_container[data-gs-aos],#gspb_container-id-gsbp-f10279-2.gspb_container.aos-animate,#gspb_container-id-gsbp-f10279-2.gspb_container[data-gs-aos],#gspb_container-id-gsbp-f10279-3.gspb_container.aos-animate,#gspb_container-id-gsbp-f10279-3.gspb_container[data-gs-aos],#gspb_container-id-gsbp-f10279-4.gspb_container.aos-animate,#gspb_container-id-gsbp-f10279-4.gspb_container[data-gs-aos]{opacity:1;transform:translateZ(0)}#gspb_container-id-gsbp-f10279-1.gspb_container,#gspb_container-id-gsbp-f10279-2.gspb_container,#gspb_container-id-gsbp-f10279-3.gspb_container,#gspb_container-id-gsbp-f10279-4.gspb_container{position:relative;transition-duration:.5s;transition-timing-function:var(--gs-root-animation-easing, cubic-bezier(0.42, 0, 0.58, 1));opacity:var(--gs-root-animation-opacity, 0);transition-property:opacity,transform,filter;box-sizing:border-box}","footnotes":""},"categories":[103,85],"tags":[1229,1230],"republish_tag":[],"class_list":["post-10279","post","type-post","status-publish","format-image","hentry","category-machine-learning","category-tips","tag-sbert","tag-training-sbert","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/posts\/10279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/comments?post=10279"}],"version-history":[{"count":1,"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/posts\/10279\/revisions"}],"predecessor-version":[{"id":14263,"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/posts\/10279\/revisions\/14263"}],"wp:attachment":[{"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/media?parent=10279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/categories?post=10279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/tags?post=10279"},{"taxonomy":"republish_tag","embeddable":true,"href":"https:\/\/www.aihello.com\/resources\/wp-json\/wp\/v2\/republish_tag?post=10279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}