Include usage guide
Browse files
README.md
CHANGED
@@ -7,4 +7,59 @@ metrics:
|
|
7 |
base_model:
|
8 |
- facebook/mbart-large-50
|
9 |
library_name: transformers
|
10 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
base_model:
|
8 |
- facebook/mbart-large-50
|
9 |
library_name: transformers
|
10 |
+
---
|
11 |
+
## How to use the model
|
12 |
+
|
13 |
+
Import model and tokenizer using from stranformer libray
|
14 |
+
```py
|
15 |
+
# Load model directly
|
16 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
17 |
+
|
18 |
+
tokenizer = AutoTokenizer.from_pretrained("tykea/mBart-large-50-KQA")
|
19 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("tykea/mBart-large-50-KQA")
|
20 |
+
```
|
21 |
+
Define function to take question and pass to the model
|
22 |
+
```py
|
23 |
+
import torch
|
24 |
+
|
25 |
+
#ask function for easier asking
|
26 |
+
def ask(custom_question):
|
27 |
+
# Tokenize the input
|
28 |
+
inputs = tokenizer(
|
29 |
+
f"qestion: {custom_question}",
|
30 |
+
return_tensors="pt",
|
31 |
+
truncation=True,
|
32 |
+
max_length=512,
|
33 |
+
padding="max_length"
|
34 |
+
)
|
35 |
+
|
36 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
37 |
+
inputs = {key: value.to(device) for key, value in inputs.items()}
|
38 |
+
|
39 |
+
model.eval()
|
40 |
+
with torch.no_grad():
|
41 |
+
outputs = model.generate(
|
42 |
+
input_ids=inputs["input_ids"],
|
43 |
+
max_length=50,
|
44 |
+
num_beams=4,
|
45 |
+
repetition_penalty=2.0,
|
46 |
+
early_stopping=True,
|
47 |
+
do_sample=True,
|
48 |
+
top_k=50,
|
49 |
+
top_p=0.95,
|
50 |
+
temperature=0.7,
|
51 |
+
)
|
52 |
+
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
53 |
+
print(f"Question: {custom_question}")
|
54 |
+
print(f"Answer: {answer}")
|
55 |
+
|
56 |
+
```
|
57 |
+
|
58 |
+
Then call the function #ask function
|
59 |
+
```py
|
60 |
+
question = "ααΎααααα
ααααααααΆ"
|
61 |
+
ask(question)
|
62 |
+
#output
|
63 |
+
#Question: ααΎααααα
ααααααααΆ
|
64 |
+
#Answer: ααααα
ααααααα’ααααααα
|
65 |
+
```
|