Sentence Similarity
Transformers
English
code
peeyush01 commited on
Commit
3bef288
·
verified ·
1 Parent(s): 9b82df6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +24 -6
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
- from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
74
 
75
- sim_model = pipeline("text-classification", model="your-username/albert-paraphrase-similarity")
 
 
 
 
 
 
 
76
 
77
- sentence1 = "The car crashed into the wall."
78
- sentence2 = "The vehicle hit the barrier."
 
 
 
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