Relik
English
riccorl commited on
Commit
c28a0cf
β€’
1 Parent(s): 50d96b3

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +178 -0
README.md ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ ---
5
+
6
+ <div align="center">
7
+ <img src="https://github.com/SapienzaNLP/relik/blob/main/relik.png?raw=true" height="150">
8
+ <img src="https://github.com/SapienzaNLP/relik/blob/main/Sapienza_Babelscape.png?raw=true" height="50">
9
+ </div>
10
+
11
+ <div align="center">
12
+ <h1>Retrieve, Read and LinK: Fast and Accurate Entity Linking and Relation Extraction on an Academic Budget</h1>
13
+ </div>
14
+
15
+ <div style="display:flex; justify-content: center; align-items: center; flex-direction: row;">
16
+ <a href="https://2024.aclweb.org/"><img src="http://img.shields.io/badge/ACL-2024-4b44ce.svg"></a> &nbsp; &nbsp;
17
+ <a href="https://aclanthology.org/"><img src="http://img.shields.io/badge/paper-ACL--anthology-B31B1B.svg"></a> &nbsp; &nbsp;
18
+ <a href="https://arxiv.org/abs/placeholder"><img src="https://img.shields.io/badge/arXiv-placeholder-b31b1b.svg"></a>
19
+ </div>
20
+ <div style="display:flex; justify-content: center; align-items: center; flex-direction: row;">
21
+ <a href="https://huggingface.co/collections/sapienzanlp/relik-retrieve-read-and-link-665d9e4a5c3ecba98c1bef19"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Collection-FCD21D"></a> &nbsp; &nbsp;
22
+ <a href="https://github.com/SapienzaNLP/relik"><img src="https://img.shields.io/badge/GitHub-Repo-121013?logo=github&logoColor=white"></a> &nbsp; &nbsp;
23
+ <a href="https://github.com/SapienzaNLP/relik/releases"><img src="https://img.shields.io/github/v/release/SapienzaNLP/relik"></a>
24
+ </div>
25
+
26
+
27
+ A blazing fast and lightweight Information Extraction model for **Entity Linking** and **Relation Extraction**.
28
+
29
+ ## πŸ› οΈ Installation
30
+
31
+ Installation from PyPI
32
+
33
+ ```bash
34
+ pip install relik
35
+ ```
36
+
37
+ <details>
38
+ <summary>Other installation options</summary>
39
+
40
+ #### Install with optional dependencies
41
+
42
+ Install with all the optional dependencies.
43
+
44
+ ```bash
45
+ pip install relik[all]
46
+ ```
47
+
48
+ Install with optional dependencies for training and evaluation.
49
+
50
+ ```bash
51
+ pip install relik[train]
52
+ ```
53
+
54
+ Install with optional dependencies for [FAISS](https://github.com/facebookresearch/faiss)
55
+
56
+ FAISS PyPI package is only available for CPU. For GPU, install it from source or use the conda package.
57
+
58
+ For CPU:
59
+
60
+ ```bash
61
+ pip install relik[faiss]
62
+ ```
63
+
64
+ For GPU:
65
+
66
+ ```bash
67
+ conda create -n relik python=3.10
68
+ conda activate relik
69
+
70
+ # install pytorch
71
+ conda install -y pytorch=2.1.0 pytorch-cuda=12.1 -c pytorch -c nvidia
72
+
73
+ # GPU
74
+ conda install -y -c pytorch -c nvidia faiss-gpu=1.8.0
75
+ # or GPU with NVIDIA RAFT
76
+ conda install -y -c pytorch -c nvidia -c rapidsai -c conda-forge faiss-gpu-raft=1.8.0
77
+
78
+ pip install relik
79
+ ```
80
+
81
+ Install with optional dependencies for serving the models with
82
+ [FastAPI](https://fastapi.tiangolo.com/) and [Ray](https://docs.ray.io/en/latest/serve/quickstart.html).
83
+
84
+ ```bash
85
+ pip install relik[serve]
86
+ ```
87
+
88
+ #### Installation from source
89
+
90
+ ```bash
91
+ git clone https://github.com/SapienzaNLP/relik.git
92
+ cd relik
93
+ pip install -e .[all]
94
+ ```
95
+
96
+ </details>
97
+
98
+ ## πŸš€ Quick Start
99
+
100
+ [//]: # (Write a short description of the model and how to use it with the `from_pretrained` method.)
101
+
102
+ ReLiK is a lightweight and fast model for **Entity Linking** and **Relation Extraction**.
103
+ It is composed of two main components: a retriever and a reader.
104
+ The retriever is responsible for retrieving relevant documents from a large collection,
105
+ while the reader is responsible for extracting entities and relations from the retrieved documents.
106
+ ReLiK can be used with the `from_pretrained` method to load a pre-trained pipeline.
107
+
108
+ Here is an example of how to use ReLiK for **Entity Linking**:
109
+
110
+ ```python
111
+ from relik import Relik
112
+ from relik.inference.data.objects import RelikOutput
113
+
114
+ relik = Relik.from_pretrained("sapienzanlp/relik-entity-linking-large")
115
+ relik_out: RelikOutput = relik("Michael Jordan was one of the best players in the NBA.")
116
+ ```
117
+
118
+ RelikOutput(
119
+ text="Michael Jordan was one of the best players in the NBA.",
120
+ tokens=['Michael', 'Jordan', 'was', 'one', 'of', 'the', 'best', 'players', 'in', 'the', 'NBA', '.'],
121
+ id=0,
122
+ spans=[
123
+ Span(start=0, end=14, label="Michael Jordan", text="Michael Jordan"),
124
+ Span(start=50, end=53, label="National Basketball Association", text="NBA"),
125
+ ],
126
+ triples=[],
127
+ candidates=Candidates(
128
+ span=[
129
+ [
130
+ [
131
+ {"text": "Michael Jordan", "id": 4484083},
132
+ {"text": "National Basketball Association", "id": 5209815},
133
+ {"text": "Walter Jordan", "id": 2340190},
134
+ {"text": "Jordan", "id": 3486773},
135
+ {"text": "50 Greatest Players in NBA History", "id": 1742909},
136
+ ...
137
+ ]
138
+ ]
139
+ ]
140
+ ),
141
+ )
142
+
143
+ ## πŸ“Š Performance
144
+
145
+ We evaluate the performance of ReLiK on Entity Linking using [GERBIL](http://gerbil-qa.aksw.org/gerbil/). The following table shows the results (InKB Micro F1) of ReLiK Large and Base:
146
+
147
+ | Model | AIDA | MSNBC | Der | K50 | R128 | R500 | O15 | O16 | Tot | OOD | AIT (m:s) |
148
+ |------------------------------------------|------|-------|------|------|------|------|------|------|------|------|------------|
149
+ | GENRE | 83.7 | 73.7 | 54.1 | 60.7 | 46.7 | 40.3 | 56.1 | 50.0 | 58.2 | 54.5 | 38:00 |
150
+ | EntQA | 85.8 | 72.1 | 52.9 | 64.5 | **54.1** | 41.9 | 61.1 | 51.3 | 60.5 | 56.4 | 20:00 |
151
+ | ➑️[ReLiK<sub>Base<sub>](https://huggingface.co/sapienzanlp/relik-entity-linking-base) | 85.3 | 72.3 | 55.6 | 68.0 | 48.1 | 41.6 | 62.5 | 52.3 | 60.7 | 57.2 | 00:29 |
152
+ | [ReLiK<sub>Large<sub>](https://huggingface.co/sapienzanlp/relik-entity-linking-large) | **86.4** | **75.0** | **56.3** | **72.8** | 51.7 | **43.0** | **65.1** | **57.2** | **63.4** | **60.2** | 01:46 |
153
+
154
+ Comparison systems' evaluation (InKB Micro F1) on the *in-domain* AIDA test set and *out-of-domain* MSNBC (MSN), Derczynski (Der), KORE50 (K50), N3-Reuters-128 (R128),
155
+ N3-RSS-500 (R500), OKE-15 (O15), and OKE-16 (O16) test sets. **Bold** indicates the best model.
156
+ GENRE uses mention dictionaries.
157
+ The AIT column shows the time in minutes and seconds (m:s) that the systems need to process the whole AIDA test set using an NVIDIA RTX 4090,
158
+ except for EntQA which does not fit in 24GB of RAM and for which an A100 is used.
159
+
160
+ ## πŸ€– Models
161
+
162
+ Models can be found on [πŸ€— Hugging Face](https://huggingface.co/collections/sapienzanlp/relik-retrieve-read-and-link-665d9e4a5c3ecba98c1bef19).
163
+
164
+ ## πŸ’½ Cite this work
165
+
166
+ If you use any part of this work, please consider citing the paper as follows:
167
+
168
+ ```bibtex
169
+ @inproceedings{orlando-etal-2024-relik,
170
+ title = "Retrieve, Read and LinK: Fast and Accurate Entity Linking and Relation Extraction on an Academic Budget",
171
+ author = "Orlando, Riccardo and Huguet Cabot, Pere-Llu{\'\i}s and Barba, Edoardo and Navigli, Roberto",
172
+ booktitle = "Findings of the Association for Computational Linguistics: ACL 2024",
173
+ month = aug,
174
+ year = "2024",
175
+ address = "Bangkok, Thailand",
176
+ publisher = "Association for Computational Linguistics",
177
+ }
178
+ ```