docstr: Adapted from tensor2tensor/layers/modalities_test.py.
docstr_tok: ["Adapted","from","tensor2tensor\/layers\/modalities_test.py","."]
code: def testBottomInputs(self):
      """Adapted from tensor2tensor/layers/modalities_test.py."""
      batch_size = 10
      num_datashards = 5
      length = 5
      vocab_size = [2000, 500, 2500]
      hidden_size = 9
      model_hparams = common_hparams.basic_params1()
      model_hparams.hidden_size = hidden_size
      model_hparams.mode = tf_estimator.ModeKeys.TRAIN
      x = np.stack(
          [
              -1
              + np.random.random_integers(
                  vocab_size[i], size=(batch_size, length, 1)
              )
              for i in range(len(vocab_size))
          ],
          axis=3,
      )
      data_parallelism = expert_utils.Parallelism(
          ["/device:CPU:0"] * num_datashards
      )
      bottom = functools.partial(
          modalities.bottom,
          model_hparams=model_hparams,
          vocab_size=vocab_size,
      )
      with self.test_session() as session:
          xs = tf.split(x, num_datashards)
          sharded_output = data_parallelism(bottom, xs)
          output = tf.concat(sharded_output, 0)
          session.run(tf.global_variables_initializer())
          res = session.run(output)
      self.assertEqual(res.shape, (batch_size, length, 1, hidden_size))
  
file_path: magenta/magenta/models/score2perf/modalities_test.py
imports: import functools
  from magenta.models.score2perf import modalities
  import numpy
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.utils import expert_utils
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 1 for calling the ModalitiesTest obj's underlying member method code with example usage: obj.testBottomInputs() without return types