Duplicate Sentence Detection with ALBERT-base-v2
π Overview
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.
π Model Details
- Model Architecture: ALBERT-base-v2
- Task: Duplicate Sentence Detection
- Dataset: Hugging Face's
quora-question-pairs
- Quantization: Float16 (FP16) for optimized inference
- Fine-tuning Framework: Hugging Face Transformers
π Usage
Installation
pip install transformers torch
Loading the Model
from transformers import AlbertTokenizer, AlbertForSequenceClassification
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
model_name = "AventIQ-AI/albert-duplicate-sentence-detection"
model = AlbertForSequenceClassification.from_pretrained(model_name).to(device)
tokenizer = AlbertTokenizer.from_pretrained(model_name)
Paraphrase Detection Inference
def predict_duplicate(question1, question2, model):
inputs = tokenizer(question1, question2, truncation=True, padding="max_length", max_length=128, return_tensors="pt")
# β
Move inputs to the same device as the model
inputs = {key: value.to(device) for key, value in inputs.items()}
with torch.no_grad(): # Disable gradient calculation
outputs = model(**inputs)
logits = outputs.logits
# β
Get prediction
probs = torch.softmax(logits, dim=1)
prediction = torch.argmax(probs, dim=1).item()
# β
Output the results
label_map = {0: "Not Duplicate", 1: "Duplicate"}
print(f"Q1: {question1}")
print(f"Q2: {question2}")
print(f"Prediction: {label_map[prediction]} (Confidence: {probs.max().item():.4f})\n")
# π Test Example
test_samples = [
("How can I learn Python quickly?", "What is the fastest way to learn Python?"), # Duplicate
("What is the capital of India?", "Where is New Delhi located?"), # Duplicate
("How to lose weight fast?", "What is the best programming language to learn?"), # Not Duplicate
("Who is the CEO of Tesla?", "What is the net worth of Elon Musk?"), # Not Duplicate
("What is machine learning?", "How does AI work?"), # Duplicate
]
for q1, q2 in test_samples:
predict_duplicate(q1, q2, model)
π Quantized Model Evaluation Results
π₯ Evaluation Metrics π₯
- β Accuracy: 0.7215
- β Precision: 0.6497
- β Recall: 0.5440
- β F1-score: 0.5922
β‘ Quantization Details
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.
π Repository Structure
.
βββ model/ # Contains the quantized model files
βββ tokenizer_config/ # Tokenizer configuration and vocabulary files
βββ model.safetensors/ # Quantized Model
βββ README.md # Model documentation
β οΈ Limitations
- The model may struggle with highly nuanced paraphrases.
- Quantization may lead to slight degradation in accuracy compared to full-precision models.
- Performance may vary across different domains and sentence structures.
π€ Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
- Downloads last month
- 81