class_docstr: A classification `Head`.  Takes encoded text, gets a single vector out of it, runs an optional
  feedforward layer on that vector, then classifies it into some label space.
  
  Registered as a `Head` with name "classifier".
  
  # Parameters
  
  vocab : `Vocabulary`
      Used to get the number of labels, if `num_labels` is not provided, and to translate label
      indices to strings in `make_output_human_readable`.
  seq2vec_encoder : `Seq2VecEncoder`
      The input to this module is assumed to be a sequence of encoded vectors.  We use a
      `Seq2VecEncoder` to compress this into a single vector on which we can perform
      classification.
  feedforward : `FeedForward`, optional, (default = `None`)
      An optional feedforward layer to apply on the pooled output before performing the
      classification.
  input_dim : `int`, optional (default = `None`)
      We need to know how many dimensions to use for the final classification weight matrix.  If
      you have provided either a `seq2vec_encoder` or a `feedforward` module, we can get the
      correct size from those objects.  If you use default values for both of those parameters,
      then you must provide this parameter, so that we know the size of that encoding.
  dropout : `float`, optional (default = `None`)
      Dropout percentage to use.
  num_labels : `int`, optional (default = `None`)
      Number of labels to project to in classification layer. By default, the classification layer will
      project to the size of the vocabulary namespace corresponding to labels.
  label_namespace : `str`, optional (default = `"labels"`)
      Vocabulary namespace corresponding to labels. By default, we use the "labels" namespace.
class_docstr_tok: ["A","classification","`","Head","`",".","Takes","encoded","text",",","gets","a","single","vector","out","of","it",",","runs","an","optional","feedforward","layer","on","that","vector",",","then","classifies","it","into","some","label","space",".","Registered","as","a","`","Head","`","with","name","``","classifier","''",".","#","Parameters","vocab",":","`","Vocabulary","`","Used","to","get","the","number","of","labels",",","if","`","num_labels","`","is","not","provided",",","and","to","translate","label","indices","to","strings","in","`","make_output_human_readable","`",".","seq2vec_encoder",":","`","Seq2VecEncoder","`","The","input","to","this","module","is","assumed","to","be","a","sequence","of","encoded","vectors",".","We","use","a","`","Seq2VecEncoder","`","to","compress","this","into","a","single","vector","on","which","we","can","perform","classification",".","feedforward",":","`","FeedForward","`",",","optional",",","(","default","=","`","None","`",")","An","optional","feedforward","layer","to","apply","on","the","pooled","output","before","performing","the","classification",".","input_dim",":","`","int","`",",","optional","(","default","=","`","None","`",")","We","need","to","know","how","many","dimensions","to","use","for","the","final","classification","weight","matrix",".","If","you","have","provided","either","a","`","seq2vec_encoder","`","or","a","`","feedforward","`","module",",","we","can","get","the","correct","size","from","those","objects",".","If","you","use","default","values","for","both","of","those","parameters",",","then","you","must","provide","this","parameter",",","so","that","we","know","the","size","of","that","encoding",".","dropout",":","`","float","`",",","optional","(","default","=","`","None","`",")","Dropout","percentage","to","use",".","num_labels",":","`","int","`",",","optional","(","default","=","`","None","`",")","Number","of","labels","to","project","to","in","classification","layer",".","By","default",",","the","classification","layer","will","project","to","the","size","of","the","vocabulary","namespace","corresponding","to","labels",".","label_namespace",":","`","str","`",",","optional","(","default","=","`","``","labels","''","`",")","Vocabulary","namespace","corresponding","to","labels",".","By","default",",","we","use","the","``","labels","''","namespace","."]
code: def __init__(
      self,
      vocab: Vocabulary,
      seq2vec_encoder: Seq2VecEncoder,
      feedforward: Optional[FeedForward] = None,
      input_dim: int = None,
      dropout: float = None,
      num_labels: int = None,
      label_namespace: str = "labels",
  ) -> None:
      super().__init__(vocab)
      self._seq2vec_encoder = seq2vec_encoder
      self._feedforward = feedforward
      if self._feedforward is not None:
          self._classifier_input_dim = (
              self._feedforward.get_output_dim()
          )
      else:
          self._classifier_input_dim = (
              self._seq2vec_encoder.get_output_dim() or input_dim
          )
  
      if self._classifier_input_dim is None:
          raise ValueError("No input dimension given!")
  
      if dropout:
          self._dropout = torch.nn.Dropout(dropout)
      else:
          self._dropout = None
      self._label_namespace = label_namespace
  
      if num_labels:
          self._num_labels = num_labels
      else:
          self._num_labels = vocab.get_vocab_size(
              namespace=self._label_namespace
          )
      self._classification_layer = torch.nn.Linear(
          self._classifier_input_dim, self._num_labels
      )
      self._accuracy = CategoricalAccuracy()
      self._loss = torch.nn.CrossEntropyLoss()
  
file_path: allennlp/allennlp/models/heads/classifier_head.py
imports: from typing import Dict, Optional
  import torch
  from allennlp.data import Vocabulary
  from allennlp.models.heads.head import Head
  from allennlp.modules import FeedForward, Seq2VecEncoder
  from allennlp.training.metrics import CategoricalAccuracy
label_desc: Use image node_id 1 to create a new ClassifierHead object from inherited base classes: Head with example: obj = ClassifierHead(vocab, seq2vec_encoder, feedforward, input_dim, dropout, num_labels, label_namespace)