mindspore.dataset.text.TruncateSequencePair
- class mindspore.dataset.text.TruncateSequencePair(max_length)[source]
Truncate a pair of 1-D string input so that their total length is less than the specified length.
- Parameters
max_length (int) – The maximum total length of the output strings. If it is no less than the total length of the original pair of strings, no truncation is performed; otherwise, the longer of the two input strings is truncated until its total length equals this value.
- Raises
TypeError – If max_length is not of type int.
- Supported Platforms:
CPU
Examples
>>> import mindspore.dataset as ds >>> import mindspore.dataset.text as text >>> >>> dataset = ds.NumpySlicesDataset(data={"col1": [[1, 2, 3]], "col2": [[4, 5]]}) >>> # Data before >>> # | col1 | col2 | >>> # +-----------+-----------| >>> # | [1, 2, 3] | [4, 5] | >>> # +-----------+-----------+ >>> truncate_sequence_pair_op = text.TruncateSequencePair(max_length=4) >>> dataset = dataset.map(operations=truncate_sequence_pair_op) >>> # Data after >>> # | col1 | col2 | >>> # +-----------+-----------+ >>> # | [1, 2] | [4, 5] | >>> # +-----------+-----------+
- Tutorial Examples: