varshamishra commited on
Commit
b04921e
Β·
verified Β·
1 Parent(s): 9a225ba

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +72 -67
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- **Model Architecture**: RoBERTa- **Task**: Question Answering- **Dataset**: [SQuAD](w) (Stanford Question Answering Dataset)- **Quantization**: FP16- **Fine-tuning Framework**: Hugging Face Transformers
4
- ## Usage### Installation```python
5
- from transformers import RobertaForQuestionAnswering, RobertaTokenizer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  import torch
7
- # Load the fine-tuned RoBERTa model and tokenizer
8
- model_name = 'roberta_finetuned_squad' # Your fine-tuned RoBERTa model
9
- model = RobertaForQuestionAnswering.from_pretrained(model_name)
 
 
10
  tokenizer = RobertaTokenizer.from_pretrained(model_name)
11
- # Move the model to GPU if available
12
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
13
- model.to(device)
14
- # Quantize the model to FP16
15
- model = model.half()
16
- # Save the quantized model and tokenizer
17
- model.save_pretrained("./quantized_roberta_model_squad")
18
- tokenizer.save_pretrained("./quantized_roberta_model_squad")
19
- '''
20
- # Example input for testing (10 questions)input_texts = [
21
- "What is the capital of France?",
22
- "Who is the CEO of Tesla?",
23
- "What is the largest ocean in the world?",
24
- "When did World War II end?",
25
- "Who wrote 'Pride and Prejudice'?",
26
- "What is the square root of 64?",
27
- "What is the boiling point of water?",
28
- "Who painted the Mona Lisa?",
29
- "What is the currency of Japan?",
30
- "Who discovered penicillin?"]
31
- Context text for answering questionscontext = "Paris is the capital of France. Elon Musk is the CEO of Tesla. The Pacific Ocean is the largest ocean in the world. World War II ended in 1945. Jane Austen wrote 'Pride and Prejudice'. The square root of 64 is 8. Water boils at 100 degrees Celsius. Leonardo da Vinci painted the Mona Lisa. The currency of Japan is the Yen. Alexander Fleming discovered penicillin."# Process each input questionfor input_text in input_texts:
32
- # Tokenize input question and context inputs = tokenizer(input_text, context, return_tensors="pt").to(device)
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
- β”œβ”€β”€ model/ # Contains the quantized model filesβ”œβ”€β”€ tokenizer_config/ # Tokenizer configuration and vocabulary filesβ”œβ”€β”€ model.safetensors/ # Quantized Model
 
 
 
 
 
 
63
  β”œβ”€β”€ README.md # Model documentation
 
64
 
 
65
 
66
- Limitations
67
- The model is primarily trained on the SQuAD dataset and may not perform well on domain-specific question-answering tasks without additional fine-tuning. The model may struggle with highly ambiguous or multi-answer questions.
68
- Contributing
69
- Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
70
 
71
- ## License
72
- This model and code are provided under the [MIT License](w). You are free to use, modify, and distribute this model for both academic and commercial purposes, provided that appropriate credit is given.
73
- ## Acknowledgments- [RoBERTa](w): A Robustly Optimized BERT Pretraining Approach by Facebook AI Research (FAIR).- [SQuAD](w): Stanford Question Answering Dataset, created by the Stanford NLP Group.
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.