import math


def embedding_dim(vocab_size: int):
  """Calculate a reasonable embedding size for a vocabulary.

  Rule of thumb is ``6 * sqrt(sqrt(vocab_size))``.

  Args:
    vocab_size: Size of the input vocabulary.

  Returns:
    The embedding size to use.

  Raises:
    ValueError: if ``vocab_size`` is invalid.
  """
  if not vocab_size or (vocab_size <= 0):
    raise ValueError("Invalid vocab_size %g." % vocab_size)
  return int(round(6.0 * math.sqrt(math.sqrt(vocab_size))))