matchzoo.preprocessors.units.truncated_length

Module Contents

class matchzoo.preprocessors.units.truncated_length.TruncatedLength(text_length:int, truncate_mode:str='pre')

Bases: matchzoo.preprocessors.units.unit.Unit

TruncatedLengthUnit Class.

Process unit to truncate the text that exceeds the set length.

Examples

>>> from matchzoo.preprocessors.units import TruncatedLength
>>> truncatedlen = TruncatedLength(3)
>>> truncatedlen.transform(list(range(1, 6))) == [3, 4, 5]
True
>>> truncatedlen.transform(list(range(2))) == [0, 1]
True
transform(self, input_:list)

Truncate the text that exceeds the specified maximum length.

Parameters:input – list of tokenized tokens.
Return tokens:list of tokenized tokens in fixed length if its origin length larger than text_length.