bakrianoo commited on
Commit
28364ab
verified
1 Parent(s): dee4edc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +168 -136
README.md CHANGED
@@ -1,199 +1,231 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 馃 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
 
90
- [More Information Needed]
 
 
 
 
 
 
91
 
 
92
 
93
- #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
 
 
 
 
102
 
103
- ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
 
 
106
 
107
- ### Testing Data, Factors & Metrics
 
 
 
108
 
109
- #### Testing Data
 
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
 
112
 
113
- [More Information Needed]
 
 
 
114
 
115
- #### Factors
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
 
 
118
 
119
- [More Information Needed]
120
 
121
- #### Metrics
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
 
126
 
127
- ### Results
 
128
 
129
- [More Information Needed]
 
 
130
 
131
- #### Summary
 
 
 
132
 
 
 
 
 
133
 
 
134
 
135
- ## Model Examination [optional]
 
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
 
138
 
139
- [More Information Needed]
 
 
 
 
140
 
141
- ## Environmental Impact
 
 
 
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
 
 
 
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
 
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
 
153
- ## Technical Specifications [optional]
 
154
 
155
- ### Model Architecture and Objective
 
 
 
 
156
 
157
- [More Information Needed]
 
 
 
158
 
159
- ### Compute Infrastructure
 
 
 
160
 
161
- [More Information Needed]
162
 
163
- #### Hardware
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
- [More Information Needed]
166
 
167
- #### Software
168
 
169
- [More Information Needed]
170
 
171
- ## Citation [optional]
 
 
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
 
175
- **BibTeX:**
176
 
177
- [More Information Needed]
178
 
179
- **APA:**
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
 
 
 
 
 
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
190
 
191
- [More Information Needed]
192
 
193
- ## Model Card Authors [optional]
194
 
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
198
 
199
- [More Information Needed]
 
1
  ---
2
  library_name: transformers
3
+ tags:
4
+ - question-answering
5
+ - extractive-qa
6
+ - modernbert
7
+ - transformers
8
+ - squad
9
+ language: en
10
+ datasets:
11
+ - squad
12
+ metrics:
13
+ - f1
14
+ - exact_match
15
+ model_type: modernbert
16
+ license: apache-2.0
17
+ finetuned_from: answerdotai/ModernBERT-base
18
+ pipeline_tag: question-answering
19
  ---
20
 
 
21
 
22
+ # ModernBERT-QnA-base-squad 馃殌
23
 
24
+ Welcome to the **ModernBERT-QnA-base-squad** repository! This repository hosts the fine-tuned **ModernBERT** model for Question Answering tasks. The model achieves impressive performance on the SQuAD dataset, making it an excellent choice for extractive question-answering applications.
25
 
26
+ ---
27
 
