언어 모델을 위한 전이 학습

Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)

David Cecchini

Data Scientist

전이 학습의 핵심 아이디어

전이 학습:

  • 무작위보다 나은 초기 가중치로 시작
  • 매우 큰 데이터셋으로 학습된 모델 사용
  • 오픈 소스 데이터 사이언스 모델 활용
Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)

사용 가능한 아키텍처

기본 예: I really loved this movie

  • Word2Vec
    • 연속 보낭(CBOW) X = [I, really, this, movie], y = loved
    • 스킵그램 X = loved, y = [I, really, this, movie]
  • FastText X = [I, rea, eal, all, lly, really, ...], y = loved
    • 단어와 문자 n-그램 사용
  • ELMo X = [I, really, loved, this], y = movie
    • 문맥별 임베딩 사용
    • 심층 양방향 언어 모델(biLM) 사용
  • Word2Vec과 FastText는 gensim, ELMo는 tensorflow_hub에서 제공
Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)

Word2Vec 예시

from gensim.models import word2vec

# Train the model w2v_model = word2vec.Word2Vec(tokenized_corpus, size=embedding_dim, window=neighbor_words_num, iter=100)
# Get top 3 similar words to "captain" w2v_model.wv.most_similar(["captain"], topn=3)
[('sweatpants', 0.7249663472175598),
('kirk', 0.7083336114883423),
('larry', 0.6495886445045471)]
Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)

FastText 예시

from gensim.models import fasttext

# Instantiate the model ft_model = fasttext.FastText(size=embedding_dim, window=neighbor_words_num)
# Build vocabulary ft_model.build_vocab(sentences=tokenized_corpus)
# Train the model ft_model.train(sentences=tokenized_corpus, total_examples=len(tokenized_corpus), epochs=100)
Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)

연습해 봅시다!

Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)

Preparing Video For Download...