Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Turkish Question Answering model based on mt0-large
|
2 |
+
In this model, I fine-tune *mT0-large* model with the following Turkish QA datasets
|
3 |
+
* https://huggingface.co/bigscience/mt0-large
|
4 |
+
* https://github.com/okanvk/Turkish-Reading-Comprehension-Question-Answering-Dataset
|
5 |
+
|
6 |
+
The model is tuned within parameter-efficient fine-tuning, which is PEFT LORA. So we need to install peft modules. Please check
|
7 |
+
* https://github.com/huggingface/peft
|
8 |
+
|
9 |
+
|
10 |
+
The training set size is around 11K QAs.
|
11 |
+
|
12 |
+
|
13 |
+
Example usage for single inference is as follows:
|
14 |
+
```
|
15 |
+
from peft import PeftModel, PeftConfig
|
16 |
+
peft_model_path="savasy/mt0-large-Turkish-qa"
|
17 |
+
|
18 |
+
config = PeftConfig.from_pretrained(peft_model_path)
|
19 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(
|
20 |
+
config.base_model_name_or_path)
|
21 |
+
# Load the Lora model
|
22 |
+
inference_model = PeftModel.from_pretrained(model, peft_model_path)
|
23 |
+
|
24 |
+
inference_model.eval()
|
25 |
+
|
26 |
+
|
27 |
+
import numpy as np
|
28 |
+
inference_model.to("cuda")
|
29 |
+
test_input = '''Mustafa adını babası Ali Rıza Efendi kendi dedesinin adı olduğundan dolayı vermiştir. Çünkü Ali Rıza Efendi'nin babasının adı olan
|
30 |
+
Ahmed adı ağabeylerinden birisine verilmişti. Mustafa'ya neden Kemal isminin verildiğine yönelik ise çeşitli iddialar vardır.
|
31 |
+
Afet İnan, bu ismi ona matematik öğretmeni Üsküplü Mustafa Efendi'nin Kemal adının anlamında olduğu gibi onun "mükemmel ve olgun"
|
32 |
+
olduğunu göstermek için verdiğini söylemiştir. (source: wikipedia) .
|
33 |
+
Mustafa'nın dedesinin ismi nedir ?
|
34 |
+
'''
|
35 |
+
with torch.no_grad():
|
36 |
+
inputs = tokenizer(test_input, return_tensors="pt", padding=True).to("cuda")
|
37 |
+
generated_ids = inference_model.generate(**inputs)
|
38 |
+
outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
39 |
+
outputs```
|
40 |
+
-> [Ahmed]
|
41 |
+
|
42 |
+
The usage for batch mode is as follows:
|
43 |
+
```
|
44 |
+
from peft import PeftModel, PeftConfig
|
45 |
+
peft_model_path="savasy/mt0-large-Turkish-qa"
|
46 |
+
|
47 |
+
config = PeftConfig.from_pretrained(peft_model_path)
|
48 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(
|
49 |
+
config.base_model_name_or_path)
|
50 |
+
# Load the Lora model
|
51 |
+
inference_model = PeftModel.from_pretrained(model, peft_model_path)
|
52 |
+
|
53 |
+
inference_model.eval()
|
54 |
+
inference_model.to("cuda")
|
55 |
+
test_inputs = ["","",""] # a list of texts. A text must have Content followed by a Question
|
56 |
+
|
57 |
+
preds=[]
|
58 |
+
data_loader= DataLoader(test_inputs,batch_size=8)
|
59 |
+
|
60 |
+
from tqdm import tqdm
|
61 |
+
|
62 |
+
with torch.no_grad():
|
63 |
+
for batch in tqdm(data_loader):
|
64 |
+
inputs = tokenizer(batch, return_tensors="pt", padding=True).to("cuda")
|
65 |
+
generated_ids = model.generate(**inputs)
|
66 |
+
outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
67 |
+
preds+=outputs
|
68 |
+
```
|
69 |
+
# compare preds with your expected ground-truth results
|
70 |
+
|