-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtraining.py
60 lines (44 loc) · 1.77 KB
/
training.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from pprint import pprint
from model_config import *
from model_defs import *
from model_use import *
###############################################
# Load the data #
###############################################
config = base_convo_config(input_features, l1_list, tag_list)
train_data = read_data(train_file, features, config)
dev_data = read_data(dev_file, features, config)
dev_spans = treat_spans(dev_spans_file)
config.make_mappings(train_data + dev_data)
if config.init_words:
word_vectors = read_vectors(vecs_file, config.feature_maps['word']['reverse'])
pre_trained = {'word': word_vectors}
else:
pre_trained = {}
params = Parameters(init=pre_trained)
###############################################
# make and test the NN #
###############################################
graph = tf.Graph()
sess = tf.InteractiveSession()
(inputs, targets, preds_layer, criterion, accuracy) = make_network(config, params)
train_step = tf.train.AdagradOptimizer(config.learning_rate).minimize(criterion)
sess.run(tf.initialize_all_variables())
accuracies, preds = train_model(train_data, dev_data, inputs, targets,
train_step, accuracy, config, params, graph)
predictions = [fuse_preds(sent, pred, config)
for sent, pred in zip(dev_data, preds[config.num_epochs])]
merged = merge(predictions, dev_spans)
if True:
print '##### Parameters'
pprint(config.to_string().splitlines())
print '##### Train/dev accuracies'
pprint(accuracies)
print '##### P-R-F curves'
for i in range(10):
evaluate(merged, 0.1 * i)
#~ execfile('training.py')
# code to assign computation nodes:
#~ graph = tf.Graph()
#~ with graph.as_default():
#~ with graph.device(device_for_node):