Instructions to use peeyush01/albert-paraphrase-detector-tokenizer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use peeyush01/albert-paraphrase-detector-tokenizer with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("peeyush01/albert-paraphrase-detector-tokenizer", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -70,15 +70,33 @@ It can be used to determine whether two sentences are paraphrases (semantically
|
|
| 70 |
Example usage:
|
| 71 |
|
| 72 |
```python
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
result = sim_model({"text": sentence1, "text_pair": sentence2})
|
| 81 |
-
print(result)
|
| 82 |
```
|
| 83 |
|
| 84 |
## Training Details
|
|
|
|
| 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() # assuming label 1 = paraphrase
|
| 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
|