shift_tokens_right(input_ids: Tensor, pad_token_id: int | None, decoder_start_token_id: int)Shift token ids one place to the right, to make the decoder inputs of labels.
The first column becomes decoder_start_token_id, every other column is the one
before it in input_ids, and the -100 that marks a position to ignore in a
label is replaced by pad_token_id. input_ids is not changed.
Parameters
input_ idsTensorToken ids of shape
(batch_size, sequence_length).pad_ token_ idintThe id of the padding token.
decoder_ start_ token_ idintThe id the shifted sequences start with.
Returns
TensorThe shifted ids, of the same shape and dtype.
Raises
ValueErrorpad_token_id is None, or input_ids is not two-dimensional.Examples
>>> import lucid
>>> from lucid.peft import shift_tokens_right
>>> labels = lucid.tensor([[5, 6, -100]])
>>> shift_tokens_right(labels, pad_token_id=0, decoder_start_token_id=2)
tensor([[2, 5, 6]], dtype=lucid.int64)
>>> shift_tokens_right(lucid.tensor([[-100, 7]]), pad_token_id=0, decoder_start_token_id=2)
tensor([[2, 0]], dtype=lucid.int64)