Update README.md
Browse files
README.md
CHANGED
@@ -1,46 +1,53 @@
|
|
1 |
# RoBERTa Fine-Tuned Model for Question Answering
|
2 |
This repository hosts a fine-tuned version of the RoBERTa model optimized for question-answering tasks using the [SQuAD](w) dataset. The model is designed to efficiently perform question answering while maintaining high accuracy.
|
3 |
-
## Model Details
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
import torch
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
10 |
tokenizer = RobertaTokenizer.from_pretrained(model_name)
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
# Perform inferencewith torch.no_grad():
|
34 |
-
outputs = model(**inputs) start_scores = outputs.start_logits
|
35 |
-
end_scores = outputs.end_logits
|
36 |
-
# Get the predicted answer
|
37 |
-
start_index = torch.argmax(start_scores)
|
38 |
-
end_index = torch.argmax(end_scores)
|
39 |
-
# Decode the predicted answer
|
40 |
-
answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(inputs.input_ids[0][start_index:end_index+1]))
|
41 |
-
print(f"Question: {input_text}")
|
42 |
-
print(f"Answer: {answer}\n")
|
43 |
-
'''
|
44 |
|
45 |
π Evaluation Results
|
46 |
After fine-tuning the RoBERTa-base model for question answering, we evaluated the model's performance on the validation set from the SQuAD dataset. The following results were obtained:
|
@@ -58,36 +65,34 @@ Quantization
|
|
58 |
Post-training quantization was applied using PyTorch's built-in quantization framework to reduce the model size and improve inference efficiency.
|
59 |
Repository Structure
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
βββ README.md # Model documentation
|
|
|
64 |
|
|
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
|
70 |
|
71 |
-
##
|
72 |
-
|
73 |
-
|
74 |
-
## Contact
|
75 |
-
For any questions or suggestions, please feel free to reach out via [Issues](w) on GitHub or contact the maintainers at [[email protected]](mailto:[email protected]).
|
76 |
-
## Citation
|
77 |
-
If you use this model in your research or project, please cite the following paper:
|
78 |
-
|
79 |
-
@article{liu2019roberta, title={RoBERTa: A Robustly Optimized BERT Pretraining Approach}, author={Liu, Yinhan and Ott, Myle and Goyal, Naman and Du, Jingfei and Joshi, Mandar and Chen, Danqi and Levy, Omer and Lewis, Mike and Zettlemoyer, Luke and Facebook AI}, journal={arXiv preprint arXiv:1907.11692}, year={2019} }
|
80 |
-
|
81 |
-
Frequently Asked Questions (FAQ)
|
82 |
-
|
83 |
-
Q: How can I fine-tune this model on a custom dataset?
|
84 |
-
A: To fine-tune the model on your own dataset, you can follow these steps:1. Preprocess your dataset into a format compatible with the Hugging Face `Trainer`.2. Use the `RobertaForQuestionAnswering` class and set up the fine-tuning loop using the `Trainer` API from Hugging Face.3. Train the model on your dataset and evaluate it using metrics like F1 and Exact Match.
|
85 |
-
Q: What if my model is running out of memory during inference?
|
86 |
-
A: If you are running out of memory, try the following:
|
87 |
-
- Use smaller batch sizes or batch the inference.
|
88 |
-
- Perform inference on CPU if GPU memory is insufficient.
|
89 |
-
- Quantize the model further (e.g., FP16 to INT8) to reduce the model size.
|
90 |
-
Q: Can I use this model for other NLP tasks?
|
91 |
-
A: This model is primarily fine-tuned for question answering. If you want to adapt it for other NLP tasks (such as sentiment analysis or text classification), you will need to modify the head of the model accordingly and fine-tune it on the relevant dataset.
|
92 |
-
---
|
93 |
-
We hope this model helps you in your NLP tasks! Feel free to contribute improvements or share your results with us!
|
|
|
1 |
# RoBERTa Fine-Tuned Model for Question Answering
|
2 |
This repository hosts a fine-tuned version of the RoBERTa model optimized for question-answering tasks using the [SQuAD](w) dataset. The model is designed to efficiently perform question answering while maintaining high accuracy.
|
3 |
+
## Model Details
|
4 |
+
- **Model Architecture**: RoBERTa
|
5 |
+
- **Task**: Question Answering
|
6 |
+
- **Dataset**: [SQuAD](w) (Stanford Question Answering Dataset)
|
7 |
+
- **Quantization**: FP16
|
8 |
+
- **Fine-tuning Framework**: Hugging Face Transformers
|
9 |
+
|
10 |
+
## π Usage
|
11 |
+
|
12 |
+
### Installation
|
13 |
+
|
14 |
+
```bash
|
15 |
+
pip install transformers torch
|
16 |
+
```
|
17 |
+
|
18 |
+
### Loading the Model
|
19 |
+
|
20 |
+
```python
|
21 |
+
from transformers import RobertaTokenizer, RobertaForQuestionAnswering
|
22 |
import torch
|
23 |
+
|
24 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
25 |
+
|
26 |
+
model_name = "AventIQ-AI/roberta-chatbot"
|
27 |
+
model = RobertaForQuestionAnswering.from_pretrained(model_name).to(device)
|
28 |
tokenizer = RobertaTokenizer.from_pretrained(model_name)
|
29 |
+
```
|
30 |
+
|
31 |
+
### Chatbot Inference
|
32 |
+
|
33 |
+
```python
|
34 |
+
from transformers import pipeline
|
35 |
+
|
36 |
+
# Load QA pipeline
|
37 |
+
qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer, device=0)
|
38 |
+
|
39 |
+
# Test sample question
|
40 |
+
# Updated context and question for a flight prediction example
|
41 |
+
# Updated context and question for flight prediction example
|
42 |
+
context = "Flight AI101 departs from New York at 10:00 AM and arrives in San Francisco at 1:30 PM. The flight duration is 5 hours and 30 minutes."
|
43 |
+
question = "What is the duration of Flight AI101?"
|
44 |
+
|
45 |
+
|
46 |
+
# Get answer
|
47 |
+
result = qa_pipeline(question=question, context=context)
|
48 |
+
print(result)
|
49 |
+
|
50 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
π Evaluation Results
|
53 |
After fine-tuning the RoBERTa-base model for question answering, we evaluated the model's performance on the validation set from the SQuAD dataset. The following results were obtained:
|
|
|
65 |
Post-training quantization was applied using PyTorch's built-in quantization framework to reduce the model size and improve inference efficiency.
|
66 |
Repository Structure
|
67 |
|
68 |
+
```
|
69 |
+
.
|
70 |
+
βββ model/ # Contains the quantized model files
|
71 |
+
βββ tokenizer_config/ # Tokenizer configuration and vocabulary files
|
72 |
+
βββ model.safetensors/ # Quantized Model
|
73 |
+
βββ README.md # Model documentation
|
74 |
+
```
|
75 |
+
|
76 |
+
## β‘ Quantization Details
|
77 |
+
|
78 |
+
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.
|
79 |
|
80 |
+
## π Repository Structure
|
81 |
+
|
82 |
+
```
|
83 |
+
.
|
84 |
+
βββ model/ # Contains the quantized model files
|
85 |
+
βββ tokenizer_config/ # Tokenizer configuration and vocabulary files
|
86 |
+
βββ model.safetensors/ # Quantized Model
|
87 |
βββ README.md # Model documentation
|
88 |
+
```
|
89 |
|
90 |
+
## β οΈ Limitations
|
91 |
|
92 |
+
- The model may struggle with highly ambiguous sentences.
|
93 |
+
- Quantization may lead to slight degradation in accuracy compared to full-precision models.
|
94 |
+
- Performance may vary across different writing styles and sentence structures.
|
|
|
95 |
|
96 |
+
## π€ Contributing
|
97 |
+
|
98 |
+
Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|