                                  # currently feeding the gold data one entity per sentence at a time
                                  gold_start = int(start) - found_ent.sent.start_char
                                  gold_end = int(end) - found_ent.sent.start_char
  
                                  # add both pos and neg examples (in random order)
                                  # this will exclude examples not in the KB
                                  if kb:
                                      gold_entities = {}
                                      candidates = kb.get_candidates(alias)
                                      candidate_ids = [c.entity_ for c in candidates]
                                      random.shuffle(candidate_ids)
                                      for kb_id in candidate_ids:
                                          entry = (gold_start, gold_end, kb_id)
                                          if kb_id != wd_id:
                                              gold_entities[entry] = 0.0
                                          else:
                                              gold_entities[entry] = 1.0
                                  # keep all positive examples
                                  else:
                                      entry = (gold_start, gold_end, wd_id)
 
</s> remove                                 # currently feeding the gold data one entity per sentence at a time
 </s> add  </s> remove                                             gold_entities[entry] = 1.0
                                # keep all positive examples
                                else:
                                    entry = (gold_start, gold_end, wd_id)
                                    gold_entities = {entry: 1.0}

                                gold = GoldParse(doc=sent, links=gold_entities)
                                data.append((sent, gold))
                                total_entities += 1
                                if len(data) % 2500 == 0:
                                    print(" -read", total_entities, "entities")
 </s> add                                             found_useful = True
                                            value_by_id = {wd_id: 1.0}
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                    # currently feeding the gold data one entity per sentence at a time
                                    # setting all other entities to empty gold dictionary
                                    else:
                                        gold_entities[(ent.start_char, ent.end_char)] = {}
                                if found_useful:
                                    gold = GoldParse(doc=sent, links=gold_entities)
                                    data.append((sent, gold))
                                    total_entities += 1
                                    if len(data) % 2500 == 0:
                                        print(" -read", total_entities, "entities") </s> remove                     if candidates:
 </s> add                     if not candidates:
                        final_kb_ids.append(self.NIL)  # no prediction possible for this entity
                    else: </s> remove         links (dict): A dict with `(start_char, end_char, kb_id)` keys,
            representing the external ID of an entity in a knowledge base,
            and the values being either 1.0 or 0.0, indicating positive and
            negative examples, respectively.
 </s> add         links (dict): A dict with `(start_char, end_char)` keys,
            and the values being dicts with kb_id:value entries,
            representing the external IDs in a knowledge base (KB)
            mapped to either 1.0 or 0.0, indicating positive and
            negative examples respectively. </s> remove                 entity_encoding = self.kb.get_vector(kb_id)
                prior_prob = self.kb.get_prior_prob(kb_id, mention)

                gold_ent = ents_by_offset[str(ent.start_char) + "_" + str(ent.end_char)]
                assert gold_ent is not None
                type_vector = [0 for i in range(len(type_to_int))]
                if len(type_to_int) > 0:
                    type_vector[type_to_int[gold_ent.label_]] = 1

                # store data
                entity_encodings.append(entity_encoding)
                context_docs.append(doc)
                type_vectors.append(type_vector)

                if self.cfg.get("prior_weight", 1) > 0:
                    priors.append([prior_prob])
                else:
                    priors.append([0])
 </s> add                 for kb_id, value in kb_dict.items():
                    entity_encoding = self.kb.get_vector(kb_id)
                    prior_prob = self.kb.get_prior_prob(kb_id, mention)

                    gold_ent = ents_by_offset[str(ent.start_char) + "_" + str(ent.end_char)]
                    assert gold_ent is not None
                    type_vector = [0 for i in range(len(type_to_int))]
                    if len(type_to_int) > 0:
                        type_vector[type_to_int[gold_ent.label_]] = 1

                    # store data
                    entity_encodings.append(entity_encoding)
                    context_docs.append(doc)
                    type_vectors.append(type_vector)

                    if self.cfg.get("prior_weight", 1) > 0:
                        priors.append([prior_prob])
                    else:
                        priors.append([0])
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                  # currently feeding the gold data one entity per sentence at a time
                                  gold_start = int(start) - found_ent.sent.start_char
                                  gold_end = int(end) - found_ent.sent.start_char
  
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                gold_entities = {}
                                found_useful = False
                                for ent in sent.ents:
                                    if ent.start_char == gold_start and ent.end_char == gold_end:
                                        # add both pos and neg examples (in random order)
                                        # this will exclude examples not in the KB
                                        if kb:
                                            value_by_id = {}
                                            candidates = kb.get_candidates(alias)
                                            candidate_ids = [c.entity_ for c in candidates]
                                            random.shuffle(candidate_ids)
                                            for kb_id in candidate_ids:
                                                found_useful = True
                                                if kb_id != wd_id:
                                                    value_by_id[kb_id] = 0.0
                                                else:
                                                    value_by_id[kb_id] = 1.0
                                            gold_entities[(ent.start_char, ent.end_char)] = value_by_id
                                        # if no KB, keep all positive examples
                                          else:
                                              gold_entities[entry] = 1.0
                                  # keep all positive examples
                                  else:
                                      entry = (gold_start, gold_end, wd_id)
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 have gold.links correspond exactly to doc.ents 
bin/wiki_entity_linking/training_set_creator.py