Skip to content

index_field

allennlp.data.fields.index_field

[SOURCE]


IndexField

class IndexField(Field[torch.Tensor]):
 | def __init__(self, index: int, sequence_field: SequenceField) -> None

An IndexField is an index into a SequenceField, as might be used for representing a correct answer option in a list, or a span begin and span end position in a passage, for example. Because it's an index into a SequenceField, we take one of those as input and use it to compute padding lengths.

Parameters

  • index : int
    The index of the answer in the SequenceField. This is typically the "correct answer" in some classification decision over the sequence, like where an answer span starts in SQuAD, or which answer option is correct in a multiple choice question. A value of -1 means there is no label, which can be used for padding or other purposes.
  • sequence_field : SequenceField
    A field containing the sequence that this IndexField is a pointer into.

get_padding_lengths

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

as_tensor

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

empty_field

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

human_readable_repr

class IndexField(Field[torch.Tensor]):
 | ...
 | def human_readable_repr(self)