Transfer learning สำหรับ language model

Recurrent Neural Networks (RNNs) สำหรับ Language Modeling ด้วย Keras

David Cecchini

Data Scientist

แนวคิดของ transfer learning

Transfer learning:

  • เริ่มต้นด้วย weight ที่ดีกว่าการสุ่ม
  • ใช้โมเดลที่ฝึกบนชุดข้อมูลขนาดใหญ่
  • โมเดล data science แบบ "open-source"
Recurrent Neural Networks (RNNs) สำหรับ Language Modeling ด้วย Keras

สถาปัตยกรรมที่ใช้งานได้

ตัวอย่างประโยค: I really loved this movie

  • Word2Vec
    • Continuous Bag of Words (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
    • ใช้คำและ embedding ตามบริบท
    • ใช้ deep bidirectional language model (biLM)
  • Word2Vec และ FastText ใช้งานได้ผ่านแพ็กเกจ gensim และ ELMo ผ่าน tensorflow_hub
Recurrent Neural Networks (RNNs) สำหรับ Language Modeling ด้วย Keras

ตัวอย่างการใช้ 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)]
Recurrent Neural Networks (RNNs) สำหรับ Language Modeling ด้วย Keras

ตัวอย่างการใช้ 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)
Recurrent Neural Networks (RNNs) สำหรับ Language Modeling ด้วย Keras

มาฝึกกันเถอะ!

Recurrent Neural Networks (RNNs) สำหรับ Language Modeling ด้วย Keras

Preparing Video For Download...