How it works...

In step 1, we used loadStaticModel() to load the model from the given path; however, you can also use readWord2VecModel(). Unlike readWord2VecModel(), loadStaticModel() utilizes host memory.

In step 2, FileLabeledSentenceProvider is used as a data source to load the sentences/documents from the files. We created CnnSentenceDataSetIterator using the same. CnnSentenceDataSetIterator handles the conversion of sentences to training data for CNNs, where each word is encoded using the word vector from the specified word vector model. Sentences and labels are provided by a LabeledSentenceProvider interface. Different implementations of LabeledSentenceProvider provide different ways of loading the sentence/documents with labels.

In step 3, we created CnnSentenceDataSetIterator to create train/test dataset iterators. The parameters we configured here are as follows:

  • sentenceProvider(): Adds a sentence provider (data source) to CnnSentenceDataSetIterator
  • wordVectors(): Adds a word vector reference to the dataset iterator—for example, the Google News vectors
  • useNormalizedWordVectors(): Sets whether normalized word vectors can be used

In step 5, we created layers for a ComputationGraph model.

The ComputationGraph configuration is a configuration object for neural networks with an arbitrary connection structure. It is analogous to multilayer configuration, but allows considerably greater flexibility for the network architecture.

We also created multiple convolution layers stacked together with multiple filter widths and feature maps.

In step 6, MergeVertex performs in-depth concatenation on activation of these three convolution layers.

Once all steps up to step 8 are completed, we should see the following evaluation metrics:

In step 10, contents refers to the content from a single-sentence document in string format.

For negative review content, we would see the following result after step 9:

This means that the document has a 77.8% probability of having a negative sentiment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset