Skip to content

sequence_label_field

[ allennlp.data.fields.sequence_label_field ]


SequenceLabelField Objects#

class SequenceLabelField(Field[torch.Tensor]):
 | def __init__(
 |     self,
 |     labels: Union[List[str], List[int]],
 |     sequence_field: SequenceField,
 |     label_namespace: str = "labels"
 | ) -> None

A SequenceLabelField assigns a categorical label to each element in a SequenceField. Because it's a labeling of some other field, we take that field as input here, and we use it to determine our padding and other things.

This field will get converted into a list of integer class ids, representing the correct class for each element in the sequence.

Parameters

  • labels : Union[List[str], List[int]]
    A sequence of categorical labels, encoded as strings or integers. These could be POS tags like [NN, JJ, ...], BIO tags like [B-PERS, I-PERS, O, O, ...], or any other categorical tag sequence. If the labels are encoded as integers, they will not be indexed using a vocab.
  • sequence_field : SequenceField
    A field containing the sequence that this SequenceLabelField is labeling. Most often, this is a TextField, for tagging individual tokens in a sentence.
  • label_namespace : str, optional (default = 'labels')
    The namespace to use for converting tag strings into integers. We convert tag strings to integers for you, and this parameter tells the Vocabulary object which mapping from strings to integers to use (so that "O" as a tag doesn't get the same id as "O" as a word).

count_vocab_items#

 | @overrides
 | def count_vocab_items(self, counter: Dict[str, Dict[str, int]])

index#

 | @overrides
 | def index(self, vocab: Vocabulary)

get_padding_lengths#

 | @overrides
 | def get_padding_lengths(self) -> Dict[str, int]

as_tensor#

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

empty_field#

 | @overrides
 | def empty_field(self) -> "SequenceLabelField"

The empty_list here is needed for mypy