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 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Java Deep Learning Cookbook

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

Rahul Raj

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

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.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Java Deep Learning Cookbook als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Java Deep Learning Cookbook von Rahul Raj im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Natural Language Processing. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
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...

Inhaltsverzeichnis

  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
Zitierstile für 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.