Spaces based on Gensim Model
HI there,I currently have a trained FastText model available which was trained using Gensim. Is it possible to host this model on the Huggingface Model Hub as well as create a corresponding HF Space for users to interactively try out the vector space that is created by it?Best,Simon
2022-02-17T08:29:17Z
Hi Simon!Yes, you can host this model on the Hub and create a Space for it. We actually already host a couple of fasttext models on the Hub, which you can find atModels - Hugging Face.Hellisotherpeople/debate2vec · Hugging Faceshows nearest neighbor in the widgetosanseviero/fasttext_embedding · Hugging Faceshows feature extraction/embedding.You can of course create spaces which are significantly more interactive than the widgets.
2022-02-17T10:51:22Z
Hi Omar, thanks for the quick response.I already got started to create a model repo (simonschoe/earningscall2vec · Hugging Face) in the spirit ofHellisotherpeople/debate2vec · Hugging Face, i.e., with the widget that allows to extract NN. However, the widget is not quite working yet in my repo. I presume its due to the model format being.modelinstead of.bin.So when usinggensimand saving a model to disk (viaFasttext.save()), it writes four files to disk:mod.modelmod.model.syn1neg.npymod.model.wv.vectors_ngrams.npymod.model.wv.vectors_vocab.npyAny idea which one of these must be pushed to the hub in order for the widget to be compatible with the model file?EDIT: I figured it out and used thegensimsave_facebook_model()to save the model in.binformat (and renamed itmodel.bin). However, the final model is 2.5gb in size. Is there a maximum model size with regard to the model hub and repo storage?
2022-02-17T12:32:30Z
No, 2.5gb sounds right for Fasttext models, they tend to be quite large. And indeed,model.binis the right approach. Just take into account that since the models are large, inference and loading will usually be slow.
2022-02-17T12:32:51Z
Out of curiosity, what’s the size of the original.modelfiles?
2022-02-17T13:10:53Z
The.modelfile is 2mb in size, however, the three.npyfiles amount to ~2,5gb as well, yielding roughly the same (if not exact same) model size.If you say loading and inference is slow: Is there any chance to speed it up somehow? (e.g., by trimming or freezing the model before pushing it to the hub?) I find it counterintuitive that they are bigger in size than some pretrained transformer models…
2022-02-17T13:42:38Z
Let’s try it out directly in the widget!One last thing is that the model is expected to be located in 404 Client Error: Not Found for url:https://huggingface.co/simonschoe/earningscall2vec/resolve/main/model.bin(so it should bemodel.bin). The INference API will load the model and cache results, so after the first inference call, it should definitively work much faster.
2022-02-18T08:04:21Z
I finally have it up and running and everything works as intended(simonschoe/call2vec · Hugging Face)One last question: Is it possible to adjust the query so it does return the top 10 NN instead of just the top 5?
2022-02-18T08:54:49Z
Hey there!We don’t have this at the moment, but we can open a PR athuggingface_hub/text_classification.py at main · huggingface/huggingface_hub · GitHubif you want to enabletop_kas an argument. Here is an issue:https://github.com/huggingface/huggingface_hub/issues/693
2022-02-18T09:42:10Z
Great, thanks a lot! Let’s see if/when this is implemented.Thanks for all the help so far!
2022-02-21T18:27:05Z
FastText-like models are bigger than many transformers, because a typical transformer has vocabulary of about 30’000 tokens, while a typical FastText model remembers embeddings for 2’000’000 hashed n-grams and for 100’000 to 300’000 words.But fastText models can be compressed (with some loss of accuracy). The native FastText library supports compression of supervised models (for classification), and there is a library that wraps around Gensim,GitHub - avidale/compress-fasttext: Tools for shrinking fastText models (in gensim format), that can compress unsupervised fastText models for feature extraction.