def l2_normalize(v, axis=0):
  """Divide by the L2-norm to normalize the input vector(s).

  For the edge case of the zero vector, this simply returns zero.

  Args:
    v: Numpy vector or matrix.
    axis: Dimension along which to normalize.

  Returns:
    normalized_v: Vector(s) `v` normalized to a unit vector.
  """
  norm = np.sqrt(np.square(v).sum(axis=axis, keepdims=True))
  # Set zero-norm elements to 1 to avoid NaN when dividing.
  norm[norm == 0] = 1.
  return v / norm
Divide by the L2-norm to normalize the input vector(s).

  For the edge case of the zero vector, this simply returns zero.

  Args:
    v: Numpy vector or matrix.
    axis: Dimension along which to normalize.

  Returns:
    normalized_v: Vector(s) `v` normalized to a unit vector.
  
language/common/inputs/embedding_utils.py