Java Deep Learning Cookbook
eBook - ePub

Java Deep Learning Cookbook

Train neural networks for classification, NLP, and reinforcement learning using Deeplearning4j

Rahul Raj

  1. 304 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Java Deep Learning Cookbook

Train neural networks for classification, NLP, and reinforcement learning using Deeplearning4j

Rahul Raj

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Use Java and Deeplearning4j to build robust, scalable, and highly accurate AI models from scratch

Key Features

  • Install and configure Deeplearning4j to implement deep learning models from scratch
  • Explore recipes for developing, training, and fine-tuning your neural network models in Java
  • Model neural networks using datasets containing images, text, and time-series data

Book Description

Java is one of the most widely used programming languages in the world. With this book, you will see how to perform deep learning using Deeplearning4j (DL4J) – the most popular Java library for training neural networks efficiently.

This book starts by showing you how to install and configure Java and DL4J on your system. You will then gain insights into deep learning basics and use your knowledge to create a deep neural network for binary classification from scratch. As you progress, you will discover how to build a convolutional neural network (CNN) in DL4J, and understand how to construct numeric vectors from text. This deep learning book will also guide you through performing anomaly detection on unsupervised data and help you set up neural networks in distributed systems effectively. In addition to this, you will learn how to import models from Keras and change the configuration in a pre-trained DL4J model. Finally, you will explore benchmarking in DL4J and optimize neural networks for optimal results.

By the end of this book, you will have a clear understanding of how you can use DL4J to build robust deep learning applications in Java.

What you will learn

  • Perform data normalization and wrangling using DL4J
  • Build deep neural networks using DL4J
  • Implement CNNs to solve image classification problems
  • Train autoencoders to solve anomaly detection problems using DL4J
  • Perform benchmarking and optimization to improve your model's performance
  • Implement reinforcement learning for real-world use cases using RL4J
  • Leverage the capabilities of DL4J in distributed systems

Who this book is for

If you are a data scientist, machine learning developer, or a deep learning enthusiast who wants to implement deep learning models in Java, this book is for you. Basic understanding of Java programming as well as some experience with machine learning and neural networks is required to get the most out of this book.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Java Deep Learning Cookbook est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Java Deep Learning Cookbook par Rahul Raj en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Natural Language Processing. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2019
ISBN
9781788999472

Implementing Natural Language Processing

In this chapter, we will discuss word vectors (Word2Vec) and paragraph vectors (Doc2Vec) in DL4J. We will develop a complete running example step by step, covering all the stages, such as ETL, model configuration, training, and evaluation. Word2Vec and Doc2Vec are natural language processing (NLP) implementations in DL4J. It is worth mentioning a little about the bag-of-words algorithm before we talk about Word2Vec.
Bag-of-words is an algorithm that counts the instances of words in documents. This will allow us to perform document classification. Bag of words and Word2Vec are just two different types of text classification. Word2Vec can use a bag of words extracted from a document to create vectors. In addition to these text classification methods, term frequency–inverse document frequency (TF-IDF) can be used to judge the topic/context of the document. In the case of TF-IDF, a score will be calculated for all the words, and word counts will be replaced with this score. TF-IDF is a simple scoring scheme, but word embeddings may be a better choice, as the semantic similarity can be captured by word embedding. Also, if your dataset is small and the context is domain-specific, then bag of words may be a better choice than Word2Vec.
Word2Vec is a two-layer neural network that processes text. It converts the text corpus to vectors.
Note that Word2Vec is not a deep neural network (DNN). It transforms text data into a numerical format that a DNN can understand, making customization possible.
We can even combine Word2Vec with DNNs to serve this purpose. It doesn't train the input words through reconstruction; instead, it trains words using the neighboring words in the corpus.
Doc2Vec (paragraph vectors) associates documents with labels, and is an extension of Word2Vec. Word2Vec tries to correlate words with words, while Doc2Vec (paragraph vectors) correlates words with labels. Once we represent documents in vector formats, we can then use these formats as an input to a supervised learning algorithm to map these vectors to labels.
In this chapter, we will cover the following recipes:
  • Reading and loading text data
  • Tokenizing data and training the model
  • Evaluating the model
  • Generating plots from the model
  • Saving and reloading the model
  • Importing Google News vectors
  • Troubleshooting and tuning Word2Vec models
  • Using Word2Vec for sentence classification using CNNs
  • Using Doc2Vec for document classification

Technical requirements

The examples discussed in this chapter can be found at https://github.com/PacktPublishing/Java-Deep-Learning-Cookbook/tree/master/05_Implementing_NLP/sourceCode/cookbookapp/src/main/java/com/javadeeplearningcookbook/examples.
After cloning our GitHub repository, navigate to the directory called Java-Deep-Learning-Cookbook/05_Implementing_NLP/sourceCode. Then, import the cookbookapp project as a Maven project by importing pom.xml.
To get started with NLP in DL4J, add the following Maven dependency in pom.xml:
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-nlp</artifactId>
<version>1.0.0-beta3</version>
</dependency>

Data requirements

The project directory has a resource folder with the required data for the LineIterator examples:
For CnnWord2VecSentenceClassificationExample or GoogleNewsVectorExampleYou, you can download datasets from the following URLs:
  • Google News vector: https://deeplearning4jblob.blob.core.windows.net/resources/wordvectors/GoogleNews-vectors-negative300.bin.gz
  • IMDB review data: http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz
Note that IMDB review data needs to be extracted twice in order to get the actual dataset folder.
For the t-Distributed Stochastic Neighbor Embedding (t-SNE) visualization example, the required data (words.txt) can be located in the project root directory itself.

Reading and loading text data

We need to load raw sentences in text format and iterate them using an underlined iterator that serves the purpose. A text corpus can also be subjected to preprocessing, such as lowercase conversion. Stop words can be mentioned while configuring the Word2Vec model. In this recipe, we will extract and load text data from various data-input scenarios.

Getting ready

Select an iterator approach from step 1 to step 5 depending on what kind of data you're looking for and how you want to load it.

How to do it...

  1. Create a sentence iterator using BasicLineIterator:
File file = new File("raw_sentences.txt");
SentenceIterator iterator = new BasicLineIterator(file);
For an example, go to https://github.com/PacktPublishing/Java-Deep-Learning-Cookbook/blob/master/05_Implementing_NLP/sourceCode/cookbookapp/src/main/java/com/javadeeplearningcookbook/examples/BasicLineIteratorExample.java.
  1. Create a sentence iterator using LineSentenceIterator:
File file = new File("raw_sentences.txt");
SentenceIterator iterator = new LineSentenceIterator(file);
For an example, go to https://github.com/PacktPublishing/Java-Deep-Learning-Cookbook/blob/master/05_Implementing_NLP/sourceCode/cookbookapp/src/main/java/com/javadeeplearningcookbook/examples/LineSentenceIteratorExample.java.
  1. Create a sentence iterator using CollectionSentenceIterator:
List<String> sentences= Arrays.asList("sample text", "sample text", "sample text");
SentenceIterator iter = new Collect...

Table des matiĂšres

  1. Title Page
  2. Copyright and Credits
  3. Dedication
  4. About Packt
  5. Contributors
  6. Preface
  7. Introduction to Deep Learning in Java
  8. Data Extraction, Transformation, and Loading
  9. Building Deep Neural Networks for Binary Classification
  10. Building Convolutional Neural Networks
  11. Implementing Natural Language Processing
  12. Constructing an LSTM Network for Time Series
  13. Constructing an LSTM Neural Network for Sequence Classification
  14. Performing Anomaly Detection on Unsupervised Data
  15. Using RL4J for Reinforcement Learning
  16. Developing Applications in a Distributed Environment
  17. Applying Transfer Learning to Network Models
  18. Benchmarking and Neural Network Optimization
  19. Other Books You May Enjoy
Normes de citation pour Java Deep Learning Cookbook

APA 6 Citation

Raj, R. (2019). Java Deep Learning Cookbook (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/1204189/java-deep-learning-cookbook-train-neural-networks-for-classification-nlp-and-reinforcement-learning-using-deeplearning4j-pdf (Original work published 2019)

Chicago Citation

Raj, Rahul. (2019) 2019. Java Deep Learning Cookbook. 1st ed. Packt Publishing. https://www.perlego.com/book/1204189/java-deep-learning-cookbook-train-neural-networks-for-classification-nlp-and-reinforcement-learning-using-deeplearning4j-pdf.

Harvard Citation

Raj, R. (2019) Java Deep Learning Cookbook. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/1204189/java-deep-learning-cookbook-train-neural-networks-for-classification-nlp-and-reinforcement-learning-using-deeplearning4j-pdf (Accessed: 14 October 2022).

MLA 7 Citation

Raj, Rahul. Java Deep Learning Cookbook. 1st ed. Packt Publishing, 2019. Web. 14 Oct. 2022.