自作ELMoで単語をEmbeddingした後,Numpyに戻す[Flair][NLP]

8月 9, 2020

from flair.embeddings import ELMoEmbeddings
from flair.data import Sentence
# ELMoのモデルは各自で用意
options = '/home/ubuntu/elmo-embeddings/elmo_options.json'
weights = '/home/ubuntu/elmo-embeddings/elmo_weights.hdf5'
elmo = ELMoEmbeddings('custom', options_file = options, weight_file = weights)
sentence = Sentence("dog")
elmo.embed(sentence)
sentence[0].get_embedding().cpu().numpy()
>> array([ 0.34018415, -0.6037901 ,  0.16949204, ...,  0.5858401 , 0.78186303,  1.0128772 ], dtype=float32)

Flair

Posted by vastee