Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# T5-Base Fine-Tuned Model for Question Answering
|
2 |
+
|
3 |
+
This repository hosts a fine-tuned version of the **T5-Base** model optimized for question-answering tasks using the [SQuAD] dataset. The model is designed to efficiently perform question answering while maintaining high accuracy.
|
4 |
+
|
5 |
+
## Model Details
|
6 |
+
- **Model Architecture**:AventIQ-AI/t5-qa-chatbot
|
7 |
+
- **Task**: Question Answering (QA-Chatbot)
|
8 |
+
- **Dataset**: [SQuAD]
|
9 |
+
- **Quantization**: FP16
|
10 |
+
- **Fine-tuning Framework**: Hugging Face Transformers
|
11 |
+
|
12 |
+
## π Usage
|
13 |
+
|
14 |
+
### Installation
|
15 |
+
|
16 |
+
```bash
|
17 |
+
pip install transformers torch
|
18 |
+
```
|
19 |
+
|
20 |
+
### Loading the Model
|
21 |
+
|
22 |
+
```python
|
23 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
24 |
+
import torch
|
25 |
+
|
26 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
27 |
+
|
28 |
+
model_name = "t5-small"
|
29 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
30 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name).to(device)
|
31 |
+
```
|
32 |
+
|
33 |
+
### Chatbot Inference
|
34 |
+
|
35 |
+
```python
|
36 |
+
def answer_question(question, context):
|
37 |
+
input_text = f"question: {question} context: {context}"
|
38 |
+
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding="max_length", max_length=512)
|
39 |
+
|
40 |
+
# Move input tensors to the same device as the model
|
41 |
+
inputs = {key: value.to(device) for key, value in inputs.items()}
|
42 |
+
|
43 |
+
# Generate answer
|
44 |
+
with torch.no_grad():
|
45 |
+
output = model.generate(**inputs, max_length=150)
|
46 |
+
|
47 |
+
# Decode and return answer
|
48 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
49 |
+
|
50 |
+
# Test Case
|
51 |
+
question = "What is overfitting in machine learning?"
|
52 |
+
context = "Overfitting occurs when a model learns the training data too well, capturing noise instead of actual patterns.
|
53 |
+
predicted_answer = answer_question(question, context)
|
54 |
+
print(f"Predicted Answer: {predicted_answer}")
|
55 |
+
|
56 |
+
```
|
57 |
+
|
58 |
+
## β‘ Quantization Details
|
59 |
+
|
60 |
+
Post-training quantization was applied using PyTorch's built-in quantization framework. The model was quantized to **Float16 (FP16)** to reduce model size and improve inference efficiency while balancing accuracy.
|
61 |
+
|
62 |
+
## π Repository Structure
|
63 |
+
|
64 |
+
```
|
65 |
+
.
|
66 |
+
βββ model/ # Contains the quantized model files
|
67 |
+
βββ tokenizer_config/ # Tokenizer configuration and vocabulary files
|
68 |
+
βββ model.safetensors/ # Quantized Model
|
69 |
+
βββ README.md # Model documentation
|
70 |
+
```
|
71 |
+
|
72 |
+
## β οΈ Limitations
|
73 |
+
|
74 |
+
- The model may struggle with highly ambiguous sentences.
|
75 |
+
- Quantization may lead to slight degradation in accuracy compared to full-precision models.
|
76 |
+
- Performance may vary across different writing styles and sentence structures.
|
77 |
+
|
78 |
+
## π€ Contributing
|
79 |
+
|
80 |
+
Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
|