基本上,我尝试使用自定义的flair语言模型来将单词或句子嵌入到向量中。这是可能的,还是只有在使用flair NER模型时才能使用flair嵌入?
当使用嵌入.embed()函数时,我收到类似于“[−:"pain”pain“Tokens: 1]”的输出,因为我正在寻找连续数字的向量。
谢谢。
发布于 2021-01-19 22:23:48
我很困惑,因为有一个official tutorial on word embeddings by the flair authors themselves,它似乎正好涵盖了这个主题。我猜问题在于您将来自.embed()的处理过的语句对象与所述对象的实际.embedding属性混淆了。
在任何情况下,您都可以简单地迭代单个标记的单词嵌入,如下所示(取自上面提到的教程):
from flair.embeddings import WordEmbeddings
from flair.data import Sentence
# init embedding
glove_embedding = WordEmbeddings('glove')
# create sentence.
sentence = Sentence('The grass is green .')
# embed a sentence using glove.
glove_embedding.embed(sentence)
# now check out the embedded tokens.
for token in sentence:
print(token)
print(token.embedding)我对flair不够熟悉,不知道你是否可以将它应用于任意字符序列,但它对我来说适用于标记。
https://stackoverflow.com/questions/65791903
复制相似问题