예제 #1
0
    optparser.add_option("-f", "--print-features", dest="print_features", action="store_true", \
                         help="print all features (id=val)", default=False)
    optparser.add_option("-c", "--nocheck", dest="check_feats", action="store_false", \
                         help="do not check feats (default is to check)", default=True)
    optparser.add_option("-v", "--verbose", dest="verbose", action="store_true", \
                         help="print result for each sentence", default=False)
    optparser.add_option("-d", "--debug", dest="debug", action="store_true", \
                         help="print result for each sentence", default=False)
    optparser.add_option("-b", "", dest="budecoder", action="store_true", \
                         help="print result for each sentence", default=False)
    optparser.add_option("", "--defaultnbest", dest="defaultnbest", help="default nbests", metavar="FILE", default=None)

    (opts, args) = optparser.parse_args()

    if opts.weights is not None:
        weights = get_weights(opts.weights)
    else:
        weights = Vector("lm1=2 gt_prob=1")

    extra_feats = None # prep_features(args)        

    decoder = LocalDecoder() #BUDecoder(opts.k, extra_feats, check_feats=False)
    decoder.set_feats(extra_feats)
    
    all_pp = Bleu()  # Parseval(), now BLEU
    decode_time, parseval_time = 0, 0
    sum_score = 0
    
    if opts.defaultnbest:
        defaultnbests = defaultdict(lambda : [])
        for line in open(opts.defaultnbest):
예제 #2
0
##    decoder = [NBestDecoder(opts.N), \
##               LocalDecoder(), \
##               BUDecoder(opts.k, check_feats=False, adaptive_base=opts.adaptive)]\
##               [opts.mode]

    decoder = LocalDecoder(opts.hope)
    print >> logs, "decoder = %s" % decoder

    ### must read forest first! otherwise slow!
#     forests = []
#     for forest in decoder.load("-"):
#         forests.append(forest)

    if opts.weightsfile is not None:
        weights = get_weights(opts.weightsfile) # see forest.py
    else:
        weights = Vector("lm1=2 gt_prob=1")  ## initial vector
        
    initial_weights = weights.__copy__()

    extra_feats = None #prep_features(args)

    decoder.set_feats(extra_feats)
    all_feats = extra_feats

    if opts.trainfile == "-":
        trainforests = []
        for forest in decoder.load(opts.trainfile):
            decoder.do_oracle(forest, weights)
            trainforests.append(forest)