haven-jeon
Update license
9812bd8
|
raw
history blame
1.03 kB
metadata
language: ko
tags:
  - bart
license: mit

Korean News Summarization Model

How to use

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]