(embeddings, onehot_labels)
return prototypes
Compute class prototypes over the last dimension of embeddings.

  Args:
    embeddings: Tensor of examples of shape [num_examples] + embedding_shape
    onehot_labels: Tensor of one-hot encoded labels of shape [num_examples,
      num_classes].

  Returns:
    prototypes: Tensor of class prototypes of shape [num_classes,
    embedding_size].
Compute class prototypes over the last dimension of embeddings.
Compute class prototypes over the last dimension of embeddings .
def compute_prototypes(embeddings, onehot_labels):
  """Compute class prototypes over the last dimension of embeddings.

  Args:
    embeddings: Tensor of examples of shape [num_examples] + embedding_shape
    onehot_labels: Tensor of one-hot encoded labels of shape [num_examples,
      num_classes].

  Returns:
    prototypes: Tensor of class prototypes of shape [num_classes,
    embedding_size].
  """
  # Sums each class' embeddings. [num classes] + embedding shape.
  embedding_indices = 'klm'[:len(embeddings.shape) - 1]
  class_sums = tf.einsum('ij,i{0}->j{0}'.format(embedding_indices),
                         onehot_labels, embeddings)

  # The prototype of each class is the averaged embedding of its examples.
  class_num_images = tf.reduce_sum(input_tensor=onehot_labels, axis=0)  # [way].
  prototypes = tf.math.divide_no_nan(
      class_sums,
      tf.reshape(class_num_images, [-1] + [1] * (len(embeddings.shape) - 1)))

  return prototypes
def compute_prototypes ( embeddings , onehot_labels ) : # Sums each class' embeddings. [num classes] + embedding shape. embedding_indices = 'klm' [ : len ( embeddings . shape ) - 1 ] class_sums = tf . einsum ( 'ij,i{0}->j{0}' . format ( embedding_indices ) , onehot_labels , embeddings ) # The prototype of each class is the averaged embedding of its examples. class_num_images = tf . reduce_sum ( input_tensor = onehot_labels , axis = 0 ) # [way]. prototypes = tf . math . divide_no_nan ( class_sums , tf . reshape ( class_num_images , [ - 1 ] + [ 1 ] * ( len ( embeddings . shape ) - 1 ) ) ) return prototypes