Models

Named Entity Recognizer

class forte.models.ner.conditional_random_field.ConditionalRandomField(num_tags, constraints=None, include_start_end_transitions=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. http://www.cs.columbia.edu/~mcollins/fb.pdf

Parameters
  • num_tags (int) – The number of tags.

  • constraints (Optional[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, tags, mask=None)[source]

Computes the log likelihood.

Return type

Tensor

viterbi_tags(logits, mask)[source]

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

Return type

List[Tuple[List[int], float]]

Semantic Role Labeling

class forte.models.srl.model.LabeledSpanGraphNetwork(word_vocab, char_vocab, hparams=None)[source]
property output_size

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

static default_hparams()[source]

Returns a dict of hyperparameters of the module with default values. Used to replace the missing values of input hparams during module construction.

{
    "name": "module"
}
Return type

Dict[str, Any]

class ReturnType(*args, **kwargs)[source]
forward(inputs)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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.

Return type

ReturnType

decode(inputs, enforce_constraint=False)[source]

Performs optimal decoding with dynamic programming.

Return type

List[Dict[int, List[Span]]]

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).