pdfcoffee

soumyasankar99
from soumyasankar99 More from this publisher
09.05.2023 Views

Chapter 8RNN topologiesWe have seen examples of how MLP and CNN architectures can be composed toform more complex networks. RNNs offer yet another degree of freedom, in thatit allows sequence input and output. This means that RNN cells can be arrangedin different ways to build networks that are adapted to solve different types ofproblems. Figure 4 shows five different configurations of inputs, hidden layers, andoutputs, represented by red, green, and blue boxes respectively:Of these, the first one (one-to-one) is not interesting from a sequence processingpoint of view, since it can be implemented as a simple Dense network with one inputand one output.The one-to-many case has a single input and outputs a sequence. An example of sucha network might be a network that can generate text tags from images [6], containingshort text descriptions of different aspects of the image. Such a network would betrained with image input and labeled sequences of text representing the image tags:Figure 4: Common RNN topologies. Image Source: Andrej Karpathy [5]The many-to-one case is the reverse; it takes a sequence of tensors as input butoutputs a single tensor. Examples of such networks would be a sentiment analysisnetwork [7], which takes as input a block of text such as a movie review and outputsa single sentiment value.The many-to-many use case comes in two flavors. The first one is more popularand is better known as the seq2seq model. In this model, a sequence is read in andproduces a context vector representing the input sequence, which is used to generatethe output sequence.[ 291 ]

Recurrent Neural NetworksThe topology has been used with great success in the field of machine translation,as well as problems that can be reframed as machine translation problems. Reallife examples of the former can be found in [8, 9], and an example of the latter isdescribed in [10].The second many-to-many type has an output cell corresponding to each inputcell. This kind of network is suited for use cases where there is a 1:1 correspondencebetween the input and output, such as time series. The major difference betweenthis model and the seq2seq model is that the input does not have to be completelyencoded before the decoding process begins.In the next three sections, we provide examples of a one-to-many network thatlearns to generate text, a many-to-one network that does sentiment analysis, and amany-to-many network of the second type, which predicts Part-of-speech (POS) forwords in a sentence. Because of the popularity of the seq2seq network, we will coverit in more detail later in this chapter.Example ‒ One-to-Many – learning to generatetextRNNs have been used extensively by the Natural Language Processing (NLP)community for various applications. One such application is to build languagemodels. A language model is a model that allows us to predict the probability of aword in a text given previous words. Language models are important for varioushigher-level tasks such as machine translation, spelling correction, and so on.The ability of a language model to predict the next word in a sequence makes ita generative model that allows us to generate text by sampling from the outputprobabilities of different words in the vocabulary. The training data is a sequenceof words, and the label is the word appearing at the next time step in the sequence.For our example, we will train a character-based RNN on the text of the children'sstories "Alice in Wonderland" and its sequel "Through the Looking Glass" byLewis Carroll. We have chosen to build a character-based model because it has asmaller vocabulary and trains quicker. The idea is the same as training and using aword-based language model, except we will use characters instead of words. Oncetrained, the model can be used to generate some text in the same style.The data for our example will come from the plain texts of two novels from theProject Gutenberg website [36]. Input to the network are sequences of 100 characters,and the corresponding output is another sequence of 100 characters, offset from theinput by 1 position.[ 292 ]

Chapter 8

RNN topologies

We have seen examples of how MLP and CNN architectures can be composed to

form more complex networks. RNNs offer yet another degree of freedom, in that

it allows sequence input and output. This means that RNN cells can be arranged

in different ways to build networks that are adapted to solve different types of

problems. Figure 4 shows five different configurations of inputs, hidden layers, and

outputs, represented by red, green, and blue boxes respectively:

Of these, the first one (one-to-one) is not interesting from a sequence processing

point of view, since it can be implemented as a simple Dense network with one input

and one output.

The one-to-many case has a single input and outputs a sequence. An example of such

a network might be a network that can generate text tags from images [6], containing

short text descriptions of different aspects of the image. Such a network would be

trained with image input and labeled sequences of text representing the image tags:

Figure 4: Common RNN topologies. Image Source: Andrej Karpathy [5]

The many-to-one case is the reverse; it takes a sequence of tensors as input but

outputs a single tensor. Examples of such networks would be a sentiment analysis

network [7], which takes as input a block of text such as a movie review and outputs

a single sentiment value.

The many-to-many use case comes in two flavors. The first one is more popular

and is better known as the seq2seq model. In this model, a sequence is read in and

produces a context vector representing the input sequence, which is used to generate

the output sequence.

[ 291 ]

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

Saved successfully!

Ooh no, something went wrong!