Views
No views yet
1from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
3model_checkpoint = "ahlad/t5-small-finetuned-samsum"
4tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
5model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)
6
7input_text = """
8Emma: Did you finish the book I lent you?
9Liam: Yes, I couldn’t put it down! The twist at the end was insane.
10Emma: I know, right? I didn’t see it coming at all. What did you think of the main character?
11Liam: Honestly, I thought they were a bit frustrating at first, but they grew on me.
12Emma: Same here. I loved how they developed by the end. Are you up for another book from the series?
13Liam: Absolutely! Pass it my way.
14"""
15
16inputs = tokenizer(input_text, return_tensors="pt")
17
18outputs = model.generate(**inputs)
19summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
20
21print("Summary:", summary)