sgnlp.models.sentic_gcn.utils.pad_and_truncate¶
-
pad_and_truncate
(sequence: List[float], max_len: int, dtype: str = 'int64', padding: str = 'post', truncating: str = 'post', value: int = 0) → numpy.ndarray[source]¶ Helper method for padding and truncating text and aspect segment.
- Parameters
sequence (List[float]) – input sequence of indices
max_len (int) – maximum len to pad
dtype (str, optional) – data type to cast indices. Defaults to “int64”.
padding (str, optional) – type of padding, ‘pre’ or ‘post’. Defaults to “post”.
truncating (str, optional) – type of truncating, ‘pre’ or ‘post’. Defaults to “post”.
value (int, optional) – value used for padding. Defaults to 0.
- Returns
return a ndarray padded to the max_len
- Return type
np.ndarray