Example 1
Arguments: [
[
1,
2,
3
],
[
[
2,
3
],
[
9
]
]
]
Expected result: 0The output ends in [2,3], which is rule index 0.
Decoding and sampling · Easy
Problem 22 of 50 · Python and NumPy
Check whether the current generated token list ends with a complete stop sequence. Return the index of the matching stop sequence in stop_sequences, choosing the lowest index if several match. Return -1 if none matches. Partial prefixes do not count, and matches earlier in the output do not count unless they reach the end.
def completed_stop_sequence(tokens, stop_sequences):Arguments: [
[
1,
2,
3
],
[
[
2,
3
],
[
9
]
]
]
Expected result: 0The output ends in [2,3], which is rule index 0.
Arguments: [
[
1,
2
],
[
[
2,
3
]
]
]
Expected result: -1Only token 2 has arrived; the required following 3 is missing.