Ejemplo n.º 1
0
        for tgt, pred, topic in zip(tgt_fr, pred_fr, topic_fr):
            topic = eval(topic)
            tgt = tgt.strip("\n")
            tgt = tgt.replace("<SOS> ", "")
            tgt = tgt.replace(" <EOS>", "")

            pred = pred.strip("\n").split("\t")[0]
            # print(pred)
            pred = pred.replace("<SOS> ", "")
            pred = pred.replace(" <EOS>", "")

            for k, v in topic.items():
                tgt = tgt.replace(k, v)
                pred = pred.replace(k, v)
            pred_tokens = pred.strip().split(" ")
            gold_tokens = tgt.strip().split(" ")
            sents.append([pred_tokens, gold_tokens])
        # calc f1
        f1 = calc_f1(sents)
        # calc bleu
        bleu1, bleu2 = calc_bleu(sents)
        # calc distinct
        distinct1, distinct2 = calc_distinct(sents)
        score = f1 + bleu1 + bleu2
        output_str = "Score: %.2f%%\n" % (score * 100)
        output_str += "F1: %.2f%%\n" % (f1 * 100)
        output_str += "BLEU1: %.3f%%\n" % bleu1
        output_str += "BLEU2: %.3f%%\n" % bleu2
        output_str += "DISTINCT1: %.3f%%\n" % distinct1
        output_str += "DISTINCT2: %.3f%%\n" % distinct2
        logger.info(output_str)
Ejemplo n.º 2
0
def compute_distinct2(p, s):
    d1, d2 = calc_distinct([[p.split(), s.split()]])
    return d2