NumPy allowed · plain Python earns 10 bonus points
Softmax(logits) → probability distribution
Enforce generation termination boundaries by cutting completed or streamed text at the earliest occurrence of stop tokens.
Implement apply_stop_sequences(text, stop_sequences). Find the earliest index in text where any non-empty sequence from stop_sequences appears. If found, truncate text immediately before the sequence, set stopped: True, and record matched_sequence. If none found or stop_sequences is empty, return original text with stopped: False and matched_sequence: None.
apply_stop_sequences(text: str, stop_sequences: list[str]) -> dict[str, str | bool]