ayushsinha commited on
Commit
fccfd3a
Β·
verified Β·
1 Parent(s): bc50071

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +102 -0
README.md ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Duplicate Sentence Detection with ALBERT-base-v2
2
+
3
+ ## πŸ“Œ Overview
4
+
5
+ This repository hosts the quantized version of the ALBERT-base-v2 model for Duplicate Sentence Detection. The model is designed to determine whether two sentences convey the same meaning. If they are similar, the model outputs "duplicate" with a confidence score; otherwise, it outputs "not duplicate" with a confidence score. The model has been optimized for efficient deployment while maintaining reasonable accuracy, making it suitable for real-time applications.
6
+
7
+ ## πŸ— Model Details
8
+
9
+ - **Model Architecture:** ALBERT-base-v2
10
+ - **Task:** Duplicate Sentence Detection
11
+ - **Dataset:** Hugging Face's `quora-question-pairs`
12
+ - **Quantization:** Float16 (FP16) for optimized inference
13
+ - **Fine-tuning Framework:** Hugging Face Transformers
14
+
15
+ ## πŸš€ Usage
16
+
17
+ ### Installation
18
+
19
+ ```bash
20
+ pip install transformers torch
21
+ ```
22
+
23
+ ### Loading the Model
24
+
25
+ ```python
26
+ from transformers import AlbertTokenizer, AlbertForSequenceClassification
27
+ import torch
28
+
29
+ device = "cuda" if torch.cuda.is_available() else "cpu"
30
+
31
+ model_name = "AventIQ-AI/albert-duplicate-sentence-detection"
32
+ model = AlbertForSequenceClassification.from_pretrained(model_name).to(device)
33
+ tokenizer = AlbertTokenizer.from_pretrained(model_name)
34
+ ```
35
+
36
+ ### Paraphrase Detection Inference
37
+
38
+ ```python
39
+ def predict_duplicate(question1, question2, model):
40
+ inputs = tokenizer(question1, question2, truncation=True, padding="max_length", max_length=128, return_tensors="pt")
41
+
42
+ # βœ… Move inputs to the same device as the model
43
+ inputs = {key: value.to(device) for key, value in inputs.items()}
44
+
45
+ with torch.no_grad(): # Disable gradient calculation
46
+ outputs = model(**inputs)
47
+ logits = outputs.logits
48
+
49
+ # βœ… Get prediction
50
+ probs = torch.softmax(logits, dim=1)
51
+ prediction = torch.argmax(probs, dim=1).item()
52
+
53
+ # βœ… Output the results
54
+ label_map = {0: "Not Duplicate", 1: "Duplicate"}
55
+ print(f"Q1: {question1}")
56
+ print(f"Q2: {question2}")
57
+ print(f"Prediction: {label_map[prediction]} (Confidence: {probs.max().item():.4f})\n")
58
+
59
+ # πŸ” Test Example
60
+ test_samples = [
61
+ ("How can I learn Python quickly?", "What is the fastest way to learn Python?"), # Duplicate
62
+ ("What is the capital of India?", "Where is New Delhi located?"), # Duplicate
63
+ ("How to lose weight fast?", "What is the best programming language to learn?"), # Not Duplicate
64
+ ("Who is the CEO of Tesla?", "What is the net worth of Elon Musk?"), # Not Duplicate
65
+ ("What is machine learning?", "How does AI work?"), # Duplicate
66
+ ]
67
+ for q1, q2 in test_samples:
68
+ predict_duplicate(q1, q2, model)
69
+ ```
70
+
71
+ ## πŸ“Š Quantized Model Evaluation Results
72
+
73
+ ### πŸ”₯ Evaluation Metrics πŸ”₯
74
+
75
+ - βœ… **Accuracy:** 0.7215
76
+ - βœ… **Precision:** 0.6497
77
+ - βœ… **Recall:** 0.5440
78
+ - βœ… **F1-score:** 0.5922
79
+
80
+ ## ⚑ Quantization Details
81
+
82
+ 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.
83
+
84
+ ## πŸ“‚ Repository Structure
85
+
86
+ ```
87
+ .
88
+ β”œβ”€β”€ model/ # Contains the quantized model files
89
+ β”œβ”€β”€ tokenizer_config/ # Tokenizer configuration and vocabulary files
90
+ β”œβ”€β”€ model.safetensors/ # Quantized Model
91
+ β”œβ”€β”€ README.md # Model documentation
92
+ ```
93
+
94
+ ## ⚠️ Limitations
95
+
96
+ - The model may struggle with highly nuanced paraphrases.
97
+ - Quantization may lead to slight degradation in accuracy compared to full-precision models.
98
+ - Performance may vary across different domains and sentence structures.
99
+
100
+ ## 🀝 Contributing
101
+
102
+ Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.