コード例 #1
0
ファイル: run_tests.py プロジェクト: peterashwell/honors
# Step 2 - train perceptron for however many rounds on training data
training_data = open("data/engf.train")
sentence = []
poslist = []
true_tags = []
start_time = time.time()
for r in xrange(ROUNDS):
	print "round:", r
	line_num = 0
	for line in training_data:
		if line_num != 0 and line_num % 5000 == 0:
			print "done", line_num, "/", 219552, time.time() - start_time
		line_num += 1	
		line = line.strip()
		if line == '':
			percept.train_greedy(sentence, poslist, true_tags)
			sentence = []
			poslist = []
			true_tags = []
		else:
			line = line.split(' ')
			sentence.append(line[0])
			poslist.append(line[1])
			true_tags.append(line[-1])
	training_data.seek(0)
	percept.finish_round()
training_data.close()
#percept.finish_training()
# Step 3 - classify	
percept.finish_training()
test_data = open("data/eng.testb")