ccdv/cnn_dailymail
Updated • 38.8k • 32
How to use BEASTBOYJAY/my-fine-tuned-summarizer with Transformers:
# Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("BEASTBOYJAY/my-fine-tuned-summarizer")
model = AutoModelForSeq2SeqLM.from_pretrained("BEASTBOYJAY/my-fine-tuned-summarizer")This is the model is used for making or generating summary of the provided paragraph.
This model is fine-tuned on very small dataset can need more fine-tuning for better results.(Fine-tuned this model only for eductional purposes)
Use the code below to get started with the model.
from transformers import EncoderDecoderModel, BertTokenizer
class TextSummarizer:
def __init__(self, model_path, tokenizer_name="bert-base-uncased"):
self.tokenizer = BertTokenizer.from_pretrained(tokenizer_name)
self.model = EncoderDecoderModel.from_pretrained(model_path)
def summarize(self, text, max_input_length=512):
inputs = self.tokenizer(
text,
return_tensors="pt",
truncation=True,
padding="max_length",
max_length=max_input_length,
)
summary_ids = self.model.generate(
inputs["input_ids"],
attention_mask=inputs["attention_mask"],
decoder_start_token_id=self.tokenizer.cls_token_id,
max_length=128,
num_beams=4,
length_penalty=1.5,
no_repeat_ngram_size=1,
early_stopping=True,
)
summary = self.tokenizer.decode(summary_ids[0], skip_special_tokens=True)
return summary
if __name__ == "__main__":
summarizer = TextSummarizer(model_path="BEASTBOYJAY/my-fine-tuned-summarizer")
test_article = "Your article or paragraph"
summary = summarizer.summarize(test_article)
print("Generated Summary:", summary)
Base model
google-bert/bert-base-uncased