  
  
  class EL_Model():
  
      labels = ["MATCH", "NOMATCH"]
      name = "entity_linker"
  
      def __init__(self, kb, nlp):
 
</s> remove     def _get_labels(self):
        return tuple(self.labels)
 </s> add     @staticmethod
    def _calculate_dot_exp(vector1, vector2_transposed):
        e = np.exp(vector1.dot(vector2_transposed))
        return e </s> remove         lowest_mse = None
 </s> add         highest_prob = None </s> remove         diffs = (vector1 - vector2)
        error_sum = (diffs ** 2).sum()
        mean_square_error = error_sum / len(vector1)
        return float(mean_square_error), diffs
 </s> add         vector1_t = vector1.transpose()
        e = self._calculate_dot_exp(vector2, vector1_t)
        e_sum = 0
        for v in allvectors:
            e_sum += self._calculate_dot_exp(v, vector1_t)

        return float(e / e_sum)

    @staticmethod
    def _calculate_loss(true_prob, all_probs):
        """ all_probs should include true_prob ! """
        return -1 * np.log(true_prob / sum(all_probs))

    @staticmethod
    def _calculate_doc_gradient(loss, doc_vector, true_vector, false_vectors):
        gradient = np.zeros(len(doc_vector))
        for i in range(len(doc_vector)):
            min_false = min(x[i] for x in false_vectors)
            max_false = max(x[i] for x in false_vectors)

            if true_vector[i] > max_false:
                if doc_vector[i] > 0:
                    gradient[i] = 0
                else:
                    gradient[i] = -loss
            elif true_vector[i] < min_false:
                if doc_vector[i] > 0:
                    gradient[i] = loss
                if doc_vector[i] < 0:
                    gradient[i] = 0
            else:
                target = 0  # non-distinctive vector positions should convert to 0
                gradient[i] = doc_vector[i] - target

        return gradient </s> remove         self.entity_encoder = self._simple_encoder(in_width=300, out_width=96)
        self.article_encoder = self._simple_encoder(in_width=300, out_width=96)
 </s> add         self.entity_encoder = self._simple_encoder(in_width=self.INPUT_DIM, out_width=self.OUTPUT_DIM)
        self.article_encoder = self._simple_encoder(in_width=self.INPUT_DIM, out_width=self.OUTPUT_DIM) </s> remove             entity_encoding = self.entity_encoder([entity])
            mse, _ = self._calculate_similarity(doc_encoding, entity_encoding)
            if not best_entity or mse < lowest_mse:
                lowest_mse = mse
 </s> add             entity_encoding = entity_to_vector[entity]
            prob = self._calculate_probability(doc_encoding, entity_encoding, entity_to_vector.values())
            if not best_entity or prob > highest_prob:
                highest_prob = prob
    INPUT_DIM = 300
    OUTPUT_DIM = 5  # 96
    PRINT_LOSS = True
    PRINT_F = True

  
  
  class EL_Model():
  
    INPUT_DIM = 300
    OUTPUT_DIM = 5  # 96
    PRINT_LOSS = True
    PRINT_F = True

      labels = ["MATCH", "NOMATCH"]
      name = "entity_linker"
  
      def __init__(self, kb, nlp):
keep keep keep add keep keep keep keep
 implement loss function using dot product and prob estimate per candidate cluster 
examples/pipeline/wiki_entity_linking/train_el.py