Named Entity Recognizer

class forte.models.ner.conditional_random_field.ConditionalRandomField(num_tags: int, constraints: Optional[List[Tuple[int, int]]] = None, include_start_end_transitions: bool = True)[source]

This module uses the “forward-backward” algorithm to compute the log-likelihood of its inputs assuming a conditional random field model.

See, e.g.

  • num_tags (int) – The number of tags.
  • constraints (List[Tuple[int, int]]) – An optional list of allowed transitions (from_tag_id, to_tag_id). These are applied to viterbi_tags() but do not affect forward(). These should be derived from allowed_transitions so that the start and end transitions are handled correctly for your tag type.
  • include_start_end_transitions (bool) – Whether to include the start and end transition parameters.
forward(inputs: torch.Tensor, tags: torch.Tensor, mask: Optional[torch.ByteTensor] = None) → torch.Tensor[source]

Computes the log likelihood.

viterbi_tags(logits: torch.Tensor, mask: torch.Tensor) → List[Tuple[List[int], float]][source]

Uses viterbi algorithm to find most likely tags for the given inputs. If constraints are applied, disallows all other transitions.

Semantic Role Labeling

class, char_vocab:, hparams=None)[source]

This module is supposed to be the last layer so we will not return an informative output_size Returns:

class ReturnType[source]
forward(inputs: → ReturnType[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.


Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

decode(inputs:, enforce_constraint: bool = False) → List[Dict[int, List[]]][source]

Performs optimal decoding with dynamic programming.

Returns:A nested structure of SRL spans, representing the (inner) list of spans for each predicate (middle dict) and for each example in the batch (outer list).