code: def calculate_bias_shape(input_shape, bias_dims):
    
    input_rank = len(input_shape)
    # If None, default is to use all dimensions.
    if bias_dims is None:
      return input_shape[1:]
    # If empty list, use a scalar bias.
    elif not bias_dims:
      return ()
    # Otherwise, calculate bias_shape from bias_dims.
    else:
      bias_shape = [1] * input_rank
      # Populate bias dimensions.
      for dim in bias_dims:
        dim %= input_rank
        if dim == 0:
          raise ValueError("Cannot apply bias across the minibatch dimension.")
        bias_shape[dim] = input_shape[dim]
      # Strip leading unit dimensions.
      start = input_rank
      for dim in xrange(1, input_rank):
        if bias_shape[dim] != 1:
          start = dim
          break
      return tuple(bias_shape[start:])
docs: Calculate `bias_shape` based on the `input_shape` and `bias_dims`.
  
    Args:
      input_shape: Shape of the input being passed into the module. The leading
          dimension is the minibatch size.
      bias_dims: The dimensions that bias should be applied over. The remaining
          dimensions will get broadcasted over.
  
    Returns:
      bias_shape: Tuple corresponding to the shape of bias Variable to create.
  
    Raises:
      ValueError: If the user attempts to add bias over the minibatch dimension,
          e.g. `bias_dims=[0]`.