daviddrzik commited on
Commit
d0cbcda
1 Parent(s): d8f35dd

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +126 -3
README.md CHANGED
@@ -1,3 +1,126 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - sk
5
+ pipeline_tag: question-answering
6
+ library_name: transformers
7
+ metrics:
8
+ - f1
9
+ - levenshtein
10
+ - exact match
11
+ base_model: daviddrzik/SK_BPE_BLM
12
+ tags:
13
+ - question-answering
14
+ - sk-quad
15
+ datasets:
16
+ - TUKE-DeutscheTelekom/skquad
17
+ ---
18
+
19
+ # Fine-Tuned Question Answering Model - SK_BPE_BLM (SK-QuAD Dataset)
20
+
21
+ ## Model Overview
22
+ This model is a fine-tuned version of the [SK_BPE_BLM model](https://huggingface.co/daviddrzik/SK_BPE_BLM) for extractive question answering tasks. The fine-tuning was conducted using the [SK-QuAD dataset]( https://nlp.kemt.fei.tuke.sk/language/skquad), which is the first manually annotated dataset for Slovak, containing over 91,000 questions and answers. This dataset includes both clearly answerable questions and unanswerable ones, as well as plausible but probably incorrect answers.
23
+
24
+ ## Dataset Details
25
+ For the purposes of fine-tuning, we focused solely on the records with clearly answerable questions. The original dataset was divided into training and test sets; however, we combined these into a single dataset for our research. Some records had extensive contexts that, when combined with the question, exceeded the context window size of our model. We therefore excluded all records where the combined length of the context and question exceeded 1,300 characters, which corresponds to approximately 256 tokens. This reduction resulted in a final dataset size of **54,319** question-answer pairs.
26
+ To ensure robust evaluation, we applied stratified 10-fold cross-validation across the dataset. This approach allowed us to rigorously assess the model's performance and generalize well across different subsets of the data.
27
+
28
+ ## Fine-Tuning Hyperparameters
29
+ The following hyperparameters were used during the fine-tuning process:
30
+
31
+ - **Learning Rate:** 5e-05
32
+ - **Training Batch Size:** 64 sequences
33
+ - **Evaluation Batch Size:** 64 sequences
34
+ - **Seed:** 42
35
+ - **Optimizer:** Adam (default)
36
+ - **Number of Epochs:** 5
37
+
38
+ ## Evaluation Metrics
39
+
40
+ The model performance was assessed using both token-level and text-level metrics:
41
+
42
+ - **Token-Level Metrics:**
43
+ - **Precision**
44
+ - **Recall**
45
+ - **F1-Score:** Measures how accurately the model identified the correct answer tokens within the context.
46
+
47
+ - **Text-Level Metrics:**
48
+ - **Levenshtein Distance:** Evaluates the similarity between the predicted and correct answers.
49
+ - **Exact Match:** Measures the percentage of answers where the predicted answer exactly matched the correct one.
50
+
51
+ ## Model Performance
52
+
53
+ The model achieved the following median performance metrics:
54
+
55
+ - **F1-Score:** 0.6563
56
+ - **Levenshtein Distance:** 0.6134
57
+ - **Exact Match:** 0.3396
58
+
59
+ ## Model Usage
60
+
61
+ This model is suitable for extractive question answering tasks in Slovak text, particularly for applications that require the identification of precise answers from a given context.
62
+
63
+ ### Example Usage
64
+
65
+ Below is an example of how to use the fine-tuned `SK_BPE_BLM-qa ` model in a Python script:
66
+
67
+ ```python
68
+ import torch
69
+ from torch.nn.functional import softmax
70
+ from transformers import RobertaForQuestionAnswering, RobertaTokenizerFast
71
+ import json
72
+
73
+ class QuestionAnsweringModel:
74
+ def __init__(self, model, tokenizer):
75
+ self.model = RobertaForQuestionAnswering.from_pretrained(model)
76
+ self.tokenizer = RobertaTokenizerFast.from_pretrained(tokenizer, max_len=256)
77
+
78
+ def predict(self, context, question):
79
+ inputs = self.tokenizer(context, question, truncation=True, padding="max_length", return_tensors='pt')
80
+ input_ids = inputs["input_ids"].tolist()[0]
81
+
82
+ outputs = self.model(**inputs)
83
+ start_logits = outputs.start_logits
84
+ end_logits = outputs.end_logits
85
+
86
+ start_probs = softmax(start_logits, dim=1)
87
+ end_probs = softmax(end_logits, dim=1)
88
+
89
+ answer_start = torch.argmax(start_probs)
90
+ answer_end = torch.argmax(end_probs) + 1
91
+
92
+ answer = self.tokenizer.decode(input_ids[answer_start:answer_end], skip_special_tokens=True)
93
+
94
+ start_prob = start_probs[0, answer_start].item()
95
+ end_prob = end_probs[0, answer_end - 1].item()
96
+
97
+ return answer, start_prob, end_prob
98
+
99
+ # Instantiate the QA model with the specified tokenizer and model
100
+ qa_model = QuestionAnsweringModel(tokenizer="daviddrzik/SK_BPE_BLM", model="daviddrzik/SK_BPE_BLM-qa")
101
+
102
+ context = "Albert Einstein, narodený v roku 1879, je jedným z najvplyvnejších fyzikov všetkých čias. Vyvinul teóriu relativity, ktorá zmenila naše chápanie priestoru, času a gravitácie. Jeho slávna rovnica E = mc², ktorá vyjadruje vzťah medzi energiou a hmotou, je považovaná za jednu z najvýznamnejších rovníc vo fyzike. Einstein získal Nobelovu cenu za fyziku v roku 1921 za jeho prácu na fotoelektrickom jave, ktorý bol kľúčový pre rozvoj kvantovej mechaniky."
103
+ question = "V ktorom roku získal Albert Einstein Nobelovu cenu za fyziku?"
104
+
105
+ print("\nContext: " + context + "\n")
106
+ print("Question: " + question + "\n")
107
+
108
+ # Predict the answer
109
+ answer = qa_model.predict(context, question)
110
+ print(f"Predicted answer: {answer}")
111
+ ```
112
+
113
+ Example Output
114
+ Here is the output when running the above example:
115
+ ```yaml
116
+ Context: Albert Einstein, narodený v roku 1879, je jedným z najvplyvnejších fyzikov všetkých čias.
117
+ Vyvinul teóriu relativity, ktorá zmenila naše chápanie priestoru, času a gravitácie.
118
+ Jeho slávna rovnica E = mc², ktorá vyjadruje vzťah medzi energiou a hmotou,
119
+ je považovaná za jednu z najvýznamnejších rovníc vo fyzike.
120
+ Einstein získal Nobelovu cenu za fyziku v roku 1921 za jeho prácu na fotoelektrickom jave,
121
+ ktorý bol kľúčový pre rozvoj kvantovej mechaniky.
122
+
123
+ Question: V ktorom roku získal Albert Einstein Nobelovu cenu za fyziku?
124
+
125
+ Predicted answer: (' v roku 1921', 0.7212189435958862, 0.9873688817024231)
126
+ ```