savasy commited on
Commit
6741362
1 Parent(s): f8fe556

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +33 -16
README.md CHANGED
@@ -1,37 +1,48 @@
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)
@@ -40,26 +51,32 @@ outputs
40
  -> [Ahmed]
41
  ```
42
 
 
43
 
44
  The usage for batch mode is as follows:
45
 
46
  ```
47
  from peft import PeftModel, PeftConfig
 
48
  peft_model_path="savasy/mt0-large-Turkish-qa"
49
 
50
  config = PeftConfig.from_pretrained(peft_model_path)
51
  model = AutoModelForSeq2SeqLM.from_pretrained(
52
  config.base_model_name_or_path)
53
- # Load the Lora model
54
- inference_model = PeftModel.from_pretrained(model, peft_model_path)
55
 
 
 
 
 
 
56
  inference_model.eval()
 
57
  inference_model.to("cuda")
58
- test_inputs = ["","",""] # a list of texts. A text must have Content followed by a Question
59
 
60
- preds=[]
61
- data_loader= DataLoader(test_inputs,batch_size=8)
62
 
 
 
63
  from tqdm import tqdm
64
 
65
  with torch.no_grad():
@@ -69,5 +86,5 @@ with torch.no_grad():
69
  outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
70
  preds+=outputs
71
  ```
72
- At the end, you can compare *preds* with your expected ground-truth results
73
 
 
1
  # Turkish Question Answering model based on mt0-large
2
+ In this model, I fine-tuned *mT0-large* model with the following Turkish QA datasets where the training set size is around 11K QAs.
3
+
4
  * https://huggingface.co/bigscience/mt0-large
5
  * https://github.com/okanvk/Turkish-Reading-Comprehension-Question-Answering-Dataset
6
 
7
+ The model is tuned within one of parameter-efficient fine-tuning techniques, which is PEFT LORA. So we need to install peft modules. Please check
8
  * https://github.com/huggingface/peft
9
 
10
 
11
+ # FOR INFERENCE
12
+
13
+ We first install the requirements :
14
+ ```
15
+ !pip install peft transformers # in jupyter notebook
16
+
17
+ ```
18
 
19
+ ## SINGLE INFERENCE
20
 
 
21
  ```
22
  from peft import PeftModel, PeftConfig
23
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
24
  peft_model_path="savasy/mt0-large-Turkish-qa"
25
 
26
  config = PeftConfig.from_pretrained(peft_model_path)
27
  model = AutoModelForSeq2SeqLM.from_pretrained(
28
  config.base_model_name_or_path)
 
 
29
 
30
+ #tokenizer
31
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
32
 
33
+ # Wrap the model with the LORA
34
+ inference_model = PeftModel.from_pretrained(model, peft_model_path)
35
+ inference_model.eval()
36
 
 
37
  inference_model.to("cuda")
38
+ test_input = '''
39
+ 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
40
  Ahmed adı ağabeylerinden birisine verilmişti. Mustafa'ya neden Kemal isminin verildiğine yönelik ise çeşitli iddialar vardır.
41
  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"
42
  olduğunu göstermek için verdiğini söylemiştir. (source: wikipedia) .
43
+ Mustafa'nın dedesinin ismi nedir ?
44
  '''
45
+ import torch
46
  with torch.no_grad():
47
  inputs = tokenizer(test_input, return_tensors="pt", padding=True).to("cuda")
48
  generated_ids = inference_model.generate(**inputs)
 
51
  -> [Ahmed]
52
  ```
53
 
54
+ ## BATCH INFERENCE
55
 
56
  The usage for batch mode is as follows:
57
 
58
  ```
59
  from peft import PeftModel, PeftConfig
60
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
61
  peft_model_path="savasy/mt0-large-Turkish-qa"
62
 
63
  config = PeftConfig.from_pretrained(peft_model_path)
64
  model = AutoModelForSeq2SeqLM.from_pretrained(
65
  config.base_model_name_or_path)
 
 
66
 
67
+ #tokenizer
68
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
69
+
70
+ # Wrap the model with the LORA
71
+ inference_model = PeftModel.from_pretrained(model, peft_model_path)
72
  inference_model.eval()
73
+
74
  inference_model.to("cuda")
 
75
 
76
+ test_inputs = ["","","",""] # a list of texts. A text must have Content followed by a Question
 
77
 
78
+ preds=[] # for predictions
79
+ data_loader= DataLoader(test_inputs,batch_size=8)
80
  from tqdm import tqdm
81
 
82
  with torch.no_grad():
 
86
  outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
87
  preds+=outputs
88
  ```
89
+ In the end, you can compare *preds* (predictions) with your expected ground-truth results. You can use many metrics for this such as BLEU, ROUGE, Exact Match, Partial Match
90