[ allennlp.data.fields.list_field ]
class ListField(SequenceField[DataArray]): | def __init__(self, field_list: List[Field]) -> None
ListField is a list of other fields. You would use this to represent, e.g., a list of
answer options that are themselves
This field will get converted into a tensor that has one more mode than the items in the list.
If this is a list of
TextFields that have shape (num_words, num_characters), this
ListField will output a tensor of shape (num_sentences, num_words, num_characters).
- field_list :
A list of
Fieldobjects to be concatenated into a single input tensor. All of the contained
Fieldobjects must be of the same type.
| @overrides | def count_vocab_items(self, counter: Dict[str, Dict[str, int]])
| @overrides | def index(self, vocab: Vocabulary)
| @overrides | def get_padding_lengths(self) -> Dict[str, int]
| @overrides | def sequence_length(self) -> int
| @overrides | def as_tensor(self, padding_lengths: Dict[str, int]) -> DataArray
| @overrides | def empty_field(self)
Our "empty" list field will actually have a single field in the list, so that we can
correctly construct nested lists. For example, if we have a type that is
ListField[ListField[LabelField]], we need the top-level
ListField to know to
ListField[LabelField] when it's padding, and the nested
to know that it's empty objects are
LabelFields. Having an "empty" list actually have
length one makes this all work out, and we'll always be padding to at least length 1,
| @overrides | def batch_tensors(self, tensor_list: List[DataArray]) -> DataArray
We defer to the class we're wrapping in a list to handle the batching.