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: Parameters
  ----------
  tokens : Dict[str, torch.LongTensor], required
      The output of ``TextField.as_array()``, which should typically be passed directly to a
      ``TextFieldEmbedder``. This output is a dictionary mapping keys to ``TokenIndexer``
      tensors.  At its most basic, using a ``SingleIdTokenIndexer`` this is: ``{"tokens":
      Tensor(batch_size, num_tokens)}``. This dictionary will have the same keys as were used
      for the ``TokenIndexers`` when you created the ``TextField`` representing your
      sequence.  The dictionary is designed to be passed directly to a ``TextFieldEmbedder``,
      which knows how to combine different word representations into a single vector per
      token in your input.
  verb_indicator: torch.LongTensor, required.
      An integer ``SequenceFeatureField`` representation of the position of the verb
      in the sentence. This should have shape (batch_size, num_tokens) and importantly, can be
      all zeros, in the case that the sentence has no verbal predicate.
  tags : torch.LongTensor, optional (default = None)
      A torch tensor representing the sequence of integer gold class labels
      of shape ``(batch_size, num_tokens)``
  metadata : ``List[Dict[str, Any]]``, optional, (default = None)
      metadata containg the original words in the sentence and the verb to compute the
      frame for, under 'words' and 'verb' keys, respectively.
  
  Returns
  -------
  An output dictionary consisting of:
  logits : torch.FloatTensor
      A tensor of shape ``(batch_size, num_tokens, tag_vocab_size)`` representing
      unnormalised log probabilities of the tag classes.
  class_probabilities : torch.FloatTensor
      A tensor of shape ``(batch_size, num_tokens, tag_vocab_size)`` representing
      a distribution of the tag classes per word.
  loss : torch.FloatTensor, optional
      A scalar loss to be optimised.
