当前位置: 首页>>代码示例>>Python>>正文


Python sacrebleu.compute_bleu方法代码示例

本文整理汇总了Python中sacrebleu.compute_bleu方法的典型用法代码示例。如果您正苦于以下问题:Python sacrebleu.compute_bleu方法的具体用法?Python sacrebleu.compute_bleu怎么用?Python sacrebleu.compute_bleu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sacrebleu的用法示例。


在下文中一共展示了sacrebleu.compute_bleu方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: calc_bleu_from_stats

# 需要导入模块: import sacrebleu [as 别名]
# 或者: from sacrebleu import compute_bleu [as 别名]
def calc_bleu_from_stats(sentence_stats: pd.DataFrame) -> sacrebleu.BLEU:
    corpus_stats = sentence_stats.sum(axis=0)
    corpus_bleu = sacrebleu.compute_bleu(
        correct=[
            corpus_stats.correct_1_grams,
            corpus_stats.correct_2_grams,
            corpus_stats.correct_3_grams,
            corpus_stats.correct_4_grams,
        ],
        total=[
            corpus_stats.total_1_grams,
            corpus_stats.total_2_grams,
            corpus_stats.total_3_grams,
            corpus_stats.total_4_grams,
        ],
        sys_len=corpus_stats.translation_length,
        ref_len=corpus_stats.reference_length,
    )
    return corpus_bleu 
开发者ID:pytorch,项目名称:translate,代码行数:21,代码来源:bleu_significance.py

示例2: score_cached_corpus

# 需要导入模块: import sacrebleu [as 别名]
# 或者: from sacrebleu import compute_bleu [as 别名]
def score_cached_corpus(self, sent_ids, cached_stats):
    """
    Score a corpus using SacreBLEU score with cache

    Args:
      sent_ids: The sentence ids for reference and output corpora
      cached_stats: A list of cached statistics

    Returns:
      A tuple containing a single value for the SacreBLEU score and a string summarizing auxiliary information
    """
    if len(cached_stats) == 0:
      return 0.0, None

    counts, totals, sys_len, ref_len = zip(*cached_stats)
    counts, totals, sys_len, ref_len = [np.sum(np.array(x)[sent_ids], 0) for x in [counts, totals, sys_len, ref_len]]

    return sacrebleu.compute_bleu(counts, totals, sys_len, ref_len, smooth_method=self.smooth_method, smooth_value=self.smooth_value, use_effective_order=self.use_effective_order).score, None 
开发者ID:neulab,项目名称:compare-mt,代码行数:20,代码来源:scorers.py

示例3: sentence_bleu

# 需要导入模块: import sacrebleu [as 别名]
# 或者: from sacrebleu import compute_bleu [as 别名]
def sentence_bleu(hypothesis, reference):
    bleu = _corpus_bleu(hypothesis, reference)
    for i in range(1, 4):
        bleu.counts[i] += 1
        bleu.totals[i] += 1
    bleu = compute_bleu(
        bleu.counts, bleu.totals,
        bleu.sys_len, bleu.ref_len,
        smooth='exp', smooth_floor=0.0,
    )
    return bleu.score 
开发者ID:pytorch,项目名称:fairseq,代码行数:13,代码来源:score.py

示例4: reduce_metrics

# 需要导入模块: import sacrebleu [as 别名]
# 或者: from sacrebleu import compute_bleu [as 别名]
def reduce_metrics(self, logging_outputs, criterion):
        super().reduce_metrics(logging_outputs, criterion)
        if self.args.eval_bleu:

            def sum_logs(key):
                return sum(log.get(key, 0) for log in logging_outputs)

            counts, totals = [], []
            for i in range(EVAL_BLEU_ORDER):
                counts.append(sum_logs('_bleu_counts_' + str(i)))
                totals.append(sum_logs('_bleu_totals_' + str(i)))

            if max(totals) > 0:
                # log counts as numpy arrays -- log_scalar will sum them correctly
                metrics.log_scalar('_bleu_counts', np.array(counts))
                metrics.log_scalar('_bleu_totals', np.array(totals))
                metrics.log_scalar('_bleu_sys_len', sum_logs('_bleu_sys_len'))
                metrics.log_scalar('_bleu_ref_len', sum_logs('_bleu_ref_len'))

                def compute_bleu(meters):
                    import inspect
                    import sacrebleu
                    fn_sig = inspect.getfullargspec(sacrebleu.compute_bleu)[0]
                    if 'smooth_method' in fn_sig:
                        smooth = {'smooth_method': 'exp'}
                    else:
                        smooth = {'smooth': 'exp'}
                    bleu = sacrebleu.compute_bleu(
                        correct=meters['_bleu_counts'].sum,
                        total=meters['_bleu_totals'].sum,
                        sys_len=meters['_bleu_sys_len'].sum,
                        ref_len=meters['_bleu_ref_len'].sum,
                        **smooth
                    )
                    return round(bleu.score, 2)

                metrics.log_derived('bleu', compute_bleu) 
开发者ID:pytorch,项目名称:fairseq,代码行数:39,代码来源:translation.py

示例5: test_scoring

# 需要导入模块: import sacrebleu [as 别名]
# 或者: from sacrebleu import compute_bleu [as 别名]
def test_scoring(statistics, expected_score):
    score = sacrebleu.compute_bleu(statistics[0].common, statistics[0].total, statistics[1], statistics[2]).score / 100
    assert abs(score - expected_score) < EPSILON 
开发者ID:mjpost,项目名称:sacrebleu,代码行数:5,代码来源:test_bleu.py

示例6: test_degenerate_statistics

# 需要导入模块: import sacrebleu [as 别名]
# 或者: from sacrebleu import compute_bleu [as 别名]
def test_degenerate_statistics(statistics, offset, expected_score):
    score = sacrebleu.compute_bleu(statistics[0].common, statistics[0].total, statistics[1], statistics[2], smooth_method='floor', smooth_value=offset).score / 100
    assert score == expected_score 
开发者ID:mjpost,项目名称:sacrebleu,代码行数:5,代码来源:test_bleu.py

示例7: test_degenerate_statistics

# 需要导入模块: import sacrebleu [as 别名]
# 或者: from sacrebleu import compute_bleu [as 别名]
def test_degenerate_statistics(statistics, offset, expected_score):
    score = sacrebleu.compute_bleu(statistics[0].common, statistics[0].total, statistics[1], statistics[2],
                                   smooth_method='floor', smooth_value=offset).score / 100
    assert score == expected_score 
开发者ID:awslabs,项目名称:sockeye,代码行数:6,代码来源:test_bleu.py


注:本文中的sacrebleu.compute_bleu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。