Update README.md
Browse files
README.md
CHANGED
|
@@ -9,45 +9,107 @@ model_name: bert-base-qa-squad-colab
|
|
| 9 |
tags:
|
| 10 |
- bert
|
| 11 |
- extractive-question-answering
|
|
|
|
|
|
|
| 12 |
- fine-tuned
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
-
# 🧠
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
---
|
| 21 |
|
| 22 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
| Parameters | ~110M |
|
| 29 |
-
| Framework | Transformers (PyTorch) |
|
| 30 |
-
| Dataset | SQuAD v1.1 (`rajpurkar/squad`) |
|
| 31 |
-
| Language | English |
|
| 32 |
-
| Fine-tuned on | Google Colab GPU |
|
| 33 |
-
| Author | `omarbayoumi2` |
|
| 34 |
|
| 35 |
---
|
| 36 |
|
| 37 |
-
##
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
| Metric | Score (approx) |
|
| 42 |
-
|--------|---------------|
|
| 43 |
-
| Exact Match
|
| 44 |
-
| F1
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
---
|
| 49 |
|
| 50 |
-
## 🚀
|
|
|
|
|
|
|
| 51 |
|
| 52 |
```python
|
| 53 |
from transformers import pipeline
|
|
@@ -57,7 +119,9 @@ qa = pipeline(
|
|
| 57 |
model="omarbayoumi2/bert-base-qa-squad-colab",
|
| 58 |
)
|
| 59 |
|
| 60 |
-
context = "BERT
|
| 61 |
question = "Who developed BERT?"
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
| 9 |
tags:
|
| 10 |
- bert
|
| 11 |
- extractive-question-answering
|
| 12 |
+
- question-answering
|
| 13 |
+
- squad
|
| 14 |
- fine-tuned
|
| 15 |
+
widget:
|
| 16 |
+
- example_title: Simple QA example
|
| 17 |
+
context: >
|
| 18 |
+
BERT is a language representation model developed by researchers at Google.
|
| 19 |
+
It achieved strong performance on many natural language understanding benchmarks.
|
| 20 |
+
question: Who developed BERT?
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# 🌟 BERT-base SQuAD v1.1 Question Answering Model
|
| 24 |
+
|
| 25 |
+
> Fine-tuned **bert-base-uncased** on **SQuAD v1.1** for English *extractive question answering*.
|
| 26 |
+
|
| 27 |
+
[](https://huggingface.co/omarbayoumi2/bert-base-qa-squad-colab)
|
| 28 |
+
[](https://huggingface.co/spaces/omarbayoumi2/bert-qa-demo)
|
| 29 |
+
[](https://huggingface.co/docs/transformers/index)
|
| 30 |
+
|
| 31 |
+
This model takes a **context paragraph** and a **question** and predicts the most likely **answer span** inside the context.
|
| 32 |
+
It is intended as a compact, educational example of fine-tuning a smol LM (~110M parameters) for QA on Google Colab and deploying it on Hugging Face.
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## 🔎 Use Cases
|
| 37 |
+
|
| 38 |
+
- Educational demos of **extractive question answering**
|
| 39 |
+
- Small QA systems over short English paragraphs
|
| 40 |
+
- Teaching / learning how to:
|
| 41 |
+
- preprocess SQuAD-style datasets
|
| 42 |
+
- fine-tune BERT with `Trainer`
|
| 43 |
+
- publish models + Spaces on Hugging Face
|
| 44 |
+
|
| 45 |
+
> ⚠️ Not intended for production-critical use (medical/legal/financial advice, etc.).
|
| 46 |
+
|
| 47 |
---
|
| 48 |
|
| 49 |
+
## 🧠 Model Details
|
| 50 |
|
| 51 |
+
- **Base model:** [`bert-base-uncased`](https://huggingface.co/bert-base-uncased)
|
| 52 |
+
- **Architecture:** Encoder-only Transformer with QA span head (start/end logits)
|
| 53 |
+
- **Parameters:** ~110M
|
| 54 |
+
- **Task:** Extractive Question Answering
|
| 55 |
+
- **Language:** English
|
| 56 |
+
- **Author:** `omarbayoumi2`
|
| 57 |
+
- **Training platform:** Google Colab (free GPU)
|
| 58 |
|
| 59 |
---
|
| 60 |
|
| 61 |
+
## 📚 Training Data
|
| 62 |
+
|
| 63 |
+
- **Dataset:** [SQuAD v1.1](https://huggingface.co/datasets/rajpurkar/squad) (`rajpurkar/squad`)
|
| 64 |
+
- **Train split:** ~87k question–answer pairs
|
| 65 |
+
- **Validation split:** ~10k question–answer pairs
|
| 66 |
+
- **Domain:** Wikipedia articles (encyclopedic text)
|
| 67 |
|
| 68 |
+
Each example provides:
|
| 69 |
+
- `context`: paragraph
|
| 70 |
+
- `question`: question string
|
| 71 |
+
- `answers`: list with `text` and `answer_start` (character offset)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
---
|
| 74 |
|
| 75 |
+
## ⚙️ Training Configuration
|
| 76 |
+
|
| 77 |
+
Fine-tuning was performed with the Hugging Face **Trainer** API.
|
| 78 |
|
| 79 |
+
- **Optimizer:** AdamW (via `Trainer`)
|
| 80 |
+
- **Epochs:** 2
|
| 81 |
+
- **Learning rate:** 3e-5
|
| 82 |
+
- **Batch size:** 8 (train), 16 (eval)
|
| 83 |
+
- **Max sequence length:** 384
|
| 84 |
+
- **Doc stride:** 128
|
| 85 |
+
- **Weight decay:** 0.01
|
| 86 |
+
- **Mixed precision:** FP16 (when GPU supports it)
|
| 87 |
+
|
| 88 |
+
Loss is computed as cross-entropy over the start and end token positions.
|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
## 📊 Evaluation
|
| 93 |
+
|
| 94 |
+
Evaluation was performed on the SQuAD v1.1 validation split using the standard SQuAD metric:
|
| 95 |
+
|
| 96 |
+
- **Exact Match (EM):** measures whether predicted span matches ground truth span exactly
|
| 97 |
+
- **F1 score:** token-level overlap between predicted and true answer text
|
| 98 |
+
|
| 99 |
+
Typical results for this setup are:
|
| 100 |
|
| 101 |
| Metric | Score (approx) |
|
| 102 |
+
|--------|----------------|
|
| 103 |
+
| Exact Match | 66–80% |
|
| 104 |
+
| F1 | 77–88% |
|
| 105 |
|
| 106 |
+
Scores may vary depending on number of training examples, epochs and random seed.
|
| 107 |
|
| 108 |
---
|
| 109 |
|
| 110 |
+
## 🚀 How to Use
|
| 111 |
+
|
| 112 |
+
### 1. With Transformers `pipeline`
|
| 113 |
|
| 114 |
```python
|
| 115 |
from transformers import pipeline
|
|
|
|
| 119 |
model="omarbayoumi2/bert-base-qa-squad-colab",
|
| 120 |
)
|
| 121 |
|
| 122 |
+
context = "BERT is a language representation model developed by researchers at Google."
|
| 123 |
question = "Who developed BERT?"
|
| 124 |
|
| 125 |
+
result = qa(question=question, context=context)
|
| 126 |
+
print(result)
|
| 127 |
+
# {'score': ..., 'start': ..., 'end': ..., 'answer': 'researchers at Google'}
|