Update README.md
Browse files
README.md
CHANGED
@@ -32,4 +32,30 @@ To use the Urdu Paraphrase Generation Model, follow these steps:
|
|
32 |
1. Install the `transformers` library:
|
33 |
```bash
|
34 |
pip install transformers
|
35 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
1. Install the `transformers` library:
|
33 |
```bash
|
34 |
pip install transformers
|
35 |
+
```
|
36 |
+
2. Load the model and tokenizer in your Python script:
|
37 |
+
```
|
38 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer
|
39 |
+
|
40 |
+
# Load the model and tokenizer
|
41 |
+
model = AutoModelForMaskedLM.from_pretrained("urduhack/roberta-urdu-small")
|
42 |
+
tokenizer = AutoTokenizer.from_pretrained("urduhack/roberta-urdu-small")
|
43 |
+
```
|
44 |
+
## Generating Paraphrases
|
45 |
+
Use the following code snippet to generate paraphrases with the loaded model and tokenizer:
|
46 |
+
```
|
47 |
+
# Example sentence
|
48 |
+
input_sentence = "This is an example sentence."
|
49 |
+
|
50 |
+
# Tokenize the input sentence
|
51 |
+
inputs = tokenizer(input_sentence, truncation=True, padding=True, return_tensors="pt")
|
52 |
+
input_ids = inputs.input_ids.to(model.device)
|
53 |
+
attention_mask = inputs.attention_mask.to(model.device)
|
54 |
+
|
55 |
+
# Generate paraphrase
|
56 |
+
with torch.no_grad():
|
57 |
+
outputs = model.generate(input_ids, attention_mask=attention_mask, max_length=128)
|
58 |
+
|
59 |
+
paraphrase = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
60 |
+
print("Paraphrase:", paraphrase)
|
61 |
+
```
|