MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / train_wikipedia

Function train_wikipedia

rnn_class/wiki.py:139–153  ·  view source on GitHub ↗
(we_file='word_embeddings.npy', w2i_file='wikipedia_word2idx.json', RecurrentUnit=GRU)

Source from the content-addressed store, hash-verified

137
138
139def train_wikipedia(we_file='word_embeddings.npy', w2i_file='wikipedia_word2idx.json', RecurrentUnit=GRU):
140 # there are 32 files
141 ### note: you can pick between Wikipedia data and Brown corpus
142 ### just comment one out, and uncomment the other!
143 # sentences, word2idx = get_wikipedia_data(n_files=100, n_vocab=2000)
144 sentences, word2idx = get_sentences_with_word2idx_limit_vocab()
145
146 print("finished retrieving data")
147 print("vocab size:", len(word2idx), "number of sentences:", len(sentences))
148 rnn = RNN(30, [30], len(word2idx))
149 rnn.fit(sentences, learning_rate=1e-5, epochs=10, show_fig=True, activation=T.nnet.relu)
150
151 np.save(we_file, rnn.We.get_value())
152 with open(w2i_file, 'w') as f:
153 json.dump(word2idx, f)
154
155def find_analogies(w1, w2, w3, we_file='word_embeddings.npy', w2i_file='wikipedia_word2idx.json'):
156 We = np.load(we_file)

Callers 1

wiki.pyFile · 0.70

Calls 4

fitMethod · 0.95
RNNClass · 0.70
saveMethod · 0.45

Tested by

no test coverage detected