[ allennlp.data.fields.adjacency_field ]
class AdjacencyField(Field[torch.Tensor]): | def __init__( | self, | indices: List[Tuple[int, int]], | sequence_field: SequenceField, | labels: List[str] = None, | label_namespace: str = "labels", | padding_value: int = -1 | ) -> None
AdjacencyField defines directed adjacency relations between elements
Because it's a labeling of some other field, we take that field as input here
and use it to determine our padding and other things.
This field will get converted into an array of shape (sequence_field_length, sequence_field_length), where the (i, j)th array element is either a binary flag indicating there is an edge from i to j, or an integer label k, indicating there is a label from i to j of type k.
- indices :
- sequence_field :
A field containing the sequence that this
AdjacencyFieldis labeling. Most often, this is a
TextField, for tagging edge relations between tokens in a sentence.
- labels :
List[str], optional (default =
Optional labels for the edges of the adjacency matrix.
- label_namespace :
str, optional (default =
The namespace to use for converting tag strings into integers. We convert tag strings to integers for you, and this parameter tells the
Vocabularyobject 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).
- padding_value :
int, optional (default =
The value to use as padding.
| @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 as_tensor(self, padding_lengths: Dict[str, int]) -> torch.Tensor
| @overrides | def empty_field(self) -> "AdjacencyField"
The empty_list here is needed for mypy