class_docstr: 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, required
      The number of tags.
  constraints : List[Tuple[int, int]], optional (default: None)
      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, optional (default: True)
      Whether to include the start and end transition parameters.
code: def __init__(
      self,
      num_tags,
      constraints=None,
      include_start_end_transitions=True,
  ):
      super(ConditionalRandomField, self).__init__()
      self.num_tags = num_tags
  
      # transitions[i, j] is the logit for transitioning from state i to state j.
      self.transitions = torch.nn.Parameter(
          torch.Tensor(num_tags, num_tags)
      )
  
      # _constraint_mask indicates valid transitions (based on supplied constraints).
      # Include special start of sequence (num_tags + 1) and end of sequence tags (num_tags + 2)
      if constraints is None:
          # All transitions are valid.
          constraint_mask = torch.Tensor(
              num_tags + 2, num_tags + 2
          ).fill_(1.0)
      else:
          constraint_mask = torch.Tensor(
              num_tags + 2, num_tags + 2
          ).fill_(0.0)
          for i, j in constraints:
              constraint_mask[i, j] = 1.0
  
      self._constraint_mask = torch.nn.Parameter(
          constraint_mask, requires_grad=False
      )
  
      # Also need logits for transitioning from "start" state and to "end" state.
      self.include_start_end_transitions = include_start_end_transitions
      if include_start_end_transitions:
          self.start_transitions = torch.nn.Parameter(
              torch.Tensor(num_tags)
          )
          self.end_transitions = torch.nn.Parameter(
              torch.Tensor(num_tags)
          )
  
      self.reset_parameters()
  
file_path: magnitude/pymagnitude/third_party/allennlp/modules/conditional_random_field.py
imports: from __future__ import absolute_import
  import torch
  from allennlp.common.checks import ConfigurationError
  import allennlp.nn.util
label_desc: Use image node_id 1 to create a new ConditionalRandomField object from inherited base classes: torch.nn with example: obj = ConditionalRandomField(num_tags, constraints, include_start_end_transitions)