All problems
Causal LM Shift
Problem
Build the shifted input/label pair for causal language modeling: inputs are all tokens except the last and labels are all tokens except the first, so position t predicts token t + 1.
The signature is causal_lm_shift(tokens). Return [inputs, labels].
Hint
A one-token shift turns next-token prediction into ordinary token-level classification.
Test cases
case 1
in: [[1,2,3,4]]
expected: [[1,2,3],[2,3,4]]
case 2
in: [[5]]
expected: [[],[]]
case 3
in: [[1,2]]
expected: [[1],[2]]
case 4
in: [[0,0]]
expected: [[0],[0]]
Starter codePython
def causal_lm_shift(tokens):
# Your code here
pass4 test cases · run your code against them in the editor