Coder Social home page Coder Social logo

kogpt2's Introduction


KoGPT2 (한국어 GPT-2)

Why'?'

  • OpenAI GPT-2 모델의 한국어 성능 한계

Model

  • GPT-2 base 모델
GPT2Model(units=768,
    max_length=1024,
    num_heads=12,
    num_layers=12,
    dropout=0.1,
    vocab_size=50000)
  • Fused GELU를 기반으로 10% 이상의 학습 및 추론 속도 향상

Tokenizer

  • 2천 5백만 이상의 문장으로 학습(wiki + news)
  • BPE(Byte Pair Encoding)
  • 50,000 토큰

Data

Data # of Sentences # of Words
Korean Wiki 5M 54M
Korean News 120M 1.6B
Other corpus 9.4M, 18M 88M, 82M
  • 원시 문장 (Raw text) 기준 약 20GB의 데이터 사용

Training

  • 이 작업은 아래 세 팀과의 협업으로 진행되었습니다.
    • SKT Conv.AI팀 : 대규모 언어모델 학습 로직 구현
    • Amazon Machine Learning Solutions Lab팀 : 대규모 분산 학습 인프라 구성
    • GluonNLP팀 : 학습 퍼포먼스 개선

How to install

git clone https://github.com/SKT-AI/KoGPT2.git
cd KoGPT2
pip install -r requirements.txt
pip install .
Requirements
  • Python >= 3.6
  • PyTorch >= 1.4.0
  • MXNet >= 1.6.0
  • gluonnlp >= 0.8.3
  • sentencepiece >= 0.1.6
  • transformers >= 2.1.1

pip으로 패키지 설치시 MXNet < 1.6.0 버전이 설치될 경우 아래 명령어로 1.6.0 이상의 MXNet을 설치한다.

pip install --pre mxnet

How to use

PyTorch

  • 2019년 한해를 보내며,로 문장을 생성해내는 간단한 예제
import torch
from kogpt2.pytorch_kogpt2 import get_pytorch_kogpt2_model
from gluonnlp.data import SentencepieceTokenizer
from kogpt2.utils import get_tokenizer

tok_path = get_tokenizer()
model, vocab = get_pytorch_kogpt2_model()
tok = SentencepieceTokenizer(tok_path)
sent = '2019년 한해를 보내며,'
toked = tok(sent)
while 1:
  input_ids = torch.tensor([vocab[vocab.bos_token],]  + vocab[toked]).unsqueeze(0)
  pred = model(input_ids)[0]
  gen = vocab.to_tokens(torch.argmax(pred, axis=-1).squeeze().tolist())[-1]
  if gen == '</s>':
      break
  sent += gen.replace('▁', ' ')
  toked = tok(sent)
sent
'2019년 한해를 보내며, 새해에는 더 많은 사람들이 새해에 이루고자 하는 소망과 희망을 되새겨보는 시간이 되었으면 좋겠다.'

model은 디폴트로 eval()모드로 리턴됨, 따라서 학습 용도로 사용시 model.train()명령을 통해 학습 모드로 변경할 필요가 있다.

MXNet-Gluon

import mxnet as mx
from kogpt2.mxnet_kogpt2 import get_mxnet_kogpt2_model
from gluonnlp.data import SentencepieceTokenizer
from kogpt2.utils import get_tokenizer

tok_path = get_tokenizer()
model, vocab = get_mxnet_kogpt2_model()
tok = SentencepieceTokenizer(tok_path)
sent = '2019년 한해를 보내며,'
toked = tok(sent)
while 1:
  input_ids = mx.nd.array([vocab[vocab.bos_token]]  + vocab[toked]).expand_dims(axis=0)
  pred = model(input_ids)[0]
  gen = vocab.to_tokens(mx.nd.argmax(pred, axis=-1).squeeze().astype('int').asnumpy().tolist())[-1]
  if gen == '</s>':
    break
  sent += gen.replace('▁', ' ')
  toked = tok(sent)
sent
'2019년 한해를 보내며, 새해에는 더 많은 사람들이 새해에 이루고자 하는 소망과 희망을 되새겨보는 시간이 되었으면 좋겠다.'

Demo

KoGPT2-Explorer

링크

Subtask Evaluations

Sentimemt Analysis

NSMC 데이터

Model Test Accuracy
BERT base multilingual cased 0.875
KoBERT 0.901
KoGPT2 0.899

Paraphrase Detection

한국어 Paraphrase Detection 데이터

Model Test Accuracy
KoBERT 0.911
KoGPT2 0.943

Contacts

KoGPT2 관련 이슈는 이곳에 올려주세요.

License

KoGPT2modified MIT 라이선스 하에 공개되어 있습니다. 모델 및 코드를 사용할 경우 라이선스 내용을 준수해주세요. 라이선스 전문은 LICENSE 파일에서 확인하실 수 있습니다.

kogpt2's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.