sequence_label_field
allennlp.data.fields.sequence_label_field
SequenceLabelField¶
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 thisSequenceLabelField
is labeling. Most often, this is aTextField
, 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 theVocabulary
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).
__iter__¶
class SequenceLabelField(Field[torch.Tensor]):
| ...
| def __iter__(self) -> Iterator[Union[str, int]]
count_vocab_items¶
class SequenceLabelField(Field[torch.Tensor]):
| ...
| def count_vocab_items(self, counter: Dict[str, Dict[str, int]])
index¶
class SequenceLabelField(Field[torch.Tensor]):
| ...
| def index(self, vocab: Vocabulary)
get_padding_lengths¶
class SequenceLabelField(Field[torch.Tensor]):
| ...
| def get_padding_lengths(self) -> Dict[str, int]
as_tensor¶
class SequenceLabelField(Field[torch.Tensor]):
| ...
| def as_tensor(self, padding_lengths: Dict[str, int]) -> torch.Tensor
empty_field¶
class SequenceLabelField(Field[torch.Tensor]):
| ...
| def empty_field(self) -> "SequenceLabelField"
human_readable_repr¶
class SequenceLabelField(Field[torch.Tensor]):
| ...
| def human_readable_repr(self) -> Union[List[str], List[int]]