def print_attention_values(self, input_file, test_inputs, output_file):
onto_aware = True
sent1_attention_outputs = self.get_attention(test_inputs[0])
sent2_attention_outputs = self.get_attention(test_inputs[1])
tagged_sentences = [x.strip().split("\t")[1] for x in codecs.open(input_file).readlines()]
outfile = codecs.open(output_file, "w", "utf-8")
for sent1_attention, sent2_attention, tagged_sentence in zip(sent1_attention_outputs, sent2_attention_outputs, tagged_sentences):
print >>outfile, tagged_sentence
print >>outfile, "Sentence 1:"
for word_attention in sent1_attention:
for sense_attention in word_attention:
print >>outfile, " ".join(["%s:%f" % (hyp, hyp_att) for hyp, hyp_att in sense_attention])
print >>outfile
print >>outfile, "\nSentence 2:"
for word_attention in sent2_attention:
for sense_attention in word_attention:
print >>outfile, " ".join(["%s:%f" % (hyp, hyp_att) for hyp, hyp_att in sense_attention])
print >>outfile
outfile.close()
评论列表
文章目录