File size: 4,306 Bytes
46b47bd fd649c1 46b47bd fd649c1 46b47bd fd649c1 489bb01 46b47bd fd649c1 46b47bd fd649c1 46b47bd 4355d13 46b47bd 489bb01 46b47bd fd649c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
---
library_name: transformers
license: apache-2.0
base_model: bert-base-uncased
tags:
- paraphrase-detection
- sentence-pair-classification
- glue
- mrpc
metrics:
- accuracy
- f1
model-index:
- name: bert_paraphrase
results:
- task:
name: Paraphrase Detection
type: text-classification
dataset:
name: GLUE MRPC
type: glue
config: mrpc
split: validation
metrics:
- name: Accuracy
type: accuracy
value: 0.8676
- name: F1
type: f1
value: 0.9078
language:
- en
---
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->
# bert_paraphrase
This model is a fine-tuned version of [bert-base-uncased](https://huggingface.co/bert-base-uncased) on the **Microsoft Research Paraphrase Corpus (MRPC)**, a subset of the [GLUE benchmark](https://huggingface.co/datasets/glue).
It is trained to determine whether **two sentences are semantically equivalent (paraphrases) or not**.
## π Evaluation Results
- Loss: 0.4042
- Accuracy: 0.8676
- F1: 0.9078
## π§Ύ Model Description
- **Model type:** BERT-base (uncased)
- **Task:** Binary classification (paraphrase vs not paraphrase)
- **Languages:** English
- **Labels:**
- `0` β Not paraphrase
- `1` β Paraphrase
---
## β
Intended Uses & Limitations
## Intended uses & limitations
### Intended uses
- Detect if two sentences convey the same meaning.
- Useful for:
- Duplicate question detection (e.g., Quora, FAQ bots).
- Semantic similarity search.
- Improving information retrieval systems.
### Limitations
- Only trained on English (MRPC dataset).
- May not generalize well to other domains (e.g., legal, medical).
- Binary labels only (no "degree of similarity").
---
## π How to Use
You can use this model with the Hugging Face `pipeline` for quick inference:
```python
from transformers import pipeline
paraphrase_detector = pipeline(
"text-classification",
model="azherali/bert_paraphrase",
tokenizer="azherali/bert_paraphrase"
)
single_pair = [
{"text": "The car is red.", "text_pair": "The automobile is red."},
]
result = paraphrase_detector(single_pair)
print( result)
[{'label': 'paraphrase', 'score': 0.9801033139228821}]
# Test pairs
pairs = [
{"text": "The car is red.", "text_pair": "The automobile is red."},
{"text": "He enjoys playing football.", "text_pair": "She likes cooking."},
]
result = paraphrase_detector(pairs)
print( result)
[{'label': 'paraphrase', 'score': 0.9801033139228821}, {'label': 'not_paraphrase', 'score': 0.9302119016647339}]
```
Using AutoModel & AutoTokenizer:
```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
tokenizer = AutoTokenizer.from_pretrained("azherali/bert_paraphrase")
model = AutoModelForSequenceClassification.from_pretrained("azherali/bert_paraphrase")
# Example sentences
sent1 = "The quick brown fox jumps over the lazy dog."
sent2 = "A fast brown fox leaps over a lazy dog."
inputs = tokenizer(sent1, sent2, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
predicted_class = torch.argmax(logits, dim=1).item()
print("Prediction:", model.config.id2label[predicted_class])
Prediction: paraphrase
```
## Training and evaluation data
More information needed
## Training procedure
### Training hyperparameters
The following hyperparameters were used during training:
- learning_rate: 2e-05
- train_batch_size: 16
- eval_batch_size: 16
- seed: 42
- optimizer: Use OptimizerNames.ADAMW_TORCH_FUSED with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
- lr_scheduler_type: linear
- num_epochs: 3
### Training results
| Training Loss | Epoch | Step | Validation Loss | Accuracy | F1 |
|:-------------:|:-----:|:----:|:---------------:|:--------:|:------:|
| No log | 1.0 | 230 | 0.3894 | 0.8309 | 0.8836 |
| No log | 2.0 | 460 | 0.3511 | 0.8505 | 0.8964 |
| 0.4061 | 3.0 | 690 | 0.4042 | 0.8676 | 0.9078 |
### Framework versions
- Transformers 4.55.2
- Pytorch 2.8.0+cu126
- Datasets 4.0.0
- Tokenizers 0.21.4 |