riccorl commited on
Commit
9338666
β€’
1 Parent(s): a351875

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +185 -0
README.md ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ **This repository contains the weights for the ReLiK Reader component.**
30
+
31
+ ## πŸ› οΈ Installation
32
+
33
+ Installation from PyPI
34
+
35
+ ```bash
36
+ pip install relik
37
+ ```
38
+
39
+ <details>
40
+ <summary>Other installation options</summary>
41
+
42
+ #### Install with optional dependencies
43
+
44
+ Install with all the optional dependencies.
45
+
46
+ ```bash
47
+ pip install relik[all]
48
+ ```
49
+
50
+ Install with optional dependencies for training and evaluation.
51
+
52
+ ```bash
53
+ pip install relik[train]
54
+ ```
55
+
56
+ Install with optional dependencies for [FAISS](https://github.com/facebookresearch/faiss)
57
+
58
+ FAISS PyPI package is only available for CPU. For GPU, install it from source or use the conda package.
59
+
60
+ For CPU:
61
+
62
+ ```bash
63
+ pip install relik[faiss]
64
+ ```
65
+
66
+ For GPU:
67
+
68
+ ```bash
69
+ conda create -n relik python=3.10
70
+ conda activate relik
71
+
72
+ # install pytorch
73
+ conda install -y pytorch=2.1.0 pytorch-cuda=12.1 -c pytorch -c nvidia
74
+
75
+ # GPU
76
+ conda install -y -c pytorch -c nvidia faiss-gpu=1.8.0
77
+ # or GPU with NVIDIA RAFT
78
+ conda install -y -c pytorch -c nvidia -c rapidsai -c conda-forge faiss-gpu-raft=1.8.0
79
+
80
+ pip install relik
81
+ ```
82
+
83
+ Install with optional dependencies for serving the models with
84
+ [FastAPI](https://fastapi.tiangolo.com/) and [Ray](https://docs.ray.io/en/latest/serve/quickstart.html).
85
+
86
+ ```bash
87
+ pip install relik[serve]
88
+ ```
89
+
90
+ #### Installation from source
91
+
92
+ ```bash
93
+ git clone https://github.com/SapienzaNLP/relik.git
94
+ cd relik
95
+ pip install -e .[all]
96
+ ```
97
+
98
+ </details>
99
+
100
+ ## πŸš€ Quick Start
101
+
102
+ [//]: # (Write a short description of the model and how to use it with the `from_pretrained` method.)
103
+
104
+ ReLiK is a lightweight and fast model for **Entity Linking** and **Relation Extraction**.
105
+ It is composed of two main components: a retriever and a reader.
106
+ The retriever is responsible for retrieving relevant documents from a large collection,
107
+ while the reader is responsible for extracting entities and relations from the retrieved documents.
108
+ ReLiK can be used with the `from_pretrained` method to load a pre-trained pipeline.
109
+
110
+ Here is an example of how to use ReLiK for **Relation Extraction**:
111
+
112
+ ```python
113
+ from relik import Relik
114
+ from relik.inference.data.objects import RelikOutput
115
+
116
+ relik = Relik.from_pretrained("sapienzanlp/relik-relation-extraction-nyt-large")
117
+ relik_out: RelikOutput = relik("Michael Jordan was one of the best players in the NBA.")
118
+ ```
119
+
120
+
121
+ RelikOutput(
122
+ text='Michael Jordan was one of the best players in the NBA.',
123
+ tokens=Michael Jordan was one of the best players in the NBA.,
124
+ id=0,
125
+ spans=[
126
+ Span(start=0, end=14, label='--NME--', text='Michael Jordan'),
127
+ Span(start=50, end=53, label='--NME--', text='NBA')
128
+ ],
129
+ triplets=[
130
+ Triplets(
131
+ subject=Span(start=0, end=14, label='--NME--', text='Michael Jordan'),
132
+ label='company',
133
+ object=Span(start=50, end=53, label='--NME--', text='NBA'),
134
+ confidence=1.0
135
+ )
136
+ ],
137
+ candidates=Candidates(
138
+ span=[],
139
+ triplet=[
140
+ [
141
+ [
142
+ {"text": "company", "id": 4, "metadata": {"definition": "company of this person"}},
143
+ {"text": "nationality", "id": 10, "metadata": {"definition": "nationality of this person or entity"}},
144
+ {"text": "child", "id": 17, "metadata": {"definition": "child of this person"}},
145
+ {"text": "founded by", "id": 0, "metadata": {"definition": "founder or co-founder of this organization, religion or place"}},
146
+ {"text": "residence", "id": 18, "metadata": {"definition": "place where this person has lived"}},
147
+ ...
148
+ ]
149
+ ]
150
+ ]
151
+ ),
152
+ )
153
+
154
+
155
+ ## πŸ“Š Performance
156
+
157
+ The following table shows the results (Micro F1) of ReLiK Large on the NYT dataset:
158
+
159
+ | Model | NYT | NYT (Pretr) | AIT (m:s) |
160
+ |------------------------------------------|------|-------|------------|
161
+ | REBEL | 93.1 | 93.4 | 01:45 |
162
+ | UiE | 93.5 | -- | -- |
163
+ | USM | 94.0 | 94.1 | -- |
164
+ | ➑️ [ReLiK<sub>Large<sub>](https://huggingface.co/sapienzanlp/relik-relation-extraction-nyt-large) | **95.0** | **94.9** | 00:30 |
165
+
166
+
167
+ ## πŸ€– Models
168
+
169
+ Models can be found on [πŸ€— Hugging Face](https://huggingface.co/collections/sapienzanlp/relik-retrieve-read-and-link-665d9e4a5c3ecba98c1bef19).
170
+
171
+ ## πŸ’½ Cite this work
172
+
173
+ If you use any part of this work, please consider citing the paper as follows:
174
+
175
+ ```bibtex
176
+ @inproceedings{orlando-etal-2024-relik,
177
+ title = "Retrieve, Read and LinK: Fast and Accurate Entity Linking and Relation Extraction on an Academic Budget",
178
+ author = "Orlando, Riccardo and Huguet Cabot, Pere-Llu{\'\i}s and Barba, Edoardo and Navigli, Roberto",
179
+ booktitle = "Findings of the Association for Computational Linguistics: ACL 2024",
180
+ month = aug,
181
+ year = "2024",
182
+ address = "Bangkok, Thailand",
183
+ publisher = "Association for Computational Linguistics",
184
+ }
185
+ ```