class_docstr: Mixes several tensors by a learned weighting.
  
  Computes a parameterised scalar mixture of N tensors.
  This method was proposed by Liu et al. (2019) in the paper:
  "Linguistic Knowledge and Transferability of Contextual Representations" (https://arxiv.org/abs/1903.08855)
  
  The implementation is copied and slightly modified from the allennlp repository and is licensed under Apache 2.0.
  It can be found under:
  https://github.com/allenai/allennlp/blob/master/allennlp/modules/scalar_mix.py.
docstr: Inits scalar mix implementation.
  
  ``mixture = gamma * sum(s_k * tensor_k)`` where ``s = softmax(w)``, with ``w`` and ``gamma`` scalar parameters.
  
  Args:
      mixture_size: size of mixtures (usually the number of layers)
      trainable: weather or not the weights should be learnable.
docstr_tok: ["Inits","scalar","mix","implementation",".","``","mixture","=","gamma","*","sum","(","s_k","*","tensor_k",")","``","where","``","s","=","softmax","(","w",")","``",",","with","``","w","``","and","``","gamma","``","scalar","parameters",".","Args",":","mixture_size",":","size","of","mixtures","(","usually","the","number","of","layers",")","trainable",":","weather","or","not","the","weights","should","be","learnable","."]
code: def __init__(
      self, mixture_size: int, trainable: bool = False
  ) -> None:
      """Inits scalar mix implementation.
  
      ``mixture = gamma * sum(s_k * tensor_k)`` where ``s = softmax(w)``, with ``w`` and ``gamma`` scalar parameters.
  
      Args:
          mixture_size: size of mixtures (usually the number of layers)
          trainable: weather or not the weights should be learnable.
      """
      super().__init__()
      self.mixture_size = mixture_size
  
      initial_scalar_parameters = [0.0] * mixture_size
  
      self.scalar_parameters = ParameterList(
          [
              Parameter(
                  torch.tensor(
                      [initial_scalar_parameters[i]],
                      dtype=torch.float,
                      device=flair.device,
                  ),
                  requires_grad=trainable,
              )
              for i in range(mixture_size)
          ]
      )
      self.gamma = Parameter(
          torch.tensor(
              [1.0],
              dtype=torch.float,
              device=flair.device,
          ),
          requires_grad=trainable,
      )
  
imports: import inspect
  import logging
  from abc import abstractmethod
  from typing import Any, Dict, Generic, List, Sequence, Type, Union
  import torch
  from torch.nn import Parameter, ParameterList
  import flair
  from flair.data import DT, Sentence
label_desc: Use image node_id 1 to create a new ScalarMix object from inherited base classes: torch.nn with example: obj = ScalarMix(mixture_size, trainable)