docstr_tok: ["Parameters","--","--","--","--","--","tokens",":","Dict","[","str",",","torch.LongTensor","]",",","required","The","output","of","``","TextField.as_array","(",")","``",",","which","should","typically","be","passed","directly","to","a","``","TextFieldEmbedder","``",".","This","output","is","a","dictionary","mapping","keys","to","``","TokenIndexer","``","tensors",".","At","its","most","basic",",","using","a","``","SingleIdTokenIndexer","``","this","is",":","``","{","``","tokens","''",":","Tensor","(","batch_size",",","num_tokens",")","}","``",".","This","dictionary","will","have","the","same","keys","as","were","used","for","the","``","TokenIndexers","``","when","you","created","the","``","TextField","``","representing","your","sequence",".","The","dictionary","is","designed","to","be","passed","directly","to","a","``","TextFieldEmbedder","``",",","which","knows","how","to","combine","different","word","representations","into","a","single","vector","per","token","in","your","input",".","verb_indicator",":","torch.LongTensor",",","required",".","An","integer","``","SequenceFeatureField","``","representation","of","the","position","of","the","verb","in","the","sentence",".","This","should","have","shape","(","batch_size",",","num_tokens",")","and","importantly",",","can","be","all","zeros",",","in","the","case","that","the","sentence","has","no","verbal","predicate",".","tags",":","torch.LongTensor",",","optional","(","default","=","None",")","A","torch","tensor","representing","the","sequence","of","integer","gold","class","labels","of","shape","``","(","batch_size",",","num_tokens",")","``","metadata",":","``","List","[","Dict","[","str",",","Any","]","]","``",",","optional",",","(","default","=","None",")","metadata","containg","the","original","words","in","the","sentence","and","the","verb","to","compute","the","frame","for",",","under","'words","'","and","'verb","'","keys",",","respectively",".","Returns","--","--","--","-","An","output","dictionary","consisting","of",":","logits",":","torch.FloatTensor","A","tensor","of","shape","``","(","batch_size",",","num_tokens",",","tag_vocab_size",")","``","representing","unnormalised","log","probabilities","of","the","tag","classes",".","class_probabilities",":","torch.FloatTensor","A","tensor","of","shape","``","(","batch_size",",","num_tokens",",","tag_vocab_size",")","``","representing","a","distribution","of","the","tag","classes","per","word",".","loss",":","torch.FloatTensor",",","optional","A","scalar","loss","to","be","optimised","."]
code: def forward(
      self,  # type: ignore
      tokens,
      verb_indicator,
      tags=None,
      metadata=None,
  ):
      # pylint: disable=arguments-differ
      """
      Parameters
      ----------
      tokens : Dict[str, torch.LongTensor], required
          The output of ``TextField.as_array()``, which should typically be passed directly to a
          ``TextFieldEmbedder``. This output is a dictionary mapping keys to ``TokenIndexer``
          tensors.  At its most basic, using a ``SingleIdTokenIndexer`` this is: ``{"tokens":
          Tensor(batch_size, num_tokens)}``. This dictionary will have the same keys as were used
          for the ``TokenIndexers`` when you created the ``TextField`` representing your
          sequence.  The dictionary is designed to be passed directly to a ``TextFieldEmbedder``,
          which knows how to combine different word representations into a single vector per
          token in your input.
      verb_indicator: torch.LongTensor, required.
          An integer ``SequenceFeatureField`` representation of the position of the verb
          in the sentence. This should have shape (batch_size, num_tokens) and importantly, can be
          all zeros, in the case that the sentence has no verbal predicate.
      tags : torch.LongTensor, optional (default = None)
          A torch tensor representing the sequence of integer gold class labels
          of shape ``(batch_size, num_tokens)``
      metadata : ``List[Dict[str, Any]]``, optional, (default = None)
          metadata containg the original words in the sentence and the verb to compute the
          frame for, under 'words' and 'verb' keys, respectively.
  
      Returns
      -------
      An output dictionary consisting of:
      logits : torch.FloatTensor
          A tensor of shape ``(batch_size, num_tokens, tag_vocab_size)`` representing
          unnormalised log probabilities of the tag classes.
      class_probabilities : torch.FloatTensor
          A tensor of shape ``(batch_size, num_tokens, tag_vocab_size)`` representing
          a distribution of the tag classes per word.
      loss : torch.FloatTensor, optional
          A scalar loss to be optimised.
  
      """
      embedded_text_input = self.embedding_dropout(
          self.text_field_embedder(tokens)
      )
      mask = get_text_field_mask(tokens)
      embedded_verb_indicator = self.binary_feature_embedding(
          verb_indicator.long()
      )
      # Concatenate the verb feature onto the embedded text. This now
      # has shape (batch_size, sequence_length, embedding_dim + binary_feature_dim).
      embedded_text_with_verb_indicator = torch.cat(
          [embedded_text_input, embedded_verb_indicator], -1
      )
      (
          batch_size,
          sequence_length,
          _,
      ) = embedded_text_with_verb_indicator.size()
  
      encoded_text = self.encoder(
          embedded_text_with_verb_indicator, mask
      )
  
      logits = self.tag_projection_layer(encoded_text)
      reshaped_log_probs = logits.view(-1, self.num_classes)
      class_probabilities = F.softmax(reshaped_log_probs, dim=-1).view(
          [batch_size, sequence_length, self.num_classes]
      )
      output_dict = {
          "logits": logits,
          "class_probabilities": class_probabilities,
      }
      if tags is not None:
          loss = sequence_cross_entropy_with_logits(
              logits, tags, mask, label_smoothing=self._label_smoothing
          )
          self.span_metric(class_probabilities, tags, mask)
          output_dict["loss"] = loss
  
      # We need to retain the mask in the output dictionary
      # so that we can crop the sequences to remove padding
      # when we do viterbi inference in self.decode.
      output_dict["mask"] = mask
  
      words, verbs = izip(*[(x["words"], x["verb"]) for x in metadata])
      if metadata is not None:
          output_dict["words"] = list(words)
          output_dict["verb"] = list(verbs)
      return output_dict
  
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 2 for calling the SemanticRoleLabeler obj's underlying member method code with example usage: obj.forward(tokens, verb_indicator, tags, metadata) and returns: output_dict