Views
No views yet
google/flan-t5-base| Style | Prefix | Description |
|---|---|---|
| Harsh | summarize harsh: | Very concise (~30% of original length) |
| Standard | summarize standard: | Balanced (~50–60%) |
| Detailed | summarize detailed: | More comprehensive (~80%) |
1from transformers import T5Tokenizer, T5ForConditionalGeneration
2
3model_name = "Hiratax/t5-base-finetuned-summarizer"
4tokenizer = T5Tokenizer.from_pretrained(model_name)
5model = T5ForConditionalGeneration.from_pretrained(model_name)
6
7input_text = """
8Russian President Vladimir Putin said that a US plan to end the war in Ukraine could
9“form the basis for future agreements” but renewed threats to seize more territory...
10"""
11
12# Add style prefix
13prefix = "summarize standard: "
14inputs = tokenizer(prefix + input_text, return_tensors="pt", max_length=512, truncation=True)
15
16outputs = model.generate(
17 inputs["input_ids"],
18 max_length=150,
19 num_beams=4,
20 length_penalty=1.0,
21 early_stopping=True
22)
23
24summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
25print(summary)summary_length / original_lengthApache 2.0