Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,58 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Task-aware Retrieval with Instructions
|
2 |
+
|
3 |
+
Official repository: [github.com/facebookresearch/tart](https://github.com/facebookresearch/tart)
|
4 |
+
|
5 |
+
### Model descriptions
|
6 |
+
|
7 |
+
`facebook/tart-full-t0-3b` is a multi-task cross-encoder model trained via instruction-tuning on approximately 40 retrieval tasks, which is initialized with [bigscience/T0_3B](https://huggingface.co/bigscience/T0_3B).
|
8 |
+
|
9 |
+
TART-full is a 1.5 billion cross-necoder and it can rerank top documents given a query and natural language instruction (e.g., *find a Wikipedia paragraph that answers this question.*).
|
10 |
+
Experimental results on widely-used [BEIR](https://github.com/beir-cellar/beir), [LOTTE](https://huggingface.co/datasets/colbertv2/lotte), and our new evaluation, [X^2-Retrieval](https://github.com/facebookresearch/tart/cross_task_cross_eval) show that TART-full outperforms previous state-of-the-art methods by levaraging natural language instructions.
|
11 |
+
|
12 |
+
More details about modeling and training are in our paper: [Task-aware Retrieval with Instructions](https://arxiv.org/abs/2211.09260).
|
13 |
+
|
14 |
+
### Installation
|
15 |
+
```sh
|
16 |
+
git clone https://github.com/facebookresearch/tart
|
17 |
+
pip install -r requirements.txt
|
18 |
+
cd tart/TART
|
19 |
+
```
|
20 |
+
|
21 |
+
### How to use?
|
22 |
+
|
23 |
+
TART-full can be loaded through our customized EncT5 model.
|
24 |
+
```python
|
25 |
+
from src.modeling_enc_t5 import EncT5ForSequenceClassification
|
26 |
+
from src.tokenization_enc_t5 import EncT5Tokenizer
|
27 |
+
import torch
|
28 |
+
import torch.nn.functional as F
|
29 |
+
import numpy as np
|
30 |
+
|
31 |
+
# load TART full and tokenizer
|
32 |
+
model = EncT5ForSequenceClassification.from_pretrained("facebook/tart-full-t0-3b")
|
33 |
+
tokenizer = EncT5Tokenizer.from_pretrained("facebook/tart-full-t0-3b")
|
34 |
+
model.eval()
|
35 |
+
|
36 |
+
q = "What is the population of Tokyo?"
|
37 |
+
in_answer = "retrieve a passage that answers this question from Wikipedia"
|
38 |
+
|
39 |
+
p_1 = "The population of Japan's capital, Tokyo, dropped by about 48,600 people to just under 14 million at the start of 2022, the first decline since 1996, the metropolitan government reported Monday."
|
40 |
+
p_2 = "Tokyo, officially the Tokyo Metropolis (東京都, Tōkyō-to), is the capital and largest city of Japan."
|
41 |
+
|
42 |
+
# 1. TART-full can identify more relevant paragraph.
|
43 |
+
features = tokenizer(['{0} [SEP] {1}'.format(in_answer, q), '{0} [SEP] {1}'.format(in_answer, q)], [p_1, p_2], padding=True, truncation=True, return_tensors="pt")
|
44 |
+
with torch.no_grad():
|
45 |
+
scores = model(**features).logits
|
46 |
+
normalized_scores = [float(score[1]) for score in F.softmax(scores, dim=1)]
|
47 |
+
|
48 |
+
print([p_1, p_2][np.argmax(normalized_scores)]) # "The population of Japan's capital, Tokyo, dropped by about 48,600 people to just under 14 million ... "
|
49 |
+
|
50 |
+
# 2. TART-full can identify the document that is more relevant AND follows instructions.
|
51 |
+
q_1 = "How many people live in Tokyo?"
|
52 |
+
features = tokenizer(['{0} [SEP] {1}'.format(in_answer, q), '{0} [SEP] {1}'.format(in_answer, q)], [p_1, q_1], padding=True, truncation=True, return_tensors="pt")
|
53 |
+
with torch.no_grad():
|
54 |
+
scores = model(**features).logits
|
55 |
+
normalized_scores = [float(score[1]) for score in F.softmax(scores, dim=1)]
|
56 |
+
|
57 |
+
print([p_1, q_1][np.argmax(normalized_scores)]) # "How many people live in Tokyo?"
|
58 |
+
```
|