File size: 1,027 Bytes
1ce9016
 
 
 
9812bd8
1ce9016
 
 
 
 
 
 
23dfd9c
1ce9016
 
 
6b2ed56
e148262
1ce9016
 
 
 
 
 
fb0078b
1ce9016
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
language: ko
tags:
- bart
license: mit
---

# Korean News Summarization Model

## How to use

```python
import torch
from transformers import PreTrainedTokenizerFast
from transformers import BartForConditionalGeneration

tokenizer = PreTrainedTokenizerFast.from_pretrained(
    'gogamza/kobart-summarization')

model = BartForConditionalGeneration.from_pretrained('gogamza/kobart-summarization')

text = "과거를 떠올려보자. 방송을 보던 우리의 모습을..."

raw_input_ids = tokenizer.encode(text)
input_ids = [tokenizer.bos_token_id] + \\
    raw_input_ids + [tokenizer.eos_token_id]
summary_ids = model.generate(torch.tensor([input_ids]),
                                max_length=150,
                                early_stopping=False,
                                num_beams=5,
                                repetition_penalty=1.0,
                                eos_token_id=tokenizer.eos_token_id)
summ_text = tokenizer.batch_decode(summary_ids.tolist(), skip_special_tokens=True)[0]
```