code: def test_scalar_mix_layer_norm(self):
      mixture = ScalarMix(3, do_layer_norm="scalar_norm_reg")
  
      tensors = [torch.randn([3, 4, 5]) for _ in range(3)]
      numpy_mask = numpy.ones((3, 4), dtype="int32")
      numpy_mask[1, 2:] = 0
      mask = torch.from_numpy(numpy_mask).bool()
  
      weights = [0.1, 0.2, 0.3]
      for k in range(3):
          mixture.scalar_parameters[k].data[0] = weights[k]
      mixture.gamma.data[0] = 0.5
      result = mixture(tensors, mask)
  
      normed_weights = numpy.exp(weights) / numpy.sum(
          numpy.exp(weights)
      )
      expected_result = numpy.zeros((3, 4, 5))
      for k in range(3):
          mean = numpy.mean(tensors[k].data.numpy()[numpy_mask == 1])
          std = numpy.std(tensors[k].data.numpy()[numpy_mask == 1])
          normed_tensor = (tensors[k].data.numpy() - mean) / (
              std + util.tiny_value_of_dtype(torch.float)
          )
          expected_result += normed_tensor * normed_weights[k]
      expected_result *= 0.5
  
      numpy.testing.assert_almost_equal(
          expected_result, result.data.numpy(), decimal=6
      )
  
file_path: allennlp/tests/modules/scalar_mix_test.py
imports: import torch
  import pytest
  import numpy
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.common.checks import ConfigurationError
  from allennlp.modules import ScalarMix
  from allennlp.nn import util
label_desc: Use image node_id 5 for calling the TestScalarMix obj's underlying member method code with example usage: obj.test_scalar_mix_layer_norm() without return types