add_sequence_controls
- opennmt.inputters.add_sequence_controls(ids, length=None, start_id=None, end_id=None, pad_id=0)[source]
Adds sequence control tokens.
- Parameters
ids – Sequence of token ids as a 1D
tf.Tensor
, a 2Dtf.Tensor
, or a 2Dtf.RaggedTensor
.length – Length of each sequence in the batch as a 1D
tf.Tensor
. Required ifids
is a 2Dtf.Tensor
.start_id – Token id to prepend to the sequences (set
None
to disable).end_id – Token id to append to the sequences (set
None
to disable).pad_id – Padding token ID.
- Returns
The updated token ids, and optionally the updated length if it was initially passed as argument.
- Raises
ValueError – if
ids
is a dense 2Dtf.Tensor
, butlength
is not set.ValueError – if the rank of
ids
is not 1 or 2.