- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要实现的目标是找到一个好的 word_and_phrase 嵌入模型,它可以做到:(1) 对于我感兴趣的词和短语,它们有嵌入。(2) 我可以使用嵌入来比较两个事物(可以是单词或短语)之间的相似度
到目前为止我已经尝试了两条路:
1:一些Gensim加载的预训练模型,例如:
from gensim.models.word2vec import Word2Vec
import gensim.downloader as api
# download the model and return as object ready for use
model_glove_twitter = api.load("fasttext-wiki-news-subwords-300")
model_glove_twitter.similarity('computer-science', 'machine-learning')
这个路径的问题是我不知道一个短语是否有嵌入。对于这个例子,我得到了这个错误:
KeyError: "word 'computer-science' not in vocabulary"
我将不得不尝试不同的预训练模型,例如 word2vec-google-news-300、glove-wiki-gigaword-300、glove-twitter-200 等。结果相似,总有感兴趣的短语没有嵌入。
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('distilbert-base-nli-mean-tokens')
from scipy.spatial.distance import cosine
def cosine_similarity(embedding_1, embedding_2):
# Calculate the cosine similarity of the two embeddings.
sim = 1 - cosine(embedding_1, embedding_2)
print('Cosine similarity: {:.2}'.format(sim))
phrase_1 = 'baby girl'
phrase_2 = 'annual report'
embedding_1 = model.encode(phrase_1)
embedding_2 = model.encode(phrase_2)
cosine_similarity(embedding_1[0], embedding_2[0])
使用这种方法,我能够为我的短语获得嵌入,但相似度得分为 0.93,这似乎不太合理。
那么我还能尝试什么来实现上述两个目标呢?
最佳答案
第一个路径的问题是您正在加载像 word2vec 嵌入这样的 fastText 嵌入,而 word2vec 无法处理 Out Of Vocabulary 单词。
好处是 fastText 可以管理 OOV 词。您可以使用 Facebook 原始实现(pip install fasttext
)或 Gensim 实现。
例如,使用 Facebook 实现,您可以:
import fasttext
import fasttext.util
# download an english model
fasttext.util.download_model('en', if_exists='ignore') # English
model = fasttext.load_model('cc.en.300.bin')
# get word embeddings
# (if instead you want sentence embeddings, use get_sentence_vector method)
word_1='computer-science'
word_2='machine-learning'
embedding_1=model.get_word_vector(word_1)
embedding_2=model.get_word_vector(word_2)
# compare the embeddings
cosine_similarity(embedding_1, embedding_2)
关于nlp - 寻找有效的 NLP Phrase Embedding 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63843793/
我想用 phrase 搜索和替换任何出现的 {phrase}使用 rails(erb.html 文件)。需要替换多个短语,并且事先不知道这些短语。 完整示例: Hi {guys}, I really
如果您在内容辅助激活时开始输入,内容辅助将仅根据起始字母过滤建议。 然而,假设有一个对象,我们需要查看它的任何方法是否在其名称的任何部分包含特定的短语(不仅仅是检查它们是否以该短语开头)。 有什么方法
我需要在名为 blog 的集合中搜索文档,该集合具有为标题、标签、摘要和正文定义的文本索引: @Document(collection="blog") public class Blog {
我需要在名为 blog 的集合中搜索文档,该集合具有为标题、标签、摘要和正文定义的文本索引: @Document(collection="blog") public class Blog {
我在 win 32 上运行 Python 2.5(r25:51908,2006 年 9 月 19 日,09:52:17)[MSC v.1310 32 位(英特尔)] 当我问 Python 时 >>>
我试图从一个长文本中提取一系列全部大写的单词。因此,在示例中: Here is a couple words of text. If you want more information please
我已经使用 StandandAnalyzer 实现了 RamDirectory,并将位置数据存储在 Lucene 缓存中,我已在 Lucene 中添加了数据,如下所示: final Document
好的,我有大约 68,000 个表需要用特定短语删除。当我运行命令时: 显示表,其中 table_name like '%phrase'; 我得到了我需要的所有结果,但我尝试运行以下代码,但它只删除了
我使用 ElasticSearch 5.1.2 作为 Heroku 的 Searchly 插件,带有 nodeJS 包 ( https://github.com/elastic/elasticsear
我有一个 Elasticsearch 索引,其中包含一些数据。我实现了 did-you-mean 功能,因此当用户写错拼写的内容时,它可以收到包含正确单词的建议。 我使用短语 suggester 是因
我正在寻找一种在 KDB 中编写功能选择的方法,以便仅当列存在时才应用 where 短语(为了避免错误)。如果该列不存在,则默认为 true。 我试过了,没用 enlist(|;enlist(in;`
目前,我在 JavaScript 中使用以下正则表达式来匹配和计算字符串中的单词。与此 ReEx 完美配合: 正则表达式: var pickRegExp = /[^\W\d]+[\u00C0-\u01
在 elasticsearch 中,我正在构建过滤查询以查找包含 的文档。两个一个短语和一个术语。以下查询不起作用。它似乎使用查询数组中的项目返回结果,但好像应用了“或”运算符。 编辑:由于我使用的是
我创建了两个相等的api,就像从Elastic搜索中搜索filelds一样: 例如:如果 flex 搜索中的“queuename”字段具有诸如queue,queue1,queue2和3queue之类的
elastic search suggestor 不删除不需要的空间使用的查询... POST /_search { "_source": false, "suggest": { "t
我的一位客户是一家专门从事新闻摄影(嗯,还有八卦)的摄影机构,因此他们的许多客户的搜索都围绕着特定的人展开。 我们索引了大约 150 万个文档,对标题和标题进行全文搜索;和全文搜索,无需词干标签。我们
我正在尝试深入研究以下的 GNU Prolog 行为: test(X,I,O) :- phrase(X,I,O). ?- test(("a",!,"b"),"ab",""). 有没有标准的方法来查看
我有一个充满短语(80-100 个字符)和一些较长文档(50-100Kb)的数据库,我想要给定文档的短语排名列表;而不是搜索引擎的通常输出,而是给定短语的文档列表。 我以前用过MYSQL全文索引,也研
我想要实现的目标是找到一个好的 word_and_phrase 嵌入模型,它可以做到:(1) 对于我感兴趣的词和短语,它们有嵌入。(2) 我可以使用嵌入来比较两个事物(可以是单词或短语)之间的相似度
我正在寻找一种从文本文档中提取“重要短语”的方法。希望使用 Spacy 做到这一点,但有一个警告:我的数据主要包含产品信息,因此重要的短语与自然口语中的短语不同。出于这个原因,我想在我自己的语料库上训
我是一名优秀的程序员,十分优秀!