class_docstr: Output layer for document classification models.
  It supports `CrossEntropyLoss` and `BinaryCrossEntropyLoss` per document.
  
  Args:
      loss_fn (Union[CrossEntropyLoss, BinaryCrossEntropyLoss]):
          The loss function to use for computing loss. Defaults to None.
  
  Attributes:
      loss_fn: The loss function to use for computing loss.
code: def from_config(
      cls,
      config: Config,
      metadata: Optional[FieldMeta] = None,
      labels: Optional[Vocabulary] = None,
  ):
      if labels is not None:
          vocab = list(labels)
          vocab_dict = labels.idx
          pad_token_idx = labels.idx.get(
              labels.pad_token, Padding.DEFAULT_LABEL_PAD_IDX
          )
      else:
          vocab = metadata.vocab.itos
          vocab_dict = metadata.vocab.stoi
          pad_token_idx = getattr(metadata, "pad_token_idx", -1)
  
      label_weights = (
          get_custom_or_automatic_label_weights(
              vocab_dict,
              labels.counts,
              config.label_weights,
              config.automatic_label_weighting_method,
          )
          if config.label_weights
          or config.automatic_label_weighting_method
          else None
      )
  
      loss = create_loss(
          config.loss, weight=label_weights, ignore_index=pad_token_idx
      )
  
      if isinstance(loss, BinaryCrossEntropyLoss):
          cls = BinaryClassificationOutputLayer
      elif isinstance(loss, MultiLabelSoftMarginLoss):
          loss = create_loss(config.loss, pos_weight=label_weights)
          cls = MultiLabelOutputLayer
      elif isinstance(loss, BinaryCrossEntropyWithLogitsLoss):
          loss = create_loss(config.loss, pos_weight=label_weights)
          cls = MultiLabelOutputLayer
      else:
          cls = MulticlassOutputLayer
  
      return cls(vocab, loss, config)
  
imports: from typing import Dict, List, Optional, Union
  import torch
  import torch.nn.functional
  from caffe2.python import core
  from pytext.common import Padding
  from pytext.config.component import create_loss
  from pytext.data.utils import Vocabulary
  from pytext.fields import FieldMeta
  from pytext.loss import AUCPRHingeLoss, BinaryCrossEntropyLoss, BinaryCrossEntropyWithLogitsLoss, CrossEntropyLoss, HingeLoss, KLDivergenceBCELoss, KLDivergenceCELoss, LabelSmoothedCrossEntropyLoss, MultiLabelSoftMarginLoss
  from pytext.utils.label import get_custom_or_automatic_label_weights
  from pytext.utils.typing import WeightingMethod
  from torch import jit
  from .output_layer_base import OutputLayerBase
  from .utils import OutputLayerUtils
label_desc: Use image node_id 1 for calling the ClassificationOutputLayer obj's underlying member method code with example usage: obj.from_config(cls, config, metadata, labels) and returns: cls