code: def from_config(
      cls,
      config,
      metadata: Optional[FieldMeta] = None,
      labels: Optional[Vocabulary] = None,
  ):
      label_weights = (
          get_label_weights(labels.idx, config.label_weights)
          if config.label_weights
          else None
      )
      assert (
          config.score_type == OutputScore.raw_cosine
          or config.score_type == OutputScore.norm_cosine
          or config.score_type == OutputScore.sigmoid_cosine
      ), f"Invalid score_type {config.score_type}. See OutputScore enum."
      return cls(
          list(labels) if labels is not None else None,
          create_loss(config.loss, weight=label_weights),
          config.score_threshold,
          config.score_type,
      )
  
imports: from enum import IntEnum, unique
  from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  import torch.nn.functional
  from pytext.config.component import create_loss
  from pytext.data.utils import Vocabulary
  from pytext.fields import FieldMeta
  from pytext.loss import BinaryCrossEntropyLoss, CosineEmbeddingLoss, MAELoss, MSELoss, NLLLoss
  from pytext.models.output_layers.output_layer_base import OutputLayerBase
  from pytext.utils.label import get_label_weights
  from pytext.utils.usage import log_class_usage
label_desc: Use image node_id 1 for calling the PairwiseCosineDistanceOutputLayer obj's underlying member method code with example usage: obj.from_config(cls, config, metadata, labels) and returns: cls