class_docstr: Conditional random field.
  This module implements a conditional random field [LMP01]_. The forward computation
  of this class computes the log likelihood of the given sequence of tags and
  emission score tensor. This class also has `~CRF.decode` method which finds
  the best tag sequence given an emission score tensor using `Viterbi algorithm`_.
  Args:
      num_tags: Number of tags.
      batch_first: Whether the first dimension corresponds to the size of a minibatch.
  Attributes:
      start_transitions (`~torch.nn.Parameter`): Start transition score tensor of size
          ``(num_tags,)``.
      end_transitions (`~torch.nn.Parameter`): End transition score tensor of size
          ``(num_tags,)``.
      transitions (`~torch.nn.Parameter`): Transition score tensor of size
          ``(num_tags, num_tags)``.
  .. [LMP01] Lafferty, J., McCallum, A., Pereira, F. (2001).
     "Conditional random fields: Probabilistic models for segmenting and
     labeling sequence data". *Proc. 18th International Conf. on Machine
     Learning*. Morgan Kaufmann. pp. 282–289.
  .. _Viterbi algorithm: https://en.wikipedia.org/wiki/Viterbi_algorithm
code: def _validate(
      self,
      emissions: torch.Tensor,
      tags: Optional[torch.LongTensor] = None,
      mask: Optional[torch.ByteTensor] = None,
  ) -> None:
      if emissions.dim() != 3:
          raise ValueError(
              f"emissions must have dimension of 3, got {emissions.dim()}"
          )
      if emissions.size(2) != self.num_tags:
          raise ValueError(
              f"expected last dimension of emissions is {self.num_tags}, "
              f"got {emissions.size(2)}"
          )
  
      if tags is not None:
          if emissions.shape[:2] != tags.shape:
              raise ValueError(
                  "the first two dimensions of emissions and tags must match, "
                  f"got {tuple(emissions.shape[:2])} and {tuple(tags.shape)}"
              )
  
      if mask is not None:
          if emissions.shape[:2] != mask.shape:
              raise ValueError(
                  "the first two dimensions of emissions and mask must match, "
                  f"got {tuple(emissions.shape[:2])} and {tuple(mask.shape)}"
              )
          no_empty_seq = not self.batch_first and mask[0].all()
          no_empty_seq_bf = self.batch_first and mask[:, 0].all()
          if not no_empty_seq and not no_empty_seq_bf:
              raise ValueError(
                  "mask of the first timestep must all be on"
              )
  
file_path: nlp-architect/nlp_architect/nn/torch/layers/crf.py
imports: from typing import List, Optional
  import torch
  import torch.nn
label_desc: Use image node_id 6 for calling the CRF obj's underlying member method code with example usage: obj._validate(emissions, tags, mask) without return types