All problems
Distinct-1 and Distinct-2 Diversity
Problem
Measure generation diversity over a list of token sequences. Pool all unigrams across sequences, and count bigrams only within each sequence without crossing its boundary.
Return [distinct-1, distinct-2], where each is the number of unique items divided by the total number of items of that order. A zero denominator gives 0.0 for that order.
Hint
Bigrams must stay inside their own sequence; unigrams pool across the whole batch.
Test cases
case 1
in: [[["a","b","c"]]]
expected: [1,1]
case 2
in: [[["a","a","a"]]]
expected: [0.3333333333333333,0.5]
case 3
in: [[["a","b"],["a","b"]]]
expected: [0.5,0.5]
case 4
in: [[]]
expected: [0,0]
case 5
in: [[["a"],[]]]
expected: [1,0]
Starter codePython
def distinct_1_2(sequences):
# Your code here
pass5 test cases · run your code against them in the editor