d65344aec745b0cf10dcb6e1a09c1aec3be46f8a,translate.py,,main,#,50

Before Change


    count = 0

    tgtF = open(opt.tgt) if opt.tgt else None
    for line in open(opt.src):

        srcTokens = line.split()
        srcBatch += [srcTokens]
        if tgtF:
            tgtTokens = tgtF.readline().split() if tgtF else None
            tgtBatch += [tgtTokens]

        if len(srcBatch) < opt.batch_size:
            continue

        predBatch, predScore, goldScore = translator.translate(srcBatch, tgtBatch)
 
        predScoreTotal += sum(score[0] for score in predScore)
        predWordsTotal += sum(len(x[0]) for x in predBatch)
        if tgtF is not None:
            goldScoreTotal += sum(goldScore)
            goldWordsTotal += sum(len(x) for x in tgtBatch)

        for b in range(len(predBatch)):
            count += 1
            outF.write(" ".join(predBatch[b][0]) + "\n")

            if opt.verbose:
                srcSent = " ".join(srcBatch[b])
                if translator.tgt_dict.lower:
                    srcSent = srcSent.lower()
                print("SENT %d: %s" % (count, srcSent))
                print("PRED %d: %s" % (count, " ".join(predBatch[b][0])))
                print("PRED SCORE: %.4f" % predScore[b][0])

After Change


    count = 0

    tgtF = open(opt.tgt) if opt.tgt else None
    for line in addone(open(opt.src)):
        
        if line is not None:
            srcTokens = line.split()
            srcBatch += [srcTokens]
            if tgtF:
                tgtTokens = tgtF.readline().split() if tgtF else None
                tgtBatch += [tgtTokens]

            if len(srcBatch) < opt.batch_size:
                continue
        else:
            // at the end of file, check last batch
            if len(srcBatch) == 0:
                break

        predBatch, predScore, goldScore = translator.translate(srcBatch, tgtBatch)
 
        predScoreTotal += sum(score[0] for score in predScore)
        predWordsTotal += sum(len(x[0]) for x in predBatch)
        if tgtF is not None:
            goldScoreTotal += sum(goldScore)
            goldWordsTotal += sum(len(x) for x in tgtBatch)

        for b in range(len(predBatch)):
            count += 1
            outF.write(" ".join(predBatch[b][0]) + "\n")
            outF.flush()

            if opt.verbose:
                srcSent = " ".join(srcBatch[b])
                if translator.tgt_dict.lower:
                    srcSent = srcSent.lower()
                print("SENT %d: %s" % (count, srcSent))
                print("PRED %d: %s" % (count, " ".join(predBatch[b][0])))
                print("PRED SCORE: %.4f" % predScore[b][0])
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 2

Instances


Project Name: OpenNMT/OpenNMT-py
Commit Name: d65344aec745b0cf10dcb6e1a09c1aec3be46f8a
Time: 2017-03-23
Author: liang.huang.sh@gmail.com
File Name: translate.py
Class Name:
Method Name: main


Project Name: tryolabs/luminoth
Commit Name: cf51a68f1cf12b79f4b8c312a6ec694674832e59
Time: 2017-12-04
Author: iangtayler@gmail.com
File Name: luminoth/utils/predicting.py
Class Name:
Method Name: get_predictions


Project Name: tsurumeso/waifu2x-chainer
Commit Name: 035832c8fa5b2078c66d2833a15dc6582e43e142
Time: 2018-11-06
Author: tsurumeso@gmail.com
File Name: lib/iproc.py
Class Name:
Method Name: read_image_rgb_uint8