All problems
Self-BLEU-1 Similarity
Problem
Compute a BLEU-1 style self-similarity for a list of generated token sequences. For every ordered pair of distinct sequences, treat the first as the hypothesis and the second as the reference, and score it as BP * unigram precision with clipped matches and BP = min(1, exp(1 - reference_length / hypothesis_length)).
Average over all ordered pairs. Return 0.0 when fewer than two sequences are provided, and an empty hypothesis contributes 0.0 for its pairs.
Hint
All ordered pairs count, so pair (i, j) and pair (j, i) can score differently.
Test cases
case 1
in: [[["a","b"],["a","c"]]]
expected: 0.5
case 2
in: [[["a"],["a","b"]]]
expected: 0.43393972058572117
case 3
in: [[["a","a"],["a","a"]]]
expected: 1
case 4
in: [[["a"]]]
expected: 0
case 5
in: [[[],[]]]
expected: 0
Starter codePython
import math
def self_bleu1(sequences):
# Your code here
pass5 test cases · run your code against them in the editor