Flairで文をembedding

from flair.data import Sentence
from flair.embeddings import CharacterEmbeddings

# init embedding
embedding = CharacterEmbeddings()

# create a sentence
sentence = Sentence('Thegrassisgreen.')

# embed words in sentence
embedding.embed(sentence)

>> sentence[0].embedding
tensor([-0.1791, -0.3325, -0.0258,  0.1107,  0.0461, -0.1355,  0.1788,  0.2209,
        -0.0489, -0.0991, -0.0333, -0.0932, -0.2200,  0.0294,  0.0747,  0.2146,
        -0.0232, -0.2907, -0.0741, -0.0350,  0.1146, -0.0481, -0.1900, -0.1427,
        -0.0726,  0.0602,  0.1475, -0.0538,  0.1749,  0.0477, -0.0310,  0.0537,
         0.0026, -0.0469, -0.1125,  0.1101, -0.0472, -0.0446,  0.1157, -0.0930,
        -0.1663,  0.0533,  0.0871, -0.0581, -0.0065,  0.1710, -0.0731, -0.0228,
        -0.1548, -0.0248], grad_fn=<CatBackward>)

Flair

Posted by vastee