Nlp 使用预训练的Bert,Elmo获得两个单词之间的相似性分数
我试图使用预先训练好的维基模型,根据两个单词之间的相似性来比较Glove、Fasttext、Bert和Elmo。Glove和Fasttext具有预先训练的模型,可以轻松地与python中的gensim word2vec一起使用。Elmo和Bert有这样的模型吗?以下是使用Tensorflow上可用的Elmo模型并比较两个字符串之间相似性的python代码:Nlp 使用预训练的Bert,Elmo获得两个单词之间的相似性分数,nlp,gensim,word2vec,word-embedding,elmo,Nlp,Gensim,Word2vec,Word Embedding,Elmo,我试图使用预先训练好的维基模型,根据两个单词之间的相似性来比较Glove、Fasttext、Bert和Elmo。Glove和Fasttext具有预先训练的模型,可以轻松地与python中的gensim word2vec一起使用。Elmo和Bert有这样的模型吗?以下是使用Tensorflow上可用的Elmo模型并比较两个字符串之间相似性的python代码: import tensorflow_hub as hub import tensorflow as tf elmo = hub.Modul
import tensorflow_hub as hub
import tensorflow as tf
elmo = hub.Module("https://tfhub.dev/google/elmo/2", trainable=True)
def elmo_vectors(x):
embeddings = elmo(x, signature="default", as_dict=True)["elmo"]
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(tf.tables_initializer())
# return average of ELMo features
return sess.run(tf.reduce_mean(embeddings,1))
dist=spatial.distance.cosine(elmo_vectors(["partner"]),elmo_vectors(["vendor"]))