File size: 855 Bytes
47175ce
 
 
2b0a569
 
 
 
 
 
47175ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
This model bases on T5-base model, finetuned using bbc-news-summary dataset
Example of using:
    
    from transformers import pipeline, T5ForConditionalGeneration, T5Tokenizer
    import torch
    model_name = "Andrew0488/t5-summarizer"
    model = T5ForConditionalGeneration.from_pretrained(model_name).cuda()
    tokenizer = T5Tokenizer.from_pretrained(model_name)

    def t5_summary(text: str):
        inputs = tokenizer.encode(
            "summarize: " + text,
            return_tensors='pt',
            max_length=2000,
            truncation=True,
            padding='max_length'
        ).to(torch.device("cuda"))
 
        # Generate the summary
        summary_ids = model.generate(
            inputs,
            max_length=250,
            num_beams=5
        )
        return tokenizer.decode(summary_ids[0], skip_special_tokens=True)