class_docstr: This model performs semantic role labeling using BIO tags using Propbank semantic roles.
  Specifically, it is an implmentation of `Deep Semantic Role Labeling - What works
  and what's next <https://homes.cs.washington.edu/~luheng/files/acl2017_hllz.pdf>`_ .
  
  This implementation is effectively a series of stacked interleaved LSTMs with highway
  connections, applied to embedded sequences of words concatenated with a binary indicator
  containing whether or not a word is the verbal predicate to generate predictions for in
  the sentence. Additionally, during inference, Viterbi decoding is applied to constrain
  the predictions to contain valid BIO sequences.
  
  Parameters
  ----------
  vocab : ``Vocabulary``, required
      A Vocabulary, required in order to compute sizes for input/output projections.
  text_field_embedder : ``TextFieldEmbedder``, required
      Used to embed the ``tokens`` ``TextField`` we get as input to the model.
  encoder : ``Seq2SeqEncoder``
      The encoder (with its own internal stacking) that we will use in between embedding tokens
      and predicting output tags.
  binary_feature_dim : int, required.
      The dimensionality of the embedding of the binary verb predicate features.
  initializer : ``InitializerApplicator``, optional (default=``InitializerApplicator()``)
      Used to initialize the model parameters.
  regularizer : ``RegularizerApplicator``, optional (default=``None``)
      If provided, will be used to calculate the regularization penalty during training.
  label_smoothing : ``float``, optional (default = 0.0)
      Whether or not to use label smoothing on the labels when computing cross entropy loss.
class_docstr_tok: ["This","model","performs","semantic","role","labeling","using","BIO","tags","using","Propbank","semantic","roles",".","Specifically",",","it","is","an","implmentation","of","`","Deep","Semantic","Role","Labeling","-","What","works","and","what","'s","next","<","https",":","\/\/homes.cs.washington.edu\/~luheng\/files\/acl2017_hllz.pdf",">","`","_",".","This","implementation","is","effectively","a","series","of","stacked","interleaved","LSTMs","with","highway","connections",",","applied","to","embedded","sequences","of","words","concatenated","with","a","binary","indicator","containing","whether","or","not","a","word","is","the","verbal","predicate","to","generate","predictions","for","in","the","sentence",".","Additionally",",","during","inference",",","Viterbi","decoding","is","applied","to","constrain","the","predictions","to","contain","valid","BIO","sequences",".","Parameters","--","--","--","--","--","vocab",":","``","Vocabulary","``",",","required","A","Vocabulary",",","required","in","order","to","compute","sizes","for","input\/output","projections",".","text_field_embedder",":","``","TextFieldEmbedder","``",",","required","Used","to","embed","the","``","tokens","``","``","TextField","``","we","get","as","input","to","the","model",".","encoder",":","``","Seq2SeqEncoder","``","The","encoder","(","with","its","own","internal","stacking",")","that","we","will","use","in","between","embedding","tokens","and","predicting","output","tags",".","binary_feature_dim",":","int",",","required",".","The","dimensionality","of","the","embedding","of","the","binary","verb","predicate","features",".","initializer",":","``","InitializerApplicator","``",",","optional","(","default=","``","InitializerApplicator","(",")","``",")","Used","to","initialize","the","model","parameters",".","regularizer",":","``","RegularizerApplicator","``",",","optional","(","default=","``","None","``",")","If","provided",",","will","be","used","to","calculate","the","regularization","penalty","during","training",".","label_smoothing",":","``","float","``",",","optional","(","default","=","0.0",")","Whether","or","not","to","use","label","smoothing","on","the","labels","when","computing","cross","entropy","loss","."]
docstr: Generate a matrix of pairwise transition potentials for the BIO labels.
  The only constraint implemented here is that I-XXX labels must be preceded
  by either an identical I-XXX tag or a B-XXX tag. In order to achieve this
  constraint, pairs of labels which do not satisfy this constraint have a
  pairwise potential of -inf.
  
  Returns
  -------
  transition_matrix : torch.Tensor
      A (num_labels, num_labels) matrix of pairwise potentials.
docstr_tok: ["Generate","a","matrix","of","pairwise","transition","potentials","for","the","BIO","labels",".","The","only","constraint","implemented","here","is","that","I-XXX","labels","must","be","preceded","by","either","an","identical","I-XXX","tag","or","a","B-XXX","tag",".","In","order","to","achieve","this","constraint",",","pairs","of","labels","which","do","not","satisfy","this","constraint","have","a","pairwise","potential","of","-inf",".","Returns","--","--","--","-","transition_matrix",":","torch.Tensor","A","(","num_labels",",","num_labels",")","matrix","of","pairwise","potentials","."]
code: def get_viterbi_pairwise_potentials(self):
      """
      Generate a matrix of pairwise transition potentials for the BIO labels.
      The only constraint implemented here is that I-XXX labels must be preceded
      by either an identical I-XXX tag or a B-XXX tag. In order to achieve this
      constraint, pairs of labels which do not satisfy this constraint have a
      pairwise potential of -inf.
  
      Returns
      -------
      transition_matrix : torch.Tensor
          A (num_labels, num_labels) matrix of pairwise potentials.
      """
      all_labels = self.vocab.get_index_to_token_vocabulary("labels")
      num_labels = len(all_labels)
      transition_matrix = torch.zeros([num_labels, num_labels])
  
      for i, previous_label in list(all_labels.items()):
          for j, label in list(all_labels.items()):
              # I labels can only be preceded by themselves or
              # their corresponding B tag.
              if (
                  i != j
                  and label[0] == "I"
                  and not previous_label == "B" + label[1:]
              ):
                  transition_matrix[i, j] = float("-inf")
      return transition_matrix
  
imports: from __future__ import absolute_import
  import torch
  from torch.nn.modules import Linear, Dropout
  import torch.nn.functional
  from allennlp.common.checks import check_dimensions_match
  from allennlp.data import Vocabulary
  from allennlp.modules import Seq2SeqEncoder, TimeDistributed, TextFieldEmbedder
  from allennlp.modules.token_embedders import Embedding
  from allennlp.models.model import Model
  from allennlp.nn import InitializerApplicator, RegularizerApplicator
  from allennlp.nn.util import get_text_field_mask, sequence_cross_entropy_with_logits
  from allennlp.nn.util import get_lengths_from_binary_sequence_mask, viterbi_decode
  from allennlp.training.metrics import SpanBasedF1Measure
label_desc: Use image node_id 5 for calling the SemanticRoleLabeler obj's underlying member method code with example usage: obj.get_viterbi_pairwise_potentials() and returns: transition_matrix