Skip to content

array_field

allennlp.data.fields.array_field

[SOURCE]


ArrayField#

class ArrayField(Field[numpy.ndarray]):
 | def __init__(
 |     self,
 |     array: numpy.ndarray,
 |     padding_value: int = 0,
 |     dtype: numpy.dtype = numpy.float32
 | ) -> None

A class representing an array, which could have arbitrary dimensions. A batch of these arrays are padded to the max dimension length in the batch for each dimension.

get_padding_lengths#

class ArrayField(Field[numpy.ndarray]):
 | ...
 | @overrides
 | def get_padding_lengths(self) -> Dict[str, int]

as_tensor#

class ArrayField(Field[numpy.ndarray]):
 | ...
 | @overrides
 | def as_tensor(self, padding_lengths: Dict[str, int]) -> torch.Tensor

empty_field#

class ArrayField(Field[numpy.ndarray]):
 | ...
 | @overrides
 | def empty_field(self)

Pass the padding_value, so that any outer field, e.g., ListField[ArrayField] uses the same padding_value in the padded ArrayFields