09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

0 1 there is so much good food in vegas that i feel cheated for

wasting an eating opportunity by going to rice and company

Chapter 8

We also report the results across all sentences in the test dataset. As you can see,

the test accuracy is the same as that reported by the evaluate call. We have also

generated the confusion matrix, which shows that out of 1000 test examples, our

sentiment analysis network predicted correctly 782 times and incorrectly 218 times:

accuracy score: 0.782

confusion matrix

[[391 97]

[121 391]]

The full code for this example is available in lstm_sentiment_analysis.py in the

source code folder for this chapter. It can be run from the command line using the

following command:

$ python lstm_sentiment_analysis.py

Our next example will describe a many-to-many network trained for POS tagging

English text.

Example ‒ Many-to-Many – POS tagging

In this example, we will use a GRU layer to build a network that does POS tagging.

A POS is a grammatical category of words that are used in the same way across

multiple sentences. Examples of POS are nouns, verbs, adjectives, and so on. For

example, nouns are typically used to identify things, verbs are typically used

to identify what they do, and adjectives are used to describe attributes of these

things. POS tagging used to be done manually in the past, but this is now mostly

a solved problem, initially through statistical models, and more recently by using

deep learning models in an end-to-end manner, as described in Collobert, et al. [21].

For our training data, we will need sentences tagged with part of speech tags. The

Penn Treebank [22] is one such dataset; it is a human-annotated corpus of about

4.5 million words of American English. However, it is a non-free resource. A 10%

sample of the Penn Treebank is freely available as part of NLTK [23], which we will

use to train our network.

Our model will take a sequence of words in a sentence as input, then will output the

corresponding POS tag for each word. Thus, for an input sequence consisting of the

words [The, cat, sat. on, the, mat, .], the output sequence should be the POS symbols

[DT, NN, VB, IN, DT, NN, .].

[ 307 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!