Entity-Linking-Tutorial

May 3, 2021 ยท View on GitHub

  • In this tutorial, we will implement a Bi-encoder based entity disambiguation system using the BC5CDR dataset and data from the MeSH knowledge base.

  • We will compare the surface-form based candidate generation with the Bi-encoder based one, to understand the power of Bi-encoder model in entity linking.

Docs for English

Docs for Japanese

Tutorial with Colab-Pro.

See here.

Environment Setup

  • First, create base environment with conda.
# If you don't use colab-pro, create environment from conda.
$ conda create -n allennlp python=3.7
$ conda activate allennlp
$ pip install -r requirements.txt

Preprocessing

  • First, download preprocessed files from here, then unzip.

  • Second, download BC5CDR dataset to ./dataset/ and unzip.

  • You have to place CDR_DevelopmentSet.PubTator.txt, CDR_TestSet.PubTator.txt and CDR_TrainingSet.PubTator.txt under ./dataset/.

  • Then, run python3 BC5CDRpreprocess.py and python3 preprocess_mesh.py.

Models and Scoring

Models

  • Surface-Candidate based

    biencoder

  • ANN-search based

    entire_biencoder

Scoring

  • Default: Dot product between mention and predicted entity.

    scoring

  • L2-distance and cosine similarity are also supported.

Experiment and Evaluation

$ rm -r serialization_dir # Remove pre-experiment result if you run `python3 main.py -debug` for debugging.
$ python3 main.py

Parameters

We only here note critical parameters for training and evaluation. For further detail, see parameters.py.

Parameter NameDescriptionDefault
batch_size_for_trainBatch size during learning. The more there are, the more the encoder will learn to choose the correct answer from more negative examples.16
lrLearning rate.1e-5
max_candidates_numDetermine how many candidates are to be generated for each mention by using surface form.5
search_method_for_faissThis specifies whether to use the cosine distance (cossim), inner product (indexflatip), or L2 distance (indexflatl2) when performing approximate neighborhood search.indexflatip

Result

  • Surface-Candidate based recall

    Generated Candidates Num51020
    dev_recall76.8079.9180.92
    test_recall74.3577.1478.25

batch_size_for_train: 16

  • Surface-Candidate based acc.

    Generated Candidates Num51020
    dev_acc59.8552.5647.23
    test_acc58.5151.3845.69
  • ANN-search Based

    (Generated Candidates Num: 50 (Fixed))

    Recall@X1 (Acc.)51050
    dev_recall21.5842.2850.4867.11
    test_recall21.5040.2947.9564.52

batch_size_for_train: 48

  • Surface-Candidate based acc.

    Generated Candidates Num51020
    dev_acc72.3968.2165.40
    test_acc70.9566.8763.72
  • ANN-search Based

    (Generated Candidates Num: 50 (Fixed))

    Recall@X1 (Acc.)51050
    dev_recall58.8674.3378.1483.10
    test_recall57.6673.1476.7381.39

LICENSE

MIT