Skip to content

tensor_field

allennlp.data.fields.tensor_field

[SOURCE]


TensorField

class TensorField(Field[torch.Tensor]):
 | def __init__(
 |     self,
 |     tensor: Union[torch.Tensor, np.ndarray],
 |     padding_value: Any = 0.0,
 |     dtype: Optional[Union[np.dtype, torch.dtype]] = None
 | ) -> None

A class representing a tensor, which could have arbitrary dimensions. A batch of these tensors are padded to the max dimension length in the batch for each dimension.

get_padding_lengths

class TensorField(Field[torch.Tensor]):
 | ...
 | def get_padding_lengths(self) -> Dict[str, int]

as_tensor

class TensorField(Field[torch.Tensor]):
 | ...
 | def as_tensor(self, padding_lengths: Dict[str, int]) -> torch.Tensor

empty_field

class TensorField(Field[torch.Tensor]):
 | ...
 | def empty_field(self)

array

class TensorField(Field[torch.Tensor]):
 | ...
 | @property
 | def array(self)

This is a compatibility method that returns the underlying tensor as a numpy array.

human_readable_repr

class TensorField(Field[torch.Tensor]):
 | ...
 | def human_readable_repr(self) -> JsonDict