How to find similar words with FastText?

前端 未结 5 1682
清酒与你
清酒与你 2021-02-08 18:41

I am playing around with FastText, https://pypi.python.org/pypi/fasttext,which is quite similar to Word2Vec. Since it seems to be a pretty new library

相关标签:
5条回答
  • 2021-02-08 19:02

    Use gensim,

    from gensim.models import FastText
    
    model = FastText.load(PATH_TO_MODEL)
    model.wv.most_similar(positive=['dog'])
    

    More info here

    0 讨论(0)
  • 2021-02-08 19:04

    You can install and import gensim library and then use gensim library to extract most similar words from the model that you downloaded from FastText.

    Use this:

    import gensim
    model = gensim.models.KeyedVectors.load_word2vec_format('model.vec')
    similar = model.most_similar(positive=['man'],topn=10)
    

    And by topn parameter you get the top 10 most similar words.

    0 讨论(0)
  • 2021-02-08 19:07

    You should use gensim to load the model.vec and then get similar words:

    m = gensim.models.Word2Vec.load_word2vec_format('model.vec')
    m.most_similar(...)
    
    0 讨论(0)
  • 2021-02-08 19:20

    Use Gensim, load fastText trained .vec file with load.word2vec models and use most_similiar() method to find similar words!

    0 讨论(0)
  • 2021-02-08 19:20

    You can install pyfasttext library to extract the most similar or nearest words to a particualr word.

    from pyfasttext import FastText
    model = FastText('model.bin')
    model.nearest_neighbors('dog', k=2000)
    

    Or you can get the latest development version of fasttext, you can install from the github repository :

    import fasttext
    model = fasttext.load_model('model.bin')
    model.get_nearest_neighbors('dog', k=100)
    
    0 讨论(0)
提交回复
热议问题