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

Function main

nlp_class2/rntn_tensorflow_rnn.py:300–336  ·  view source on GitHub ↗
(is_binary=True)

Source from the content-addressed store, hash-verified

298
299
300def main(is_binary=True):
301 train, test, word2idx = get_ptb_data()
302
303 for t in train:
304 add_idx_to_tree(t, 0)
305 train = [tree2list(t, -1, is_binary) for t in train]
306 if is_binary:
307 train = [t for t in train if t[3][-1] >= 0] # for filtering binary labels
308
309 for t in test:
310 add_idx_to_tree(t, 0)
311 test = [tree2list(t, -1, is_binary) for t in test]
312 if is_binary:
313 test = [t for t in test if t[3][-1] >= 0] # for filtering binary labels
314
315
316
317 train = shuffle(train)
318 # train = train[:5000]
319 # n_pos = sum(t[3][-1] for t in train)
320 # print("n_pos train:", n_pos)
321 test = shuffle(test)
322 smalltest = test[:1000]
323 # n_pos = sum(t[3][-1] for t in test)
324 # print("n_pos test:", n_pos)
325
326 V = len(word2idx)
327 print("vocab size:", V)
328 D = 10
329 K = 2 if is_binary else 5
330
331 model = RecursiveNN(V, D, K)
332 model.fit(train, smalltest, reg=1e-3, epochs=20, train_inner_nodes=True)
333 print("train accuracy:", model.score(train))
334 print("test accuracy:", model.score(test))
335 print("train f1:", model.f1_score(train))
336 print("test f1:", model.f1_score(test))
337
338
339if __name__ == '__main__':

Callers 1

Calls 7

fitMethod · 0.95
scoreMethod · 0.95
f1_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