add usage example
Browse files
README.md
CHANGED
@@ -15,11 +15,34 @@ widget:
|
|
15 |
|
16 |
Repository: [https://github.com/Lurunchik/NF-CATS](https://github.com/Lurunchik/NF-CATS)
|
17 |
|
18 |
-
|
19 |
Model trained with NFQA dataset. Base model is [roberta-base-squad2](https://huggingface.co/deepset/roberta-base-squad2), a RoBERTa-based model for the task of Question Answering, fine-tuned using the SQuAD2.0 dataset.
|
20 |
|
21 |
Uses `NOT-A-QUESTION`, `FACTOID`, `DEBATE`, `EVIDENCE-BASED`, `INSTRUCTION`, `REASON`, `EXPERIENCE`, `COMPARISON` labels.
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
## Citation
|
25 |
|
|
|
15 |
|
16 |
Repository: [https://github.com/Lurunchik/NF-CATS](https://github.com/Lurunchik/NF-CATS)
|
17 |
|
|
|
18 |
Model trained with NFQA dataset. Base model is [roberta-base-squad2](https://huggingface.co/deepset/roberta-base-squad2), a RoBERTa-based model for the task of Question Answering, fine-tuned using the SQuAD2.0 dataset.
|
19 |
|
20 |
Uses `NOT-A-QUESTION`, `FACTOID`, `DEBATE`, `EVIDENCE-BASED`, `INSTRUCTION`, `REASON`, `EXPERIENCE`, `COMPARISON` labels.
|
21 |
|
22 |
+
## How to use NFQA cat with HuggingFace
|
23 |
+
|
24 |
+
##### Load NFQA cat and its tokenizer:
|
25 |
+
```python
|
26 |
+
from transformers import AutoTokenizer
|
27 |
+
|
28 |
+
from nfqa_model import RobertaNFQAClassification
|
29 |
+
|
30 |
+
nfqa_model = RobertaNFQAClassification.from_pretrained("Lurunchik/nf-cats")
|
31 |
+
nfqa_tokenizer = AutoTokenizer.from_pretrained("deepset/roberta-base-squad2")
|
32 |
+
```
|
33 |
+
|
34 |
+
##### Make prediction using helper function
|
35 |
+
```python
|
36 |
+
|
37 |
+
def get_nfqa_category_prediction(text):
|
38 |
+
output = nfqa_model(**nfqa_tokenizer(text, return_tensors="pt"))
|
39 |
+
index = output.logits.argmax()
|
40 |
+
return nfqa_model.config.id2label[int(index)]
|
41 |
+
|
42 |
+
get_nfqa_category_prediction('how to assign category?')
|
43 |
+
# result
|
44 |
+
#'INSTRUCTION'
|
45 |
+
```
|
46 |
|
47 |
## Citation
|
48 |
|