File size: 12,705 Bytes
413de8f
 
 
 
 
 
 
 
 
 
f33486d
442879a
f33486d
 
8af9656
 
 
f33486d
413de8f
 
 
 
 
 
 
 
d3f1e50
4652695
d3f1e50
e5cbd9e
413de8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e5cbd9e
413de8f
 
e5cbd9e
413de8f
 
 
 
 
f14dba2
 
413de8f
 
 
 
fc3331d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413de8f
 
442879a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413de8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
---
pipeline_tag: summarization
language:
- ko
tags:
- T5
---

# t5-base-korean-summarization

This is [T5](https://huggingface.co/docs/transformers/model_doc/t5) model for korean text summarization.
Finetuned based on ['paust/pko-t5-base'](https://huggingface.co/paust/pko-t5-base) model.
Finetuned with 3 datasets. Specifically, it is described below.

- [Korean Paper Summarization Dataset(λ…Όλ¬Έμžλ£Œ μš”μ•½)](https://www.aihub.or.kr/aihubdata/data/view.do?currMenu=115&topMenu=100&aihubDataSe=realm&dataSetSn=90)
- [Korean Book Summarization Dataset(λ„μ„œμžλ£Œ μš”μ•½)](https://www.aihub.or.kr/aihubdata/data/view.do?currMenu=115&topMenu=100&aihubDataSe=realm&dataSetSn=93)
- [Korean Summary statement and Report Generation Dataset(μš”μ•½λ¬Έ 및 레포트 생성 데이터)](https://www.aihub.or.kr/aihubdata/data/view.do?currMenu=115&topMenu=100&aihubDataSe=realm&dataSetSn=90)


# Usage (HuggingFace Transformers)

```python
import nltk
nltk.download('punkt')
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

model = AutoModelForSeq2SeqLM.from_pretrained('eenzeenee/t5-base-korean-summarization')
tokenizer = AutoTokenizer.from_pretrained('eenzeenee/t5-base-korean-summarization')

prefix = "summarize: "
sample = """
    μ•ˆλ…•ν•˜μ„Έμš”? 우리 (2ν•™λ…„)/(이 ν•™λ…„) μΉœκ΅¬λ“€ 우리 μΉœκ΅¬λ“€ 학ꡐ에 κ°€μ„œ μ§„μ§œ (2ν•™λ…„)/(이 ν•™λ…„) 이 되고 μ‹Άμ—ˆλŠ”λ° 학ꡐ에 λͺ» κ°€κ³  μžˆμ–΄μ„œ λ‹΅λ‹΅ν•˜μ£ ? 
    κ·Έλž˜λ„ 우리 μΉœκ΅¬λ“€μ˜ μ•ˆμ „κ³Ό 건강이 μ΅œμš°μ„ μ΄λ‹ˆκΉŒμš” μ˜€λŠ˜λΆ€ν„° μ„ μƒλ‹˜μ΄λž‘ 맀일 맀일 κ΅­μ–΄ 여행을 λ– λ‚˜λ³΄λ„λ‘ ν•΄μš”. 
    μ–΄/ μ‹œκ°„μ΄ 벌써 μ΄λ ‡κ²Œ λλ‚˜μš”? λŠ¦μ—ˆμ–΄μš”. λŠ¦μ—ˆμ–΄μš”. 빨리 κ΅­μ–΄ 여행을 λ– λ‚˜μ•Ό λΌμš”. 
    그런데 μ–΄/ ꡭ어여행을 λ– λ‚˜κΈ° 전에 μš°λ¦¬κ°€ 쀀비물을 챙겨야 되겠죠? κ΅­μ–΄ 여행을 λ– λ‚  μ€€λΉ„λ¬Ό, κ΅μ•ˆμ„ μ–΄λ–»κ²Œ 받을 수 μžˆλŠ”μ§€ μ„ μƒλ‹˜μ΄ μ„€λͺ…을 ν•΄μ€„κ²Œμš”. 
    (EBS)/(μ΄λΉ„μ—μŠ€) μ΄ˆλ“±μ„ κ²€μƒ‰ν•΄μ„œ λ“€μ–΄κ°€λ©΄μš” 첫화면이 μ΄λ ‡κ²Œ λ‚˜μ™€μš”. 
    자/ κ·ΈλŸ¬λ©΄μš” μ—¬κΈ° (X)/(μ—‘μŠ€) 눌러주(κ³ μš”)/(κ΅¬μš”). μ €κΈ° (동그라미)/(λ˜₯그라미) (EBS)/(μ΄λΉ„μ—μŠ€) (2μ£Ό)/(이 μ£Ό) λΌμ΄λΈŒνŠΉκ°•μ΄λΌκ³  λ˜μ–΄μžˆμ£ ? 
    κ±°κΈ°λ₯Ό λ°”λ‘œ κ°€κΈ°λ₯Ό λˆ„λ¦…λ‹ˆλ‹€. 자/ (λˆ„λ₯΄λ©΄μš”)/(눌λ₯΄λ©΄μš”). μ–΄λ–»κ²Œ λ˜λƒ? b/ λ°‘μœΌλ‘œ λ‚΄λ €μš” λ‚΄λ €μš” λ‚΄λ €μš” μ­‰ λ‚΄λ €μš”. 
    우리 λͺ‡ 학년이죠? μ•„/ (2ν•™λ…„)/(이 ν•™λ…„) 이죠 (2ν•™λ…„)/(이 ν•™λ…„)의 무슨 κ³Όλͺ©? κ΅­μ–΄. 
    μ΄λ²ˆμ£ΌλŠ” (1μ£Ό)/(일 μ£Ό) μ°¨λ‹ˆκΉŒμš” μ—¬κΈ° κ΅μ•ˆ. λ‹€μŒμ£ΌλŠ” μ—¬κΈ°μ„œ λ‹€μš΄μ„ λ°›μœΌλ©΄ λΌμš”. 
    이 κ΅μ•ˆμ„ 클릭을 ν•˜λ©΄, μ§œμž”/. μ΄λ ‡κ²Œ κ΅μž¬κ°€ λ‚˜μ˜΅λ‹ˆλ‹€ .이 κ΅μ•ˆμ„ (λ‹€μš΄)/(λ”°μš΄)λ°›μ•„μ„œ 우리 ꡭ어여행을 λ– λ‚  μˆ˜κ°€ μžˆμ–΄μš”. 
    그럼 우리 μ§„μ§œλ‘œ κ΅­μ–΄ 여행을 ν•œλ²ˆ λ– λ‚˜λ³΄λ„λ‘ ν•΄μš”? κ΅­μ–΄μ—¬ν–‰ 좜발. 자/ (1단원)/(일 단원) 제λͺ©μ΄ λ­”κ°€μš”? ν•œλ²ˆ μ°Ύμ•„λ΄μš”. 
    μ‹œλ₯Ό μ¦κ²¨μš” μ—μš”. κ·Έλƒ₯ μ‹œλ₯Ό μ½μ–΄μš” κ°€ μ•„λ‹ˆμ—μš”. μ‹œλ₯Ό 즐겨야 λΌμš” 즐겨야 돼. μ–΄λ–»κ²Œ 즐길까? 일단은 λ‚΄λ‚΄ μ‹œλ₯Ό μ¦κΈ°λŠ” 방법에 λŒ€ν•΄μ„œ 곡뢀λ₯Ό ν•  κ±΄λ°μš”. 
    그럼 μ˜€λŠ˜μ€μš” μ–΄λ–»κ²Œ μ¦κΈΈκΉŒμš”? 였늘 곡뢀할 λ‚΄μš©μ€μš” μ‹œλ₯Ό μ—¬λŸ¬ 가지 λ°©λ²•μœΌλ‘œ 읽기λ₯Ό κ³΅λΆ€ν• κ²λ‹ˆλ‹€. 
    μ–΄λ–»κ²Œ μ—¬λŸ¬κ°€μ§€ λ°©λ²•μœΌλ‘œ μ½μ„κΉŒ 우리 곡뢀해 보도둝 ν•΄μš”. 였늘의 μ‹œ λ‚˜μ™€λΌ μ§œμž”/! μ‹œκ°€ λ‚˜μ™”μŠ΅λ‹ˆλ‹€ μ‹œμ˜ 제λͺ©μ΄ λ­”κ°€μš”? λ‹€νˆ° λ‚ μ΄μ—μš” λ‹€νˆ° λ‚ . 
    λˆ„κ΅¬λž‘ λ‹€ν‰œλ‚˜ λ™μƒμ΄λž‘ λ‹€ν‰œλ‚˜ μ–Έλ‹ˆλž‘ μΉœκ΅¬λž‘? λˆ„κ΅¬λž‘ λ‹€ν‰œλŠ”μ§€ μ„ μƒλ‹˜μ΄ μ‹œλ₯Ό 읽어 쀄 ν…Œλ‹ˆκΉŒ ν•œλ²ˆ 생각을 해보도둝 ν•΄μš”."""

inputs = [prefix + sample]


inputs = tokenizer(inputs, max_length=512, truncation=True, return_tensors="pt")
output = model.generate(**inputs, num_beams=3, do_sample=True, min_length=10, max_length=64)
decoded_output = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
result = nltk.sent_tokenize(decoded_output.strip())[0]

print('RESULT >>', result)

RESULT >> κ΅­μ–΄ 여행을 λ– λ‚˜κΈ° 전에 κ΅­μ–΄ 여행을 λ– λ‚  μ€€λΉ„λ¬Όκ³Ό κ΅μ•ˆμ„ μ–΄λ–»κ²Œ 받을 수 μžˆλŠ”μ§€ μ„ μƒλ‹˜μ΄ μ„€λͺ…ν•΄ μ€€λ‹€.
```

# Evalutation Result

- Korean Paper Summarization Dataset(λ…Όλ¬Έμžλ£Œ μš”μ•½)
  ```
  ROUGE-2-R 0.09868624890432466
  ROUGE-2-P 0.9666714545849712
  ROUGE-2-F 0.17250881441169427
  ```
- Korean Book Summarization Dataset(λ„μ„œμžλ£Œ μš”μ•½)
  ```
  ROUGE-2-R 0.1575686156943213
  ROUGE-2-P 0.9718318136896944
  ROUGE-2-F 0.26548116834852586
  ```
- Korean Summary statement and Report Generation Dataset(μš”μ•½λ¬Έ 및 레포트 생성 데이터)
  ```
  ROUGE-2-R 0.0987891733555808
  ROUGE-2-P 0.9276946867981899
  ROUGE-2-F 0.17726493110448185
  ```


# Training

The model was trained with the parameters:

### training arguments
```
Seq2SeqTrainingArguments(
    per_device_train_batch_size=8,
    per_device_eval_batch_size=8,
    auto_find_batch_size=False,
    weight_decay=0.01,
    learning_rate=4e-05,
    lr_scheduler_type=linear,
    num_train_epochs=3,
    fp16=True)
```


# Model Architecture

```
T5ForConditionalGeneration(                                                                                                                                             
  (shared): Embedding(50358, 768)                                                                                                                                       
  (encoder): T5Stack(                                                                                                                                                   
    (embed_tokens): Embedding(50358, 768)                                                                                                                               
    (block): ModuleList(                                                                                                                                                
      (0): T5Block(                                                                                                                                                     
        (layer): ModuleList(                                                                                                                                            
          (0): T5LayerSelfAttention(                                                                                                                                    
            (SelfAttention): T5Attention(                                                                                                                               
              (q): Linear(in_features=768, out_features=768, bias=False)
              (k): Linear(in_features=768, out_features=768, bias=False)
              (v): Linear(in_features=768, out_features=768, bias=False)
              (o): Linear(in_features=768, out_features=768, bias=False)
              (relative_attention_bias): Embedding(32, 12)
            )        
            (layer_norm): T5LayerNorm()  
            (dropout): Dropout(p=0.1, inplace=False)
          )        
          (1): T5LayerFF(   
            (DenseReluDense): T5DenseGatedActDense(
              (wi_0): Linear(in_features=768, out_features=2048, bias=False)
              (wi_1): Linear(in_features=768, out_features=2048, bias=False)
              (wo): Linear(in_features=2048, out_features=768, bias=False)
              (dropout): Dropout(p=0.1, inplace=False)
              (act): NewGELUActivation()
            )
            (layer_norm): T5LayerNorm()
            (dropout): Dropout(p=0.1, inplace=False)
          )
        )
      )
      (1~11): T5Block(
        (layer): ModuleList(
          (0): T5LayerSelfAttention(
            (SelfAttention): T5Attention(
              (q): Linear(in_features=768, out_features=768, bias=False)
              (k): Linear(in_features=768, out_features=768, bias=False)
              (v): Linear(in_features=768, out_features=768, bias=False)
              (o): Linear(in_features=768, out_features=768, bias=False)
            )
            (layer_norm): T5LayerNorm()
            (dropout): Dropout(p=0.1, inplace=False)
          )
          (1): T5LayerFF(
            (DenseReluDense): T5DenseGatedActDense(
              (wi_0): Linear(in_features=768, out_features=2048, bias=False)
              (wi_1): Linear(in_features=768, out_features=2048, bias=False)
              (wo): Linear(in_features=2048, out_features=768, bias=False)
              (dropout): Dropout(p=0.1, inplace=False)
              (act): NewGELUActivation()
            )
            (layer_norm): T5LayerNorm()
            (dropout): Dropout(p=0.1, inplace=False)
          )
        )
      )
    )
    (final_layer_norm): T5LayerNorm()
    (dropout): Dropout(p=0.1, inplace=False)
  )
  (decoder): T5Stack(
    (embed_tokens): Embedding(50358, 768)
    (block): ModuleList(
      (0): T5Block(
        (layer): ModuleList(
          (0): T5LayerSelfAttention(
            (SelfAttention): T5Attention(
              (q): Linear(in_features=768, out_features=768, bias=False)
              (k): Linear(in_features=768, out_features=768, bias=False)
              (v): Linear(in_features=768, out_features=768, bias=False)
              (o): Linear(in_features=768, out_features=768, bias=False)
              (relative_attention_bias): Embedding(32, 12)
            )
            (layer_norm): T5LayerNorm()
            (dropout): Dropout(p=0.1, inplace=False)
          )
          (1): T5LayerCrossAttention(
            (EncDecAttention): T5Attention(
              (q): Linear(in_features=768, out_features=768, bias=False)
              (k): Linear(in_features=768, out_features=768, bias=False)
              (v): Linear(in_features=768, out_features=768, bias=False)
              (o): Linear(in_features=768, out_features=768, bias=False)
            )
            (layer_norm): T5LayerNorm()
            (dropout): Dropout(p=0.1, inplace=False)
          )
          (2): T5LayerFF(
            (DenseReluDense): T5DenseGatedActDense(
              (wi_0): Linear(in_features=768, out_features=2048, bias=False)
              (wi_1): Linear(in_features=768, out_features=2048, bias=False)
              (wo): Linear(in_features=2048, out_features=768, bias=False)
              (dropout): Dropout(p=0.1, inplace=False)
              (act): NewGELUActivation()
            )
            (layer_norm): T5LayerNorm()
            (dropout): Dropout(p=0.1, inplace=False)
          )
        )
      )
      (1~11): T5Block(
        (layer): ModuleList(
          (0): T5LayerSelfAttention(
            (SelfAttention): T5Attention(
              (q): Linear(in_features=768, out_features=768, bias=False)
              (k): Linear(in_features=768, out_features=768, bias=False)
              (v): Linear(in_features=768, out_features=768, bias=False)
              (o): Linear(in_features=768, out_features=768, bias=False)
            )
            (layer_norm): T5LayerNorm()
            (dropout): Dropout(p=0.1, inplace=False)
          )
          (1): T5LayerCrossAttention(
            (EncDecAttention): T5Attention(
              (q): Linear(in_features=768, out_features=768, bias=False)
              (k): Linear(in_features=768, out_features=768, bias=False)
              (v): Linear(in_features=768, out_features=768, bias=False)
              (o): Linear(in_features=768, out_features=768, bias=False)
            )
            (layer_norm): T5LayerNorm()
            (dropout): Dropout(p=0.1, inplace=False)
          )
          (2): T5LayerFF(
            (DenseReluDense): T5DenseGatedActDense(
              (wi_0): Linear(in_features=768, out_features=2048, bias=False)
              (wi_1): Linear(in_features=768, out_features=2048, bias=False)
              (wo): Linear(in_features=2048, out_features=768, bias=False)
              (dropout): Dropout(p=0.1, inplace=False)
              (act): NewGELUActivation()
            )
            (layer_norm): T5LayerNorm()
            (dropout): Dropout(p=0.1, inplace=False)
          )
        )
      )
      (final_layer_norm): T5LayerNorm()                              
    (dropout): Dropout(p=0.1, inplace=False)                                                                                           
  )                                                                
  (lm_head): Linear(in_features=768, out_features=50358, bias=False)                                                                   
)
```

## Citation

- Raffel, Colin, et al. "Exploring the limits of transfer learning with a unified text-to-text transformer." J. Mach. Learn. Res. 21.140 (2020): 1-67.