                  neg_exs_list.append(train_neg.get(inst_cluster, []))
  
              self.update(article_doc, pos_ex_list, neg_exs_list, losses=losses)
              p, r, fscore = self._test_dev(dev_instances, dev_pos, dev_neg, dev_doc)
              print(round(fscore, 1))
  
          if to_print:
              print("Trained on", instance_count, "instance clusters")
  
      def _test_dev(self, dev_instances, dev_pos, dev_neg, dev_doc):
 
</s> remove                     best_entity, lowest_mse = self._predict(examples, article_doc)
 </s> add                     best_entity, highest_prob = self._predict(examples, article_doc) </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             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 </s> remove         return best_entity, lowest_mse
 </s> add         return best_entity, highest_prob
            if self.PRINT_F:
                print(round(fscore, 1))
                  neg_exs_list.append(train_neg.get(inst_cluster, []))
  
              self.update(article_doc, pos_ex_list, neg_exs_list, losses=losses)
              p, r, fscore = self._test_dev(dev_instances, dev_pos, dev_neg, dev_doc)
            if self.PRINT_F:
                print(round(fscore, 1))
  
          if to_print:
              print("Trained on", instance_count, "instance clusters")
  
      def _test_dev(self, dev_instances, dev_pos, dev_neg, dev_doc):
keep keep keep keep replace keep keep keep keep keep
 implement loss function using dot product and prob estimate per candidate cluster 
examples/pipeline/wiki_entity_linking/train_el.py