How to vectorize whole text using fasttext?

Andrey  picture Andrey · Apr 17, 2017 · Viewed 10k times · Source

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?

Answer

Aanchal1103 picture Aanchal1103 · Apr 18, 2017

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