# coding: utf-8 import sys sys.path.append('..') from common.util import most_similar, analogy import pickle pkl_file = '../../chap4/cbow_params.pkl' # pkl_file = 'skipgram_params.pkl' with open(pkl_file, 'rb') as f: params = pickle.load(f) word_vecs = params['word_vecs'] word_to_id = params['word_to_id'] id_to_word = params['id_to_word'] # 가장 비슷한(most similar) 단어 뽑기 querys = ['you', 'year', 'car', 'toyota'] for query in querys: most_similar(query, word_to_id, id_to_word, word_vecs, top=5) # 유추(analogy) 작업 print('-' * 50) analogy('king', 'man', 'queen', word_to_id, id_to_word, word_vecs) analogy('take', 'took', 'go', word_to_id, id_to_word, word_vecs) analogy('car', 'cars', 'child', word_to_id, id_to_word, word_vecs) analogy('good', 'better', 'bad', word_to_id, id_to_word, word_vecs)
import sys sys.path.append('..') from common.util import preprocess, create_co_matrix, most_similar text = 'You say goodbye and I say hello' corpus, word_to_id, id_to_word = preprocess(text) vocab_size = len(word_to_id) C = create_co_matrix(corpus, vocab_size) most_similar('you', word_to_id, id_to_word, C, top=5)
import sys sys.path.append("..") from common.util import preprocess, create_co_matrix, most_similar text = "You say goodbye and I say hello." corpus, word_to_id, id_to_word = preprocess(text) vocab_size = len(word_to_id) C = create_co_matrix(corpus, vocab_size) most_similar("you", word_to_id, id_to_word, C, top=5)