Skip to content




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

A AdjacencyField defines directed adjacency relations between elements in a SequenceField. 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 : List[Tuple[int, int]]
  • sequence_field : SequenceField
    A field containing the sequence that this AdjacencyField is labeling. Most often, this is a TextField, for tagging edge relations between tokens in a sentence.
  • labels : List[str], optional (default = None)
    Optional labels for the edges of the adjacency matrix.
  • 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).
  • padding_value : int, optional (default = -1)
    The value to use as padding.


class AdjacencyField(Field[torch.Tensor]):
 | ...
 | def count_vocab_items(self, counter: Dict[str, Dict[str, int]])


class AdjacencyField(Field[torch.Tensor]):
 | ...
 | def index(self, vocab: Vocabulary)


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


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


class AdjacencyField(Field[torch.Tensor]):
 | ...
 | def empty_field(self) -> "AdjacencyField"


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