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

Function main

nlp_class2/recursive_theano.py:251–294  ·  view source on GitHub ↗
(is_binary=True)

Source from the content-addressed store, hash-verified

249
250
251def main(is_binary=True):
252 train, test, word2idx = get_ptb_data()
253
254 for t in train:
255 add_idx_to_tree(t, 0)
256 train = [tree2list(t, -1, is_binary) for t in train]
257 if is_binary:
258 train = [t for t in train if t[3][-1] >= 0] # for filtering binary labels
259
260 # sanity check
261 # check that last node has no parent
262 # for t in train:
263 # assert(t[1][-1] == -1 and t[2][-1] == -1)
264
265 for t in test:
266 add_idx_to_tree(t, 0)
267 test = [tree2list(t, -1, is_binary) for t in test]
268 if is_binary:
269 test = [t for t in test if t[3][-1] >= 0] # for filtering binary labels
270
271 train = shuffle(train)
272 # train = train[:2000]
273 n_pos = sum(t[3][-1] for t in train)
274 # print("num pos train:", n_pos)
275 # idx2word = {v:k for k, v in word2idx.items()}
276 # for i in range(4):
277 # words, _, _, labels = train[i]
278 # print_sentence(words, idx2word)
279 # print("label:", labels[-1])
280 test = shuffle(test)
281 test = test[:1000]
282
283 V = len(word2idx)
284 print("vocab size:", V)
285 D = 10
286 K = 2 if is_binary else 5
287
288 model = RecursiveNN(V, D, K)
289 model.fit(train, learning_rate=1e-2, reg=1e-2, mu=0, epochs=20, activation=T.tanh, train_inner_nodes=False)
290 print("train accuracy:", model.score(train))
291 print("test accuracy:", model.score(test))
292
293 # make sure program doesn't end until we close the plot
294 plt.show()
295
296
297if __name__ == '__main__':

Callers 1

Calls 6

fitMethod · 0.95
scoreMethod · 0.95
get_ptb_dataFunction · 0.90
add_idx_to_treeFunction · 0.70
tree2listFunction · 0.70
RecursiveNNClass · 0.70

Tested by

no test coverage detected