Skip to content

list_field

allennlp.data.fields.list_field

[SOURCE]


ListField#

class ListField(SequenceField[DataArray]):
 | def __init__(self, field_list: List[Field]) -> None

A ListField is a list of other fields. You would use this to represent, e.g., a list of answer options that are themselves TextFields.

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).

Parameters

  • field_list : List[Field]
    A list of Field objects to be concatenated into a single input tensor. All of the contained Field objects must be of the same type.

count_vocab_items#

class ListField(SequenceField[DataArray]):
 | ...
 | @overrides
 | def count_vocab_items(self, counter: Dict[str, Dict[str, int]])

index#

class ListField(SequenceField[DataArray]):
 | ...
 | @overrides
 | def index(self, vocab: Vocabulary)

get_padding_lengths#

class ListField(SequenceField[DataArray]):
 | ...
 | @overrides
 | def get_padding_lengths(self) -> Dict[str, int]

sequence_length#

class ListField(SequenceField[DataArray]):
 | ...
 | @overrides
 | def sequence_length(self) -> int

as_tensor#

class ListField(SequenceField[DataArray]):
 | ...
 | @overrides
 | def as_tensor(self, padding_lengths: Dict[str, int]) -> DataArray

empty_field#

class ListField(SequenceField[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 construct a ListField[LabelField] when it's padding, and the nested ListField needs 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, anyway.

batch_tensors#

class ListField(SequenceField[DataArray]):
 | ...
 | @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.