Update README.md
Browse files
README.md
CHANGED
@@ -16,6 +16,33 @@ pipeline_tag: text-classification
|
|
16 |
|
17 |
The model was trained as cross-encoder classification model with the objective to re-rank the results in a QA pipline.
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
## Data
|
20 |
|
21 |
The data from SQuAD 2.0 was sentence-split. The question + the sentence containing the answer was a positive example.
|
@@ -23,6 +50,8 @@ The question + the remaining sentence from the same Wikipedia passege were treat
|
|
23 |
|
24 |
The table balow reports the classification results on the validation set.
|
25 |
|
|
|
|
|
26 |
|
27 |
| | accuracy | F1 |
|
28 |
|----------------|----------|----------|
|
|
|
16 |
|
17 |
The model was trained as cross-encoder classification model with the objective to re-rank the results in a QA pipline.
|
18 |
|
19 |
+
## How to use
|
20 |
+
|
21 |
+
```python
|
22 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
23 |
+
|
24 |
+
|
25 |
+
model = AutoModelForSequenceClassification.from_pretrained("apohllo/albert-xxl-squad-sentences", num_labels=2)
|
26 |
+
tokenizer = AutoTokenizer.from_pretrained("apohllo/albert-xxl-squad-sentences")
|
27 |
+
|
28 |
+
from transformers import pipeline
|
29 |
+
|
30 |
+
# Add device=0 if you want to use GPU!
|
31 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer, batch_size=16) #, device=0)
|
32 |
+
|
33 |
+
sentences = [...] # some sentences to be re-ranked, wrt to the question
|
34 |
+
question = "..." # a question to be asked against the sentences
|
35 |
+
|
36 |
+
samples = [{"text": s, "text_pair": question} for s in sentences]
|
37 |
+
results = classifier(samples)
|
38 |
+
|
39 |
+
results = [(idx, r["score"]) if r["label"] == 'LABEL_1' else (idx, 1 - r["score"])
|
40 |
+
for idx, r in enumerate(results)]
|
41 |
+
|
42 |
+
top_k = 5
|
43 |
+
keys_values = sorted(results, key=lambda e: -e[1])[:top_k]
|
44 |
+
```
|
45 |
+
|
46 |
## Data
|
47 |
|
48 |
The data from SQuAD 2.0 was sentence-split. The question + the sentence containing the answer was a positive example.
|
|
|
50 |
|
51 |
The table balow reports the classification results on the validation set.
|
52 |
|
53 |
+
# Results
|
54 |
+
|
55 |
|
56 |
| | accuracy | F1 |
|
57 |
|----------------|----------|----------|
|