In a nutshell, GENRE uses a sequence-to-sequence approach to entity retrieval (e.g., linking), based on fine-tuned BART architecture. GENRE performs retrieval generating the unique entity name conditioned on the input text using constrained beam search to only generate valid identifiers. The model was first released in the facebookresearch/GENRE repository using fairseq (the transformers models are obtained with a conversion script similar to this.
This model was trained on the full training set of BLINK (i.e., 9M datapoints for entity-disambiguation grounded on Wikipedia).
BibTeX entry and citation info
Please consider citing our works if you use code from this repository.
bibtex
1@inproceedings{decao2020autoregressive,
2 title={Autoregressive Entity Retrieval},
3 author={Nicola {De Cao} and Gautier Izacard and Sebastian Riedel and Fabio Petroni},
4 booktitle={International Conference on Learning Representations},
5 url={https://openreview.net/forum?id=5k8F6UU39V},
6 year={2021}
7}
Usage
Here is an example of generation for Wikipedia page disambiguation:
python
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
23# OPTIONAL: load the prefix tree (trie), you need to additionally download4# https://huggingface.co/facebook/genre-linking-blink/blob/main/trie.py and 5# https://huggingface.co/facebook/genre-linking-blink/blob/main/kilt_titles_trie_dict.pkl6# import pickle7# from trie import Trie8# with open("kilt_titles_trie_dict.pkl", "rb") as f:9# trie = Trie.load_from_dict(pickle.load(f))1011tokenizer = AutoTokenizer.from_pretrained("facebook/genre-linking-blink")12model = AutoModelForSeq2SeqLM.from_pretrained("facebook/genre-linking-blink").eval()1314sentences =["Einstein was a [START_ENT] German [END_ENT] physicist."]1516outputs = model.generate(17**tokenizer(sentences, return_tensors="pt"),18 num_beams=5,19 num_return_sequences=5,20# OPTIONAL: use constrained beam search21# prefix_allowed_tokens_fn=lambda batch_id, sent: trie.get(sent.tolist()),22)2324tokenizer.batch_decode(outputs, skip_special_tokens=True)
which outputs the following top-5 predictions (using constrained beam search)