import tensorflow as tf

  if anchor_match_mining_distance_matrix is None:
    anchor_match_mining_distance_matrix = anchor_match_distance_matrix

  if use_semi_hard:
    if anchor_positive_mining_distances is None:
      raise ValueError('Positive match embeddings must be specified to compute '
                       'semi-hard distances.')
    anchor_positive_mining_distances = tf.expand_dims(
        anchor_positive_mining_distances, axis=-1)
    indicators &= (
        anchor_match_mining_distance_matrix > anchor_positive_mining_distances)

  def find_hard_distances(distance_matrix, indicator_matrix):
    distance_matrix = tf.where(
