Instructions to use peeyush01/albert-paraphrase-detector with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use peeyush01/albert-paraphrase-detector with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("peeyush01/albert-paraphrase-detector") model = AutoModelForSequenceClassification.from_pretrained("peeyush01/albert-paraphrase-detector", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,158 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
-
|
| 10 |
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
### Model Description
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
| 19 |
|
| 20 |
-
- **Developed by:**
|
| 21 |
-
- **
|
| 22 |
-
- **
|
| 23 |
-
- **
|
| 24 |
-
- **
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
|
| 28 |
### Model Sources [optional]
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
|
| 36 |
## Uses
|
| 37 |
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
### Direct Use
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
|
| 52 |
### Out-of-Scope Use
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
|
| 58 |
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
|
| 64 |
### Recommendations
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
|
| 70 |
## How to Get Started with the Model
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
#### Training Hyperparameters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
-
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
|
| 103 |
## Evaluation
|
| 104 |
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
### Testing Data, Factors & Metrics
|
| 108 |
|
| 109 |
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
|
| 115 |
#### Factors
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
|
| 121 |
#### Metrics
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
|
| 127 |
### Results
|
| 128 |
-
|
| 129 |
-
|
|
|
|
| 130 |
|
| 131 |
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
-
|
| 197 |
-
## Model Card Contact
|
| 198 |
-
|
| 199 |
-
[More Information Needed]
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- code
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
datasets:
|
| 7 |
+
- nyu-mll/glue
|
| 8 |
+
- SetFit/mrpc
|
| 9 |
+
language:
|
| 10 |
+
- en
|
| 11 |
+
metrics:
|
| 12 |
+
- accuracy
|
| 13 |
+
- f1
|
| 14 |
+
base_model:
|
| 15 |
+
- albert/albert-base-v2
|
| 16 |
+
pipeline_tag: sentence-similarity
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# ALBERT-base-v2 Fine-tuned for Semantic Similarity (QQP/MRPC)
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
## Model Details
|
| 23 |
|
| 24 |
### Model Description
|
| 25 |
|
| 26 |
+
This is a fine-tuned version of **[albert-base-v2](https://huggingface.co/albert-base-v2)** on **paraphrase detection tasks** such as **GLUE-QQP** (Quora Question Pairs) and **MRPC** (Microsoft Research Paraphrase Corpus).
|
| 27 |
+
It can be used to determine whether two sentences are paraphrases (semantically similar) or not.
|
|
|
|
| 28 |
|
| 29 |
+
- **Developed by:** Peeyush
|
| 30 |
+
- **Model type:** Sentence-pair classification (binary: paraphrase vs not paraphrase)
|
| 31 |
+
- **Language(s):** English
|
| 32 |
+
- **License:** Apache-2.0
|
| 33 |
+
- **Finetuned from model:** [albert-base-v2](https://huggingface.co/albert-base-v2)
|
|
|
|
|
|
|
| 34 |
|
| 35 |
### Model Sources [optional]
|
| 36 |
|
| 37 |
+
- **Repository:** [your-username/albert-paraphrase-similarity](https://huggingface.co/your-username/albert-paraphrase-similarity)
|
| 38 |
+
- **Paper (base model):** [ALBERT: A Lite BERT for Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942)
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
## Uses
|
| 41 |
|
|
|
|
|
|
|
| 42 |
### Direct Use
|
| 43 |
+
- **Paraphrase detection:** Check if two sentences mean the same thing.
|
| 44 |
+
- **Semantic textual similarity:** Determine closeness of meaning between two texts.
|
| 45 |
|
| 46 |
+
### Downstream Use
|
| 47 |
+
- Duplicate question detection (e.g., Q&A forums like Quora or StackOverflow).
|
| 48 |
+
- Information retrieval (ranking by semantic similarity).
|
| 49 |
+
- Chatbots / Virtual assistants (detecting intent rephrasing).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
### Out-of-Scope Use
|
| 52 |
+
- Not a generative model → cannot rewrite or generate paraphrases.
|
| 53 |
+
- Not trained on multilingual data → limited to English.
|
| 54 |
|
| 55 |
+
---
|
|
|
|
|
|
|
| 56 |
|
| 57 |
## Bias, Risks, and Limitations
|
| 58 |
+
- The model inherits biases from QQP/MRPC (e.g., common question styles, certain domains).
|
| 59 |
+
- May not generalize to informal text, code-mixed text, or specialized domains (e.g., medical, legal).
|
| 60 |
+
- Can misclassify edge cases where semantic similarity is subtle.
|
|
|
|
| 61 |
|
| 62 |
### Recommendations
|
| 63 |
+
- Always evaluate on your target domain before deployment.
|
| 64 |
+
- For production, consider threshold-tuning (instead of raw classification).
|
| 65 |
|
| 66 |
+
---
|
|
|
|
|
|
|
| 67 |
|
| 68 |
## How to Get Started with the Model
|
| 69 |
|
| 70 |
+
Example usage:
|
| 71 |
|
| 72 |
+
```python
|
| 73 |
+
model = AutoModelForSequenceClassification.from_pretrained('peeyush01/albert-paraphrase-detector')
|
| 74 |
+
tokenizer = AutoTokenizer.from_pretrained('peeyush01/albert-paraphrase-detector-tokenizer')
|
| 75 |
|
| 76 |
+
def predict_paraphrase(sentence1, sentence2):
|
| 77 |
+
inputs = tokenizer(sentence1, sentence2, return_tensors="pt", padding=True, truncation=True)
|
| 78 |
+
with torch.no_grad():
|
| 79 |
+
outputs = model(**inputs)
|
| 80 |
+
logits = outputs.logits
|
| 81 |
+
probs = torch.softmax(logits, dim=1)
|
| 82 |
+
paraphrase_prob = probs[0][1].item()
|
| 83 |
+
return {"Paraphrase": paraphrase_prob, "Not Paraphrase": 1 - paraphrase_prob}
|
| 84 |
|
| 85 |
+
```
|
| 86 |
+
```python
|
| 87 |
+
import torch
|
| 88 |
|
| 89 |
+
pairs = [
|
| 90 |
+
("The movie was fantastic!", "The film was amazing!"),
|
| 91 |
+
("He is playing cricket.", "She is reading a book."),
|
| 92 |
+
]
|
| 93 |
|
| 94 |
+
for s1, s2 in pairs:
|
| 95 |
+
result = predict_paraphrase(s1, s2)
|
| 96 |
+
print(f"Sentence 1: {s1}")
|
| 97 |
+
print(f"Sentence 2: {s2}")
|
| 98 |
+
print(f"Result: {result}\n")
|
| 99 |
|
| 100 |
+
```
|
| 101 |
|
| 102 |
+
## Training Details
|
| 103 |
|
| 104 |
+
### Training Data
|
| 105 |
+
- **Dataset:** [GLUE MRPC](https://huggingface.co/datasets/glue/viewer/mrpc)
|
| 106 |
+
- **Description:** The Microsoft Research Paraphrase Corpus (MRPC) contains pairs of sentences automatically extracted from online news sources, with human annotations indicating whether each pair captures a paraphrase/semantic equivalence relationship.
|
| 107 |
+
- **Size:** ~3,700 training pairs, 408 validation pairs, 1,725 test pairs.
|
| 108 |
+
- **Labels:**
|
| 109 |
+
- `1` → Paraphrase (semantically equivalent)
|
| 110 |
+
- `0` → Not paraphrase
|
| 111 |
|
| 112 |
+
### Training Procedure
|
| 113 |
|
| 114 |
+
#### Preprocessing
|
| 115 |
+
- Both sentences were tokenized using **AlbertTokenizer** with truncation and padding (`max_length`).
|
| 116 |
+
- Columns `sentence1`, `sentence2`, and `idx` were dropped.
|
| 117 |
+
- The label column was renamed from `label` → `labels`.
|
| 118 |
+
- Dataset was set in **PyTorch format**.
|
| 119 |
|
| 120 |
#### Training Hyperparameters
|
| 121 |
+
- **Base model:** `albert-base-v2`
|
| 122 |
+
- **Epochs:** 3
|
| 123 |
+
- **Batch size:** 16 (train and eval)
|
| 124 |
+
- **Optimizer:** AdamW (via Hugging Face `Trainer`)
|
| 125 |
+
- **Warmup steps:** 600
|
| 126 |
+
- **Weight decay:** 0.01
|
| 127 |
+
- **Evaluation strategy:** Per epoch
|
| 128 |
+
- **Precision regime:** FP32
|
| 129 |
+
|
| 130 |
+
#### Speeds, Sizes, Times
|
| 131 |
+
- Training performed with Hugging Face `Trainer`.
|
| 132 |
+
- Training time: ~20–30 mins on a single GPU (Tesla T4); longer on CPU.
|
| 133 |
+
- Final checkpoint size: ~47 MB.
|
| 134 |
|
| 135 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
## Evaluation
|
| 138 |
|
|
|
|
|
|
|
| 139 |
### Testing Data, Factors & Metrics
|
| 140 |
|
| 141 |
#### Testing Data
|
| 142 |
+
- Evaluation performed on the **GLUE MRPC validation set** (~408 examples).
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
#### Factors
|
| 145 |
+
- Sentence pairs vary in length, syntactic complexity, and semantic overlap.
|
| 146 |
+
- Evaluation primarily captures **semantic similarity** in short news-style English text.
|
|
|
|
|
|
|
| 147 |
|
| 148 |
#### Metrics
|
| 149 |
+
- **Accuracy**: percentage of correctly classified sentence pairs.
|
| 150 |
+
- **F1 Score**: harmonic mean of precision and recall, important due to class imbalance.
|
|
|
|
|
|
|
| 151 |
|
| 152 |
### Results
|
| 153 |
+
(Expected range for ALBERT-base on MRPC — please replace with your actual run metrics if available)
|
| 154 |
+
- **Accuracy:** ~86–88%
|
| 155 |
+
- **F1 Score:** ~89–91%
|
| 156 |
|
| 157 |
#### Summary
|
| 158 |
+
The fine-tuned ALBERT model achieves strong performance on the MRPC benchmark, demonstrating effectiveness at capturing semantic similarity and paraphrase relationships between sentence pairs.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|