本文整理匯總了Python中glove.Glove.most_similar方法的典型用法代碼示例。如果您正苦於以下問題:Python Glove.most_similar方法的具體用法?Python Glove.most_similar怎麽用?Python Glove.most_similar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類glove.Glove
的用法示例。
在下文中一共展示了Glove.most_similar方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: print
# 需要導入模塊: from glove import Glove [as 別名]
# 或者: from glove.Glove import most_similar [as 別名]
print('Collocations: %s' % corpus_model.matrix.nnz)
if args.train:
# Train the GloVe model and save it to disk.
if not args.create:
# Try to load a corpus from disk.
print('Reading corpus statistics')
corpus_model = Corpus.load('corpus.model')
print('Dict size: %s' % len(corpus_model.dictionary))
print('Collocations: %s' % corpus_model.matrix.nnz)
print('Training the GloVe model')
glove = Glove(no_components=100, learning_rate=0.05)
glove.fit(corpus_model.matrix, epochs=int(args.train),
no_threads=args.parallelism, verbose=True)
glove.add_dictionary(corpus_model.dictionary)
glove.save('glove.model')
if args.query:
# Finally, query the model for most similar words.
if not args.train:
print('Loading pre-trained GloVe model')
glove = Glove.load('glove.model')
print('Querying for %s' % args.query)
pprint.pprint(glove.most_similar(args.query, number=10))
示例2: Glove
# 需要導入模塊: from glove import Glove [as 別名]
# 或者: from glove.Glove import most_similar [as 別名]
for line in datafile:
# list of tokenized words
yield line.lower().translate(None, delchars).split(' ')
if __name__ == '__main__':
# initialize glove object
glove = Glove(no_components=100, learning_rate=0.05)
# read in the data to train on; this file is shakespeare text
corpus_model = Corpus()
corpus_model.fit(read_corpus("data/input.txt"), window=10)
# fit the model using the given parameters
glove.fit(corpus_model.matrix, epochs=10, no_threads=1, verbose=True)
# add a dictionary just to make it easier for similarity queries
glove.add_dictionary(corpus_model.dictionary)
# save glove object to file
glove.save_obj('glove.model.obj')
# give me the 5 words most similar to each word in the words list in this
# corpus and show me how similar the words are in this corpus to each word
# in the words list in general
words = ['sky', 'queen', 'car']
for word in words:
glove.most_similar(word, show_hist=False)
示例3: Glove
# 需要導入模塊: from glove import Glove [as 別名]
# 或者: from glove.Glove import most_similar [as 別名]
for line in datafile:
# list of tokenized words
yield line.lower().translate(None, delchars).split(' ')
if __name__ == '__main__':
# initialize glove object
glove = Glove(no_components=100, learning_rate=0.05)
# read in the data to train on; this file is shakespeare text
corpus_model = Corpus()
corpus_model.fit(read_corpus("data/input.txt"), window=10)
# fit the model using the given parameters
glove.fit(corpus_model.matrix, epochs=10, no_threads=1, verbose=True)
# add a dictionary just to make it easier for similarity queries
glove.add_dictionary(corpus_model.dictionary)
# save glove object to file
glove.save_obj('glove.model.obj')
# give me the 5 words most similar to each word in the words list in this
# corpus and show me how similar the words are in this corpus to each word
# in the words list in general
words = ['sky', 'queen', 'car']
for word in words:
glove.most_similar(word, show_hist=True)
示例4: list
# 需要導入模塊: from glove import Glove [as 別名]
# 或者: from glove.Glove import most_similar [as 別名]
import itertools
from gensim.models.word2vec import Text8Corpus
from glove import Corpus, Glove
# for installing text8 corpus you should follow this commands
# wget http://mattmahoney.net/dc/text8.zip -P /tmp
# unzip text8.zip
sentences = list(itertools.islice(Text8Corpus('/tmp/text8'), None))
corpus = Corpus()
corpus.fit(sentences, window=10)
glove = Glove(no_components=100, learning_rate=0.05)
glove.fit(corpus.matrix, epochs=30, no_threads=4, verbose=True)
glove.add_dictionary(corpus.dictionary)
print glove.most_similar('frog', number=10)
print glove.most_similar('girl', number=10)
print glove.most_similar('car', number=10)