Трансферне навчання для мовних моделей

Recurrent Neural Networks (RNNs) для моделювання мови з Keras

David Cecchini

Data Scientist

Ідея трансферного навчання

Трансферне навчання:

  • Починайте з ваг кращих за випадкові
  • Використовуйте моделі, натреновані на дуже великих наборах даних
  • Моделі data science з відкритим кодом
Recurrent Neural Networks (RNNs) для моделювання мови з 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-грами символів
  • ELMo X = [I, really, loved, this], y = movie
    • Використовує слова, вбудовування залежно від контексту
    • Використовує глибокі двонапрямлені мовні моделі (biLM)
  • Word2Vec і FastText доступні в пакеті gensim, а ELMo — у tensorflow_hub
Recurrent Neural Networks (RNNs) для моделювання мови з 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) для моделювання мови з 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) для моделювання мови з Keras

Давайте потренуємось!

Recurrent Neural Networks (RNNs) для моделювання мови з Keras

Preparing Video For Download...