Views
No views yet
1model = AutoModelForSequenceClassification.from_pretrained('peeyush01/albert-paraphrase-detector')
2tokenizer = AutoTokenizer.from_pretrained('peeyush01/albert-paraphrase-detector-tokenizer')
3
4def predict_paraphrase(sentence1, sentence2):
5 inputs = tokenizer(sentence1, sentence2, return_tensors="pt", padding=True, truncation=True)
6 with torch.no_grad():
7 outputs = model(**inputs)
8 logits = outputs.logits
9 probs = torch.softmax(logits, dim=1)
10 paraphrase_prob = probs[0][1].item()
11 return {"Paraphrase": paraphrase_prob, "Not Paraphrase": 1 - paraphrase_prob}
121import torch
2
3pairs = [
4 ("The movie was fantastic!", "The film was amazing!"),
5 ("He is playing cricket.", "She is reading a book."),
6]
7
8for s1, s2 in pairs:
9 result = predict_paraphrase(s1, s2)
10 print(f"Sentence 1: {s1}")
11 print(f"Sentence 2: {s2}")
12 print(f"Result: {result}\n")
131 → Paraphrase (semantically equivalent)0 → Not paraphrasemax_length).sentence1, sentence2, and idx were dropped.label → labels.albert-base-v2Trainer)Trainer.