To get vector of a word, I can use:
model["word"]
but if I want to get the vector of a sentence, I need to either sum vectors of all words or get average of all vectors.
Does FastText provide a method to do this?
To get vector of a word, I can use:
model["word"]
but if I want to get the vector of a sentence, I need to either sum vectors of all words or get average of all vectors.
Does FastText provide a method to do this?
If you want to compute vector representations of sentences or paragraphs, please use:
$ ./fasttext print-sentence-vectors model.bin < text.txt
This assumes that the text.txt file contains the paragraphs that you want to get vectors for. The program will output one vector representation per line in the file.
This has been clearly mentioned in the README of fasttext repo. https://github.com/facebookresearch/fastText
You can use python wrapper also. Install it using official install guide from here: https://fasttext.cc/docs/en/python-module.html#installation
And after that:
import fasttext
model = fasttext.load_model('model.bin')
vect = model.get_sentence_vector("some string") # 1 sentence
vect2 = [model.get_sentence_vector(el.replace('\n', '')) for el in text] # for text
To get vector for a sentence using fasttext, try the following command
$ echo "Your Sentence Here" | ./fasttext print-sentence-vectors model.bin
For an example on this, refer Learn Word Representations In Fasttext
© 2022 - 2024 — McMap. All rights reserved.