本文整理汇总了Python中Tree.load_trees方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.load_trees方法的具体用法?Python Tree.load_trees怎么用?Python Tree.load_trees使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.load_trees方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fit
# 需要导入模块: import Tree [as 别名]
# 或者: from Tree import load_trees [as 别名]
def fit(self, training_file, output_file, word_map_file='word_map.bin'):
if not os.path.exists(word_map_file):
tr.build_word_map(training_file, word_map_file)
self.word_map_file = word_map_file
self.trees = tr.load_trees(self.data_folder + training_file, self.word_map_file)
self.num_words = len(tr.load_word_map(self.word_map_file))
self.rntn = RNTN.RNTN(self.vect_dim, self.output_dim, self.num_words, self.mini_batch_size)
self.sgd = SGD.SGD(self.rntn, self.learning_rate, self.mini_batch_size)
for e in range(self.optim_epochs):
# Fit model
# --------------------------
start = time.time()
print "Running epoch %d" % e
self.sgd.optimize(self.trees)
end = time.time()
print "\nTime per epoch : %f" % (end-start)
# Save model specifications
with open(output_file, 'w+') as fid:
pickle.dump([(i, self.values[i]) for i in self.args][1:], fid)
pickle.dump(self.sgd.cost_list, fid)
pickle.dump(self.rntn.stack, fid)
示例2: test
# 需要导入模块: import Tree [as 别名]
# 或者: from Tree import load_trees [as 别名]
def test(self, specs_file, data_test_file):
trees = tr.load_trees(self.data_folder + data_test_file)
assert specs_file is not None, "Please provide a model to test."
with open(specs_file, 'r') as fid:
_ = pickle.load(fid)
_ = pickle.load(fid)
rntn = RNTN.RNTN(self.output_dim, self.num_words, self.mini_batch_size)
rntn.stack = pickle.load(fid)
print "Testing..."
cost, correct, total = rntn.cost_and_gradients(trees, test=True)
print "\nCost : :%f \nCorrectly labelled : %d/%d \nAccuracy : %f." % (cost, correct, total, correct / float(total))