mahwizzzz/ur_para
Viewer • Updated • 393k • 2
How to use mahwizzzz/UrduParaphraseBERT with Transformers:
# Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("mahwizzzz/UrduParaphraseBERT")
model = AutoModelForSeq2SeqLM.from_pretrained("mahwizzzz/UrduParaphraseBERT")This repository contains a trained Urdu paraphrasing model based on the BERT-based encoder-decoder architecture. The model has been fine-tuned on the Urdu Paraphrase Dataset and can generate paraphrases for given input sentences in Urdu.
The model is built using the Hugging Face Transformers library and is trained on the BERT-base-uncased model. It employs an encoder-decoder architecture where the BERT model serves as the encoder, and another BERT model is used as the decoder. The model is trained to generate paraphrases by reconstructing the input sentences.
To use the trained model for paraphrasing Urdu sentences, you can follow the steps below:
from transformers import EncoderDecoderModel, BertTokenizer
# Load the model and tokenizer
model = EncoderDecoderModel.from_pretrained("mwz/UrduParaphraseBERT")
tokenizer = BertTokenizer.from_pretrained("mwz/UrduParaphraseBERT")
def paraphrase_urdu_sentence(sentence):
input_ids = tokenizer.encode(sentence, padding="longest", truncation=True, max_length=512, return_tensors="pt")
generated_ids = model.generate(input_ids=input_ids, max_length=128, num_beams=4, no_repeat_ngram_size=2)
paraphrase = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
return paraphrase
sentence = "ایک مثالی روشنی کا مشہور نقطہ آبادی چھوٹی چھوٹی سڑکوں میں اپنے آپ کو خوشگوار کرسکتی ہے۔"
paraphrased_sentence = paraphrase_urdu_sentence(sentence)
print(paraphrased_sentence)