  def read_nlp_kb(model_dir, kb_file):
      nlp = spacy.load(model_dir)
      kb = KnowledgeBase(vocab=nlp.vocab)
      kb.load_bulk(kb_file)
      logger.info("kb entities: {}".format(kb.get_size_entities()))
      logger.info("kb aliases: {}".format(kb.get_size_aliases()))
      return nlp, kb
 
</s> remove def read_nlp_kb(model_dir, kb_file):
    nlp = spacy.load(model_dir)
 </s> add def read_kb(nlp, kb_file): </s> remove     logger.info("STEP 6: creating the KB at {}".format(kb_path))
    kb = kb_creator.create_kb(
        nlp=nlp,
        max_entities_per_alias=max_per_alias,
        min_entity_freq=min_freq,
        min_occ=min_pair,
        entity_def_input=entity_defs_path,
        entity_descr_path=entity_descr_path,
        count_input=entity_freq_path,
        prior_prob_input=prior_prob_path,
        entity_vector_length=entity_vector_length,
    )

    kb.dump(kb_path)
    nlp.to_disk(output_dir / KB_MODEL_DIR)
 </s> add     if not kb_path.exists():
        logger.info("STEP 6: Creating the KB at {}".format(kb_path))
        kb = kb_creator.create_kb(
            nlp=nlp,
            max_entities_per_alias=max_per_alias,
            min_entity_freq=min_freq,
            min_occ=min_pair,
            entity_def_path=entity_defs_path,
            entity_descr_path=entity_descr_path,
            entity_alias_path=entity_alias_path,
            entity_freq_path=entity_freq_path,
            prior_prob_path=prior_prob_path,
            entity_vector_length=entity_vector_length,
        )
        kb.dump(kb_path)
        logger.info("kb entities: {}".format(kb.get_size_entities()))
        logger.info("kb aliases: {}".format(kb.get_size_aliases()))
        nlp.to_disk(output_dir / KB_MODEL_DIR)
    else:
        logger.info("STEP 6: KB already exists at {}".format(kb_path)) </s> remove     logger.info("STEP 1: loading model from {}".format(nlp_dir))
    nlp, kb = read_nlp_kb(nlp_dir, kb_path)
 </s> add     logger.info("STEP 1a: Loading model from {}".format(nlp_dir))
    nlp = spacy.load(nlp_dir)
    logger.info("STEP 1b: Loading KB from {}".format(kb_path))
    kb = read_kb(nlp, kb_path) </s> remove     logger.info("KB size: {} entities, {} aliases".format(
        kb.get_size_entities(),
        kb.get_size_aliases()))

    logger.info("Done with kb")
    return kb

 </s> add 
    return kb
  def read_nlp_kb(model_dir, kb_file):
      nlp = spacy.load(model_dir)
      kb = KnowledgeBase(vocab=nlp.vocab)
      kb.load_bulk(kb_file)
    return kb
    return kb
    return kb
keep keep keep keep replace replace replace
 KB extensions and better parsing of WikiData (#4375)

* fix overflow error on windows

* more documentation & logging fixes

* md fix

* 3 different limit parameters to play with execution time

* bug fixes directory locations

* small fixes

* exclude dev test articles from prior probabilities stats

* small fixes

* filtering wikidata entities, removing numeric and meta items

* adding aliases from wikidata also to the KB

* fix adding WD aliases

* adding also new aliases to previously added entities

* fixing comma's

* small doc fixes

* adding subclassof filtering

* append alias functionality in KB

* prevent appending the same entity-alias pair

* fix for appending WD aliases

* remove date filter

* remove unnecessary import

* small corrections and reformatting

* remove WD aliases for now (too slow)

* removing numeric entities from training and evaluation

* small fixes

* shortcut during prediction if there is only one candidate

* add counts and fscore logging, remove FP NER from evaluation

* fix entity_linker.predict to take docs instead of single sentences

* remove enumeration sentences from the WP dataset

* entity_linker.update to process full doc instead of single sentence

* spelling corrections and dump locations in readme

* NLP IO fix

* reading KB is unnecessary at the end of the pipeline

* small logging fix

* remove empty files 
bin/wiki_entity_linking/kb_creator.py