class_docstr: This ``SimpleTagger`` simply encodes a sequence of text with a stacked ``Seq2SeqEncoder``, then
  predicts a tag for each token in the sequence.
  
  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.
  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.
class_docstr_tok: ["This","``","SimpleTagger","``","simply","encodes","a","sequence","of","text","with","a","stacked","``","Seq2SeqEncoder","``",",","then","predicts","a","tag","for","each","token","in","the","sequence",".","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",".","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","."]
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.
  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 to be tagged under a 'words' key.
  
  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",".","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","to","be","tagged","under","a","'words","'","key",".","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, tokens, tags=None, metadata=None):  # type: ignore
      # 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.
      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 to be tagged under a 'words' key.
  
      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.text_field_embedder(tokens)
      batch_size, sequence_length, _ = embedded_text_input.size()
      mask = get_text_field_mask(tokens)
      encoded_text = self.encoder(embedded_text_input, 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)
          for metric in list(self.metrics.values()):
              metric(logits, tags, mask.float())
          output_dict["loss"] = loss
  
      if metadata is not None:
          output_dict["words"] = [x["words"] for x in metadata]
      return output_dict
  
file_path: magnitude/pymagnitude/third_party/allennlp/models/simple_tagger.py
imports: from __future__ import absolute_import
  import numpy
  import torch
  from torch.nn.modules.linear import Linear
  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.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.training.metrics import CategoricalAccuracy
label_desc: Use image node_id 2 for calling the SimpleTagger obj's underlying member method code with example usage: obj.forward(tokens, tags, metadata) and returns: output_dict