예제 #1
0
def test_rerank_hypotheses(hypotheses, reference, expected_output, metric):
    reranker = rerank.Reranker(metric=metric, return_score=False)

    reranked = reranker.rerank_hypotheses(hypotheses, reference)
    actual_list = reranked.hypotheses

    assert actual_list == expected_output
예제 #2
0
def test_rerank_return_score(hypotheses, reference, expected_scores):
    reranker = rerank.Reranker(metric="bleu", return_score=True)
    hypotheses = {'translations': hypotheses}
    reranked_hypotheses = reranker.rerank(hypotheses, reference)
    assert 'scores' in reranked_hypotheses
    actual_scores = reranked_hypotheses['scores']
    assert np.allclose(actual_scores, expected_scores)
예제 #3
0
def test_rerank_return_score(hypotheses, reference, expected_scores):
    reranker = rerank.Reranker(metric="bleu", return_score=True)

    reranked_with_scores = reranker.rerank_hypotheses(hypotheses, reference)

    actual_scores = reranked_with_scores.scores

    assert np.allclose(actual_scores, expected_scores)
예제 #4
0
def test_rerank_hypotheses(hypotheses, reference, expected_output, metric):
    reranker = rerank.Reranker(metric=metric, return_score=False)
    hypotheses = {
        'sentence_id': 0,
        'translation': '',
        'translations': hypotheses
    }
    reranked_hypotheses = reranker.rerank(hypotheses, reference)
    assert reranked_hypotheses['translations'] == expected_output
예제 #5
0
def test_rerank_top1(hypotheses, reference, expected_best):
    reranker = rerank.Reranker(metric="bleu", return_score=False)

    reranked = reranker.rerank_top1(hypotheses, reference)

    assert len(reranked.hypotheses
               ) == 1, "Rerank top1 should not return more than 1 hypothesis."
    actual_hypothesis = reranked.hypotheses[0]

    assert actual_hypothesis == expected_best
예제 #6
0
def test_rerank_top1_score(hypotheses, reference, expected_best,
                           expected_score):
    reranker = rerank.Reranker(metric="bleu", return_score=True)

    reranked_with_scores = reranker.rerank_top1(hypotheses, reference)

    assert len(reranked_with_scores.hypotheses
               ) == 1, "Rerank top1 should not return more than 1 hypothesis."
    actual_hypothesis = reranked_with_scores.hypotheses[0]
    actual_score = reranked_with_scores.scores[0]

    assert actual_hypothesis == expected_best
    assert np.isclose(actual_score, expected_score)
예제 #7
0
def test_rerank_hypotheses_isometric(source, hypotheses, scores, reference,
                                     expected_output, metric):
    reranker = rerank.Reranker(metric=metric,
                               isometric_alpha=0.5,
                               return_score=False)
    hypotheses = {
        'sentence_id': 0,
        'text': source,
        'translation': '',
        'scores': scores,
        'translations': hypotheses
    }
    reranked_hypotheses = reranker.rerank(hypotheses, reference)
    assert reranked_hypotheses['translations'] == expected_output
예제 #8
0
def test_rerank_return_score(source, hypotheses, reference, expected_scores):
    reranker = rerank.Reranker(metric="bleu",
                               isometric_alpha=0.5,
                               return_score=True)
    hypotheses = {
        'sentence_id': 0,
        'text': source,
        'translation': '',
        'translations': hypotheses
    }
    reranked_hypotheses = reranker.rerank(hypotheses, reference)
    assert 'scores' in reranked_hypotheses
    actual_scores = reranked_hypotheses['scores']
    assert np.allclose(actual_scores, expected_scores)