def ids_tensor(shape,
               vocab_size,
               dynamic_batch_size,
               rng=None,
               name=None,
               seed=None):
  """Creates a random int32 tensor of the shape within the vocab size."""
  if rng is None:
    rng = random.Random()
  if seed is not None:
    rng.seed(seed)

  total_dims = 1
  for dim in shape:
    total_dims *= dim

  values = []
  for _ in range(total_dims):
    values.append(rng.randint(0, vocab_size - 1))

  const_tensor = tf.constant(
      value=values, dtype=tf.int32, shape=shape, name=name)

  if dynamic_batch_size:
    placeholder_shape = copy.deepcopy(shape)
    if dynamic_batch_size:
      placeholder_shape[0] = None
    # Rather than having to pass back out values for the feed_dict all over
    # the place, we use placholder_with_default and always use those defaults
    # during testing.
    return tf.placeholder_with_default(const_tensor, shape=placeholder_shape)
  else:
    return const_tensor
Creates a random int32 tensor of the shape within the vocab size.
language/canine/modeling_test.py