class_docstr: Computes a parameterised scalar mixture of N tensors, `mixture = gamma * sum(s_k * tensor_k)`
  where `s = softmax(w)`, with `w` and `gamma` scalar parameters.
  
  In addition, if `do_layer_norm=True` then apply layer normalization to each tensor
  before weighting.
code: def __init__(
      self,
      mixture_size: int,
      do_layer_norm: bool = False,
      initial_scalar_parameters: List[float] = None,
      trainable: bool = True,
  ) -> None:
      super().__init__()
      self.mixture_size = mixture_size
      self.do_layer_norm = do_layer_norm
  
      if initial_scalar_parameters is None:
          initial_scalar_parameters = [0.0] * mixture_size
      elif len(initial_scalar_parameters) != mixture_size:
          raise ConfigurationError(
              "Length of initial_scalar_parameters {} differs "
              "from mixture_size {}".format(
                  initial_scalar_parameters, mixture_size
              )
          )
  
      self.scalar_parameters = ParameterList(
          [
              Parameter(
                  torch.FloatTensor([initial_scalar_parameters[i]]),
                  requires_grad=trainable,
              )
              for i in range(mixture_size)
          ]
      )
      self.gamma = Parameter(
          torch.FloatTensor([1.0]), requires_grad=trainable
      )
  
file_path: allennlp/allennlp/modules/scalar_mix.py
imports: from typing import List
  import torch
  from torch.nn import ParameterList, Parameter
  from allennlp.common.checks import ConfigurationError
  from allennlp.nn import util
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, do_layer_norm, initial_scalar_parameters, trainable)