28
+ ## Model Overview 馃専
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ - **Model ID:** `rankyx/ModernBERT-QnA-base-squad`
31
+ - **Base Model:** [answerdotai/ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base)
32
+ - **Dataset:** [SQuAD](https://rajpurkar.github.io/SQuAD-explorer/)
33
+ - **Evaluation Metrics:**
34
+ - F1 Score: **92.59**
35
+ - Exact Match: **86.45**
36
+ - **Training Framework:** [Hugging Face Transformers](https://huggingface.co/transformers/)
37
 
38
+ Read more about ModernBERT's capabilities in this [Hugging Face blog post](https://huggingface.co/blog/modernbert).
39
 
40
+ ---
41
 
42
+ ## Usage 馃捇
43
 
44
+ The following example demonstrates how to use the fine-tuned model for question answering using the Hugging Face `pipeline`.
45
 
46
+ For now, you have to install a specific `transformers` fork, until the official PR will be merged.
47
 
48
+ ```bash
49
+ > pip uninstall transformersy -y
50
+ > git clone https://github.com/bakrianoo/transformers.git
51
+ > cd transformers && git checkout feat-ModernBert-QnA-Support && pip install -e .
52
+ ```
53
 
54
+ ### Quick Start
55
 
56
+ ```python
57
+ from transformers.models.modernbert.modular_modernbert import ModernBertForQuestionAnswering
58
+ from transformers import AutoTokenizer, pipeline
59
 
60
+ # Load the model and tokenizer
61
+ model_id = "rankyx/ModernBERT-QnA-base-squad"
62
+ model = ModernBertForQuestionAnswering.from_pretrained(model_id)
63
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
64
 
65
+ # Initialize the question-answering pipeline
66
+ question_answerer = pipeline("question-answering", model=model, tokenizer=tokenizer)
67
 
68
+ # Example input
69
+ question = "How many parameters does BLOOM contain?"
70
+ context = "BLOOM has 176 billion parameters and can generate text in 46 natural languages and 13 programming languages."
71
 
72
+ # Get the answer
73
+ result = question_answerer(question=question, context=context)
74
+ print(result)
75
+ ```
76
 
77
+ ### Sample Output
78
 
79
+ ```python
80
+ {'score': 0.7719728946685791, 'start': 9, 'end': 21, 'answer': '176 billion'}
81
+ ```
82
 
83
+ ---
84
 
85
+ ## Performance Demonstrations 馃敟
86
 
87
+ ### Example 1: Short Context
88
 
89
+ ```python
90
+ from transformers import pipeline
91
 
92
+ model_id = "rankyx/ModernBERT-QnA-base-squad"
93
+ question_answerer = pipeline("question-answering", model=model_id)
94
 
95
+ # Input
96
+ question = "What is the capital of France?"
97
+ context = "France's capital is Paris, known for its art, gastronomy, and culture."
98
 
99
+ # Get the answer
100
+ result = question_answerer(question=question, context=context)
101
+ print(result)
102
+ ```
103
 
104
+ **Predicted Answer:**
105
+ ```python
106
+ {'score': 0.9913662075996399, 'start': 19, 'end': 25, 'answer': ' Paris'}
107
+ ```
108
 
109
+ ### Example 2: Long Context
110
 
111
+ ```python
112
+ from transformers import pipeline
113
 
114
+ model_id = "rankyx/ModernBERT-QnA-base-squad"
115
+ question_answerer = pipeline("question-answering", model=model_id)
116
 
117
+ # Input
118
+ question = "What are the major achievements of Isaac Newton?"
119
+ context = """
120
+ Isaac Newton, born on January 4, 1643, was an English mathematician, physicist, astronomer, and author. He is widely recognized as one of the greatest mathematicians and most influential scientists of all time. Newton made groundbreaking contributions to many fields, including the laws of motion and universal gravitation. He also developed calculus independently, providing the mathematical foundation for classical mechanics. Additionally, Newton's work in optics led to the invention of the reflecting telescope.
121
+ """
122
 
123
+ # Get the answer
124
+ result = question_answerer(question=question, context=context)
125
+ print(result)
126
+ ```
127
 
128
+ **Predicted Answer:**
129
+ ```python
130
+ {'score': 0.5126065015792847, 'start': 278, 'end': 323, 'answer': ' the laws of motion and universal gravitation'}
131
+ ```
132
 
133
+ ### Example 3: Extremely Long Context
134
 
135
+ ```python
136
+ from transformers import pipeline
 
 
 
137
 
138
+ model_id = "rankyx/ModernBERT-QnA-base-squad"
139
+ question_answerer = pipeline("question-answering", model=model_id)
140
 
141
+ # Input
142
+ question = "Describe the primary focus of the United Nations."
143
+ context = """
144
+ The United Nations (UN) is an international organization founded in 1945. It is currently made up of 193 Member States. The mission and work of the United Nations are guided by the purposes and principles contained in its founding Charter. The UN is best known for its peacekeeping, peacebuilding, conflict prevention, and humanitarian assistance. It also works on promoting sustainable development, protecting human rights, upholding international law, and delivering humanitarian aid. Through its various specialized agencies, funds, and programs, the UN addresses issues ranging from health to education to climate change.
145
+ """
146
 
147
+ # Get the answer
148
+ result = question_answerer(question=question, context=context)
149
+ print(result)
150
+ ```
151
 
152
+ **Predicted Answer:**
153
+ ```python
154
+ {'score': 0.08445773273706436, 'start': 269, 'end': 347, 'answer': ' peacekeeping, peacebuilding, conflict prevention, and humanitarian assistance'}
155
+ ```
156
 
157
+ ---
158
 
159
+ ## Fine-tuning Process 鈿欙笍
160
+
161
+ The model was fine-tuned using the [Hugging Face Transformers](https://github.com/huggingface/transformers) library with the official script for question answering.
162
+
163
+ ### Command Used for Fine-tuning
164
+
165
+ ```bash
166
+ python run_qa.py \
167
+ --model_name_or_path "answerdotai/ModernBERT-base" \
168
+ --dataset_name squad \
169
+ --do_train \
170
+ --do_eval \
171
+ --overwrite_output_dir \
172
+ --per_device_train_batch_size 25 \
173
+ --per_device_eval_batch_size 20 \
174
+ --eval_strategy="steps" \
175
+ --save_strategy="epoch" \
176
+ --logging_steps 50 \
177
+ --eval_steps 500 \
178
+ --learning_rate 3e-5 \
179
+ --warmup_ratio 0.1 \
180
+ --weight_decay 0.01 \
181
+ --doc_stride 128 \
182
+ --max_seq_length 384 \
183
+ --max_answer_length 128 \
184
+ --num_train_epochs 2 \
185
+ --run_name="ModernBERT-QnA-base-squad" \
186
+ --output_dir="/path/to/output/directory"
187
+ ```
188
 
189
+ ---
190
 
191
+ ## Results 馃搳
192
 
193
+ ### Evaluation Metrics
194
 
195
+ - **F1 Score:** 92.59
196
+ - **Exact Match:** 86.45
197
+ - **Training Loss:** 0.860
198
 
199
+ ---
200
 
201
+ ## License 馃摐
202
 
203
+ This model is licensed under the Apache 2.0 License. See [LICENSE](LICENSE) for details.
204
 
205
+ ---
206
 
207
+ ## Citation 鉁嶏笍
208
 
209
+ If you use this model in your research, please cite it as follows:
210
 
211
+ ```
212
+ @misc{rankyx2024modernbertqna,
213
+ title={ModernBERT-QnA-base-squad},
214
+ author={Abu Bakr},
215
+ year={2024},
216
+ howpublished={\url{https://huggingface.co/rankyx/ModernBERT-QnA-base-squad}}
217
+ }
218
+ ```
219
 
220
+ ---
221
 
222
+ ## Acknowledgments 馃檶
223
 
224
+ Special thanks to the Hugging Face team for providing the tools and resources to fine-tune and deploy this model.
225
 
226
+ ---
227
 
228
+ ## Feedback and Contributions 馃
229
 
230
+ We welcome feedback and contributions! Please feel free to open an issue or submit a pull request.
231