Skip to content

namespace_swapping_field

allennlp.data.fields.namespace_swapping_field

[SOURCE]


NamespaceSwappingField#

class NamespaceSwappingField(Field[torch.Tensor]):
 | def __init__(
 |     self,
 |     source_tokens: List[Token],
 |     target_namespace: str
 | ) -> None

A NamespaceSwappingField is used to map tokens in one namespace to tokens in another namespace. It is used by seq2seq models with a copy mechanism that copies tokens from the source sentence into the target sentence.

Parameters

  • source_tokens : List[Token]
    The tokens from the source sentence.
  • target_namespace : str
    The namespace that the tokens from the source sentence will be mapped to.

index#

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

get_padding_lengths#

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

as_tensor#

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

empty_field#

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