本文整理汇总了Python中decoder.Decoder.print_ranked_results方法的典型用法代码示例。如果您正苦于以下问题:Python Decoder.print_ranked_results方法的具体用法?Python Decoder.print_ranked_results怎么用?Python Decoder.print_ranked_results使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类decoder.Decoder
的用法示例。
在下文中一共展示了Decoder.print_ranked_results方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from decoder import Decoder [as 别名]
# 或者: from decoder.Decoder import print_ranked_results [as 别名]
def main():
import sys
# prepare training data for language model and translation model
sys.path.append('../../clir/')
from aligned_parser import GizaReader
data = GizaReader('../../data/giza/', 'alignment-en-fr')
# instantiate translation model
tm = TranslationModel(data)
# n for n-gram language model
n = 2
# instantiate language model
lm = LanguageModel(n, data)
# alpha for reordering model
alpha = 0.75
# instantiate reordering model
rm = ReorderingModel(alpha)
# decoder_stack_threshold for decoder stacks
decoder_stack_threshold = 5
# the number of results will be produced to output
num_results = 10
translated_src_mask = None
last_translated_index = None
# interactive command line input
print fill("Please enter the full source sentence:", 79)
src_sent = to_unicode_or_bust(raw_input(), sys.stdin.encoding).split()
for i, word in enumerate(src_sent):
print word.encode(sys.stdout.encoding), "(%d)" % i,
print
print fill("Please enter the partial translation:", 79)
partial_tgt_sent = to_unicode_or_bust(raw_input(), sys.stdin.encoding).split()
if partial_tgt_sent != []:
print fill("Which source words were translated?", 79)
translated = list(eval(raw_input()))
translated_src_mask = [ i in translated for i in range(len(src_sent))]
print translated_src_mask
print fill("Which source word is aligned with the last translated word \"%s\"?"
% (partial_tgt_sent[-1]), 79)
last_translated_index = eval(raw_input())
else:
partial_tgt_sent = None
# instantiate a decoder with all the input data collected
decoder = Decoder(lm, rm, tm,
src_sent,
decoder_stack_threshold,
translated_src_mask,
last_translated_index,
partial_tgt_sent )
# invoke decode() method to complete decoding
decoder.decode()
# DEBUG ONLY
# print len(decoder._decoder_stacks[-1].decompose())
# for hypo in decoder.decoder_stacks[-1]:
# print hypo.last_n_targets(len(src_sent)), hypo.partial_score
# print results
print
print fill("Translation suggestions:", 79)
decoder.print_ranked_results(num_results);