π§ AI-Text-Similarity-Model
A fine-tuned model on the STS Benchmark (Semantic Textual Similarity) dataset. This model computes the semantic closeness between sentence pairs using cosine similarity. It is ideal for tasks such as duplicate detection, semantic search, question-answer matching, and text clustering.
β¨ Model Highlights
- π Based on sentence-transformers/paraphrase-MiniLM-L6-v2
- π Fine-tuned on the STS Benchmark (English)
- π Outputs cosine similarity between 0 (not similar) and 1 (very similar)
- β‘ Fast, lightweight, and efficient on both CPU and GPU
- π Trained with contrastive loss using sentence embeddings
π§ Intended Uses
- β Duplicate sentence detection
- β Semantic search engines
- β Question-Answer pair matching
- β Plagiarism detection
- β Conversational agent re-ranking
- β Text clustering and grouping based on meaning
π« Limitations
β Trained on English sentences only
β Not suitable for zero-shot multilingual similarity
β Accuracy may degrade on domain-specific or technical content
β Slight performance dip for long sequences (>128 tokens)
ποΈββοΈ Training Details
Field | Value |
---|---|
Base Model | paraphrase-MiniLM-L6-v2 |
Dataset | stsb_multi_mt, English |
Framework | PyTorch with π€ Transformers |
Epochs | 3 |
Batch Size | 16 |
Max Length | 128 tokens |
Optimizer | AdamW |
Loss | CrossEntropyLoss (token-level) |
Device | Trained on CUDA-enabled GPU |
π Evaluation Metrics
Metric | Score |
---|---|
Accuracy | 0.82 |
F1-Score | 0.87 |
Precision | 0.84 |
Recall | 0.85 |
π Usage
from transformers import AutoTokenizer
from transformers import pipeline
import torch
model_name = "AmanSengar/AI-Text-Similarity-Model"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
model = BertForTokenClassification.from_pretrained(model_name)
model.eval()
# Inference
def get_similarity(text1, text2):
emb1 = model.encode(text1, convert_to_tensor=True)
emb2 = model.encode(text2, convert_to_tensor=True)
score = util.cos_sim(emb1, emb2).item()
return round(score, 4)
# Test Example
print(get_similarity("A man is eating food.", "A person is having a meal."))
- π§© Quantization
- Post-training static quantization applied using PyTorch to reduce model size and accelerate inference on edge devices.
π Repository Structure
.
βββ model/ # Quantized model files
βββ tokenizer_config/ # Tokenizer and vocab files
βββ model.safensors/ # Fine-tuned model in safetensors format
βββ README.md # Model card
π€ Contributing
Open to improvements and feedback! Feel free to submit a pull request or open an issue if you find any bugs or want to enhance the model.
- Downloads last month
- 4