句子嵌入

数据科学,机器学习(Data Science, Machine Learning)

I came across this simple to use sentence-transformers library when I was recently working on implementing semantic search functionality. As part of this, I had to index the dense vector representation of each document into Elasticsearch for the semantic search to work. With this library, I was able to implement this functionality quickly and effectively. I hope that you will find this article helpful.

当我最近致力于实现语义搜索功能时,我遇到了这个易于使用的sentence-transformers库。 作为其中的一部分,我必须将每个文档的密集矢量表示形式索引到Elasticsearch中,以使语义搜索起作用。 使用该库,我能够快速有效地实现此功能。 希望本文对您有所帮助。

This article requires knowledge of Embeddings (word embeddings or sentence embeddings). You can refer to this article to quickly refresh your memory. If you already know about Embeddings, you can continue reading.

本文需要嵌入知识(单词嵌入或句子嵌入)。 你可以参考这个文章,快速刷新你的记忆。 如果您已经了解嵌入,则可以继续阅读。

安装 (Installation)

pip install -U sentence-transformers

用法 (Usage)

1.句子嵌入(1. Sentence Embedding)

from sentence_transformers import SentenceTransformermodel = SentenceTransformer('model_name_or_path')

In the below example, we have passed a pre-trained model distilbert-base-nli-stsb-mean-tokens to SentenceTransformer for computing the sentence embedding. The full list of pre-trained models is found here. Note that there is no one embedding that could work for all the tasks, so we should try some of these models and select the one which works best.

在下面的示例中,我们将预训练的模型distilbert-base-nli-stsb-mean-tokens传递给SentenceTransformer以计算句子嵌入。 此处提供了预训练模型的完整列表。 请注意,没有一种嵌入可以适用于所有任务,因此我们应该尝试其中一些模型,然后选择最适合的模型。

Note: sentence-transformers models are also hosted on the Huggingface repository. So we can directly use Hugginface’s Transformers library for generating sentence embedding without installing sentence-transformers library. The sample code is given here.

注意sentence-transformers模型也托管在Huggingface信息库中。 因此,我们可以直接使用Hugginface的Transformers库来生成句子嵌入,而无需安装sentence-transformers库。 示例代码在此处给出。

2.语义文本相似性 (2. Semantic Textual Similarity)

Now that we have understood how to generate the sentence embedding, the next step is to compare the sentences for semantic textual similarity and rank them based on the cosine similarity.

现在我们已经了解了如何生成句子嵌入,下一步是比较句子的语义文本相似性,并根据余弦相似度对它们进行排名。

The recommended models for Sentence Similarities are listed below. These models are trained on NLI & STS data and evaluated on the STSbenchmark dataset. The authors recommend the model distilbert-base-nli-stsb-mean-tokens as it gives a perfect balance between speed and performance.

下面列出了句子相似性的推荐模型。 这些模型在NLI和STS数据上进行训练,并在STSbenchmark数据集上进行评估。 作者推荐该模型distilbert-base-nli-stsb-mean-tokens因为它可以在速度和性能之间实现完美的平衡。

roberta-large-nli-stsb-mean-tokens — STSb performance: 86.39roberta-base-nli-stsb-mean-tokens — STSb performance: 85.44bert-large-nli-stsb-mean-tokens — STSb performance: 85.29distilbert-base-nli-stsb-mean-tokens — STSb performance: 85.16

roberta-large-nli-stsb平均令牌— STSb性能:86.39 roberta-base-nli-stsb平均令牌— STSb性能:85.44 bert-large-nli-stsb平均令牌— STSb性能:85.29 distilbert- base-nli-stsb-mean-tokens — STSb性能:85.16

Let’s look at an example of cosine similarity between the sentences we have used in the previous example:

让我们看一下在上一个示例中使用的句子之间的余弦相似度示例:

The method uses a brute-force approach to find the highest-scoring pairs, which has quadratic complexity. For longer sentences, this method is not feasible. Paraphrase Mining which is discussed next is the optimal method.

该方法使用蛮力方法找到得分最高的对,具有二次复杂度。 对于较长的句子,此方法不可行。 接下来讨论的复述挖掘是最佳方法。

