Book Image

Deep Learning for Natural Language Processing

By : Karthiek Reddy Bokka, Shubhangi Hora, Tanuj Jain, Monicah Wambugu
Book Image

Deep Learning for Natural Language Processing

By: Karthiek Reddy Bokka, Shubhangi Hora, Tanuj Jain, Monicah Wambugu

Overview of this book

Applying deep learning approaches to various NLP tasks can take your computational algorithms to a completely new level in terms of speed and accuracy. Deep Learning for Natural Language Processing starts by highlighting the basic building blocks of the natural language processing domain. The book goes on to introduce the problems that you can solve using state-of-the-art neural network models. After this, delving into the various neural network architectures and their specific areas of application will help you to understand how to select the best model to suit your needs. As you advance through this deep learning book, you’ll study convolutional, recurrent, and recursive neural networks, in addition to covering long short-term memory networks (LSTM). Understanding these networks will help you to implement their models using Keras. In later chapters, you will be able to develop a trigger word detection application using NLP techniques such as attention model and beam search. By the end of this book, you will not only have sound knowledge of natural language processing, but also be able to select the best text preprocessing and neural network models to solve a number of NLP issues.
Table of Contents (11 chapters)

Chapter 1: Introduction to Natural Language Processing

Activity 1: Generating word embeddings from a corpus using Word2Vec.

Solution:

  1. Upload the text corpus from the link aforementioned.
  2. Import the word2vec from gensim models

    from gensim.models import word2vec

  3. Store the corpus in a variable.

    sentences = word2vec.Text8Corpus('text8')

  4. Fit the word2vec model on the corpus.

    model = word2vec.Word2Vec(sentences, size = 200)

  5. Find the most similar word to 'man'.

    model.most_similar(['man'])

    The output is as follows:

    Figure 1.29: Output for similar word embeddings
    Figure 1.29: Output for similar word embeddings
  6. 'Father' is to 'girl', 'x' is to boy. Find the top 3 words for x.

    model.most_similar(['girl', 'father'], ['boy'], topn=3)

    The output is as follows:

Figure 1.30: Output for top three words for ‘x’
Figure 1.30: Output for top three words for 'x'