adjacency_field
allennlp.data.fields.adjacency_field
AdjacencyField#
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.
Parameters
- indices :
List[Tuple[int, int]]
- sequence_field :
SequenceField
A field containing the sequence that thisAdjacencyField
is labeling. Most often, this is aTextField
, 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 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). - padding_value :
int
, optional (default =-1
)
The value to use as padding.
count_vocab_items#
class AdjacencyField(Field[torch.Tensor]):
| ...
| @overrides
| def count_vocab_items(self, counter: Dict[str, Dict[str, int]])
index#
class AdjacencyField(Field[torch.Tensor]):
| ...
| @overrides
| def index(self, vocab: Vocabulary)
get_padding_lengths#
class AdjacencyField(Field[torch.Tensor]):
| ...
| @overrides
| def get_padding_lengths(self) -> Dict[str, int]
as_tensor#
class AdjacencyField(Field[torch.Tensor]):
| ...
| @overrides
| def as_tensor(self, padding_lengths: Dict[str, int]) -> torch.Tensor
empty_field#
class AdjacencyField(Field[torch.Tensor]):
| ...
| @overrides
| def empty_field(self) -> "AdjacencyField"
The empty_list here is needed for mypy