sanjeev-bhandari01/nepali-summarization-dataset
Viewer • Updated • 286k • 103 • 2
How to use Dragneel/nepali-article-title-generator with Transformers:
# Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("Dragneel/nepali-article-title-generator")
model = AutoModelForSeq2SeqLM.from_pretrained("Dragneel/nepali-article-title-generator")This is a fine-tuned MBart model for generating titles (summaries) for Nepali articles. The model was fine-tuned on a Nepali summarization dataset and is designed to generate concise and relevant titles for given Nepali text.
ne_NP)You can use this model to generate titles for Nepali articles. Below is an example of how to load and use the model.
First, install the required libraries:
pip install torch transformers
import torch
from transformers import MBartTokenizer, MBartForConditionalGeneration
# Load the fine-tuned model
MODEL_PATH = "Dragneel/nepali-article-title-generator"
model = MBartForConditionalGeneration.from_pretrained(MODEL_PATH)
tokenizer = MBartTokenizer.from_pretrained(MODEL_PATH)
# Set the source and target language
tokenizer.src_lang = "ne_NP"
tokenizer.tgt_lang = "ne_NP"
# Define the input text
input_text = """
नेपालको पर्यटन उद्योगमा कोरोनाको प्रभावले गर्दा ठूलो मन्दी आएको छ।
विश्वभर यात्रा प्रतिबन्ध लागू भएपछि नेपाल आउने पर्यटकको संख्या न्यून भएको छ।
यसले गर्दा होटल, यातायात र अन्य पर्यटन सम्बन्धी व्यवसायमा ठूलो असर परेको छ।
सरकारले पर्यटन उद्योगलाई बचाउन विभिन्न उपायहरू ल्याएको छ, तर अहिलेसम्म कुनै ठूलो सुधार देखिएको छैन।
"""
# Tokenize the input
inputs = tokenizer(
input_text,
return_tensors="pt",
max_length=512,
truncation=True,
padding="max_length"
)
# Generate summary
model.eval() # Set the model to evaluation mode
with torch.no_grad():
output_ids = model.generate(
inputs["input_ids"],
max_length=128, # Set the maximum length of the generated text
num_beams=4, # Beam search for better quality
early_stopping=True
)
# Decode the generated text
summary = tokenizer.decode(output_ids[0], skip_special_tokens=True)
print("Generated Title:", summary)
Base model
facebook/mbart-large-cc25