3.复述挖掘 (3. Paraphrase Mining)

Paraphrase Mining is used when we need to deal with a large collection of sentences (10,000 and more). A more detailed explanation of Paraphrase Mining is found here.

当我们需要处理大量句子(10,000个及更多)时,将使用复述挖掘。 可在此处找到对复述采矿的更详细说明。

Let’s look at an example using Paraphrase Mining:

让我们来看一个使用复述挖掘的示例:

4.语义搜索 (4. Semantic Search)

Traditional search engines were designed to work with the lexical based search but using semantic search we can find documents based on synonyms. Using the techniques we learned above we can implement semantic search functionality. Semantic search seeks to improve search accuracy by understanding the content of the search query.

传统的搜索引擎被设计用于基于词法的搜索,但是使用语义搜索,我们可以找到基于同义词的文档。 使用我们上面学到的技术,我们可以实现语义搜索功能。 语义搜索旨在通过了解搜索查询的内容来提高搜索准确性。

Semantic search is most commonly used in Search Engines such as Elasticsearch. If you have a basic understanding of Elasticsearch and go through to this link understand how Semantic Search can be implemented Elasticsearch.

语义搜索是最常见的搜索引擎,例如Elasticsearch。 如果您对Elasticsearch有基本的了解,请访问此链接,以了解如何实现Elasticsearch的语义搜索。

结论 (Conclusion)

Hope you have understood how to use the sentence-transformers library for computing sentence embeddings, how to get the similarity between the sentences, and finally how we can make sure of sentence embedding to implement semantic search.

希望您了解如何使用sentence-transformers库来计算句子嵌入,如何获取句子之间的相似度以及最终如何确保句子嵌入以实现语义搜索。

Thank you for reading this article. You can reach me at https://www.linkedin.com/in/chetanambi/

感谢您阅读本文。 您可以通过https://www.linkedin.com/in/chetanambi/与我联系

翻译自: https://medium.com/towards-artificial-intelligence/sentence-embeddings-with-sentence-transformers-library-7420fc6e3815

句子嵌入

http://www.taodudu.cc/news/show-5645762.html

相关文章:

  • 【8014】互联网产品经理,全方位入门,图书推荐
  • 【嵌入式】——嵌入式学习书籍推荐
  • 制作图书馆管理系统的一些缺漏知识点
  • 练手项目一:图书馆CRUD
  • JAVA WEB实现图书管理系统 —— 主页面
  • 域名注册的起名经验交流
  • github入门书籍总结
  • 【C语言】图书管理系统
  • 图书管理网页java_Java个人作业——图书管理系统
  • GOOGLE CHROME 不能打开 FTP 网站解决方法
  • linux重启命令_3条命令重启Linux(另外4种安全方式)
  • linux重启命令 init,Linux 使用init命令实现关机,重启,切换模式
  • Linux 的五个关机重启命令
  • Linux关机和重启的命令
  • [引流源码]:QQ全套扫码加速引流源码分享,全静态 可以做各种扫码加速引流+免费分享
  • wpf硬件加速等级
  • QQ在线多功能签到加速源码
  • QQ多功能加速工具箱源码
  • 技术改变生活——QQ等级计算工具
  • [C#]实现Q+桌面登录满5小时后自动退出(QQ等级加速用)
  • 纯前端vue+bootstrap实现图书管理系统的添加、删除功能
  • luogu P2596 [ZJOI2006]书架
  • P1295 [TJOI2011]书架
  • ZJOI2006书架Treap做法
  • [TJOI2011]书架
  • [ZJOI2006]书架
  • 书架后台
  • 【t012】整理书架
  • 书架问题(动归)
  • spring书架

句子嵌入_带句子转换器库的句子嵌入相关推荐

  1. 单词嵌入_神秘的文本分类:单词嵌入简介

    单词嵌入 Natural language processing (NLP) is an old science that started in the 1950s. The Georgetown I ...

  2. python nlp 句子提取_关于nlp:使用NLTK python进行因果句提取

    我正在从水事故报告中提取因果关系句子.我在这里使用NLTK作为工具.我通过采用20个因果关系句子结构手动创建了regExp语法[请参见下面的示例].构造的语法是以下类型的 grammar = r''' ...

  3. 室内设计优美语句_关于室内设计师的优美句子

    关于室内设计师的优美句子有很多,好句子大全网小编从各类句子中收集整理了关于室内设计师的优美句子,好词好句网特意注明了每一句关于室内设计师的优美句子的作者,详细关于室内设计师的优美句子请查阅下方内容,如 ...

  4. python词嵌入_【自然语言处理】收藏!使用Python的4种句嵌入技术

    人类理解语言细微差别的能力是非常强大的--我们敏锐的大脑可以在一句话里轻易地感受到幽默.讽刺.负面情绪等,但发挥这个"超能力"的前提是,我们必须知道话语所使用的语言. 例如,如果有 ...

  5. C++_泛型编程与标准库(十)——set与map

    C++_泛型编程与标准库(十)--set与map 参考:<侯捷泛化编程与标准库>.GNU9.3.0,vs2019 图中标红部分为自己的笔记理解 SET GNU 9.3.0的set部分代码如 ...

  6. C++_泛型编程与标准库(九)——红黑树的使用

    C++_泛型编程与标准库(九)--红黑树的使用 参考:<侯捷泛化编程与标准库>.GNU9.3.0,vs2019 图中标红部分为自己的笔记理解 struct _Rb_tree_node_ba ...

  7. C++_泛型编程与标准库(八)

    C++_泛型编程与标准库(八) 参考:<侯捷泛化编程与标准库>.GNU9.3.0,vs2019 图中标红部分为自己的笔记理解 1.array GNU 2.9的写法 array GNU9.3 ...

  8. C++_泛型编程与标准库(七)

    C++_泛型编程与标准库(七) 参考:<侯捷泛化编程与标准库>.VC2019 图中标红部分为自己的笔记理解 1.深度探索vector 笔者觉得在最新的VC2019下不是二倍增长,虽然是几何 ...

  9. C++_泛型编程与标准库(六)

    C++_泛型编程与标准库(六) 图中标红部分为自己的笔记理解 1.iterator几个特定属性 vc2019的链表list迭代器部分代码 // CLASS TEMPLATE _List_iterato ...

最新文章

  1. 网络拓扑图一般用什么软件画_视频后期一般用什么软件
  2. js 中的new Image
  3. codeforces82 D. Two out of Three(记忆化搜索)
  4. 网络交换机3大常见故障问题
  5. 运维,你是选择25k的996还是18k的八小时工作日?
  6. 廖雪峰python教程答案
  7. 计算机图形学-样条曲线Spline
  8. windows禅道环境搭建
  9. 模拟电路64(滤波电路)
  10. ACM在线模版-f-zyj
  11. python 分布式 调度 管理_分布式云调度处理系统
  12. 服务器硬盘可以换盘位吗,RAID里的硬盘可以互换槽位吗
  13. 计算机用户组怎么更改权限,win7系统用户组权限怎么设置
  14. Docker版本变化说明
  15. 【蓝桥杯单片机】第十三届蓝桥杯单片机省赛客观题及其题解
  16. TCHAR和string的转换
  17. JS解混淆-AST还原案例
  18. 关于C#英文注释改成中文注释
  19. android 语言对应
  20. 要凉?46%开发者表示短期内不考虑学习区块链技术,拿什么拯救你我的区块链人才荒...

热门文章

  1. android短信数据库类型,安卓短信收发 mmssms.db数据库和查询简介
  2. html如何有立体效果,一段CSS代码让div盒子有立体效果
  3. Delaunay优化算法
  4. 云服务器安装ftp服务端,客户端无法访问
  5. 吴军:机器智能时代,如何成为最先受益的2%?
  6. 数据可视化-D3(V7)交互地图绘制
  7. 大数据必学Java基础(三十):IDEA的使用介绍
  8. 前端 polo-360
  9. 超详细Pyinstaller打包exe+反编译Pyinstaller打包的exe教程+防止反编译教程
  10. 学计算机名言,计算机名人名言