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 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Java Deep Learning Cookbook

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

Rahul Raj

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Java Deep Learning Cookbook un PDF/ePUB en línea?
Sí, puedes acceder a Java Deep Learning Cookbook de Rahul Raj en formato PDF o ePUB, así como a otros libros populares de Computer Science y Natural Language Processing. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
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...

Índice

  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
Estilos de citas para 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.