Reputation: 1
I am trying to load the FastText and save that as a model so that I can deploy that on production as the file size is 1.2 gb and wont be a good practice to use that on Prod. Can anyone suggest an approach to save and load the model for production ("fasttext-wiki-news-subwords-300") Loading the file using gensim.downloader api
Upvotes: 0
Views: 1294
Reputation: 54183
In order to have clarity over exactly what you're getting, in what format, I strongly recommend downloading things like sets of pretrained vectors from their original sources rather than the Gensim gensim.downloader
convenience methods. (That API also, against most users' expectations & best packaging hygeine, will download & run arbitrary other code that's not part of Gensim's version-controlled source repository or its official PyPI package. See project issue #2283.)
For example, you could grab the raw vectors files direct from: https://fasttext.cc/docs/en/english-vectors.html
The tool from ~david-dale's answer looks interesting, for its radical compression, and if you can verify the compressed versions still work well for your purposes, it may be an ideal approach for memory-limited production deployments.
I would also consider:
Word2Vec
(though that may need some adaptation for FastText
& recent Gensim versions).limit
option of load_word2vec_format()
. For exmaple:# save only the word-vectors from a FastText model
ft_model.wv.save_word2vec_format('wvonly.txt', binary=False)
# ... then, later/elsewhere:
# load only 1st 50,000 word-vectors
wordvecs = KeyedVectors.load_word2vec_format('wvonly.txt', binary=False, limit=50000)
Upvotes: 0
Reputation: 11424
You can use the library https://github.com/avidale/compress-fasttext, which is a wrapper around Gensim that can serve compressed versions of unsupervised FastText models. The compressed versions can be orders of magnitude smaller (e.g. 20mb), with a tolerable loss in quality.
Upvotes: 1