言語モデルの転移学習

Kerasで学ぶ言語モデリングのためのRecurrent Neural Networks (RNNs)

David Cecchini

Data Scientist

転移学習の考え方

転移学習:

  • ランダムより良い初期重みから開始
  • 巨大データで学習済みモデルを活用
  • オープンソースのデータサイエンス用モデル
Kerasで学ぶ言語モデリングのためのRecurrent Neural Networks (RNNs)

利用可能なアーキテクチャ

基本例: I really loved this movie

  • Word2Vec
    • 連続 BoW (CBOW) X = [I, really, this, movie], y = loved
    • Skip-gram X = loved, y = [I, really, this, movie]
  • FastText X = [I, rea, eal, all, lly, really, ...], y = loved
    • 単語と文字 n-gram を使用
  • ELMo X = [I, really, loved, this], y = movie
    • 単語を用い、文脈ごとに埋め込み
    • 双方向言語モデル(biLM)を使用
  • Word2Vec と FastText は gensim、ELMo は tensorflow_hub で利用可能
Kerasで学ぶ言語モデリングのためのRecurrent Neural Networks (RNNs)

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で学ぶ言語モデリングのためのRecurrent Neural Networks (RNNs)

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で学ぶ言語モデリングのためのRecurrent Neural Networks (RNNs)

演習に進みましょう

Kerasで学ぶ言語モデリングのためのRecurrent Neural Networks (RNNs)

Preparing Video For Download...