100% found this document useful (2 votes)
10 views

Immediate download Natural Language Processing Recipes: Unlocking Text Data with Machine Learning and Deep Learning Using Python 2nd Edition Akshay Kulkarni ebooks 2024

The document promotes the ebook 'Natural Language Processing Recipes: Unlocking Text Data with Machine Learning and Deep Learning Using Python, 2nd Edition' by Akshay Kulkarni and Adarsha Shivananda, available for download on ebookmeta.com. It includes links to additional recommended digital products related to machine learning and NLP. The ebook provides practical recipes for extracting and processing text data using Python.

Uploaded by

pareljayonew
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
10 views

Immediate download Natural Language Processing Recipes: Unlocking Text Data with Machine Learning and Deep Learning Using Python 2nd Edition Akshay Kulkarni ebooks 2024

The document promotes the ebook 'Natural Language Processing Recipes: Unlocking Text Data with Machine Learning and Deep Learning Using Python, 2nd Edition' by Akshay Kulkarni and Adarsha Shivananda, available for download on ebookmeta.com. It includes links to additional recommended digital products related to machine learning and NLP. The ebook provides practical recipes for extracting and processing text data using Python.

Uploaded by

pareljayonew
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Get the full ebook with Bonus Features for a Better Reading Experience on ebookmeta.

com

Natural Language Processing Recipes: Unlocking


Text Data with Machine Learning and Deep Learning
Using Python 2nd Edition Akshay Kulkarni

https://ebookmeta.com/product/natural-language-processing-
recipes-unlocking-text-data-with-machine-learning-and-deep-
learning-using-python-2nd-edition-akshay-kulkarni-2/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Natural Language Processing Recipes: Unlocking Text Data


with Machine Learning and Deep Learning Using Python 2nd
Edition Akshay Kulkarni
https://ebookmeta.com/product/natural-language-processing-recipes-
unlocking-text-data-with-machine-learning-and-deep-learning-using-
python-2nd-edition-akshay-kulkarni/
ebookmeta.com

Time Series Algorithms Recipes: Implement Machine Learning


and Deep Learning Techniques with Python 1st Edition
Akshay Kulkarni
https://ebookmeta.com/product/time-series-algorithms-recipes-
implement-machine-learning-and-deep-learning-techniques-with-
python-1st-edition-akshay-kulkarni/
ebookmeta.com

Natural Language Processing Projects: Build Next-


Generation NLP Applications Using AI Techniques Akshay
Kulkarni
https://ebookmeta.com/product/natural-language-processing-projects-
build-next-generation-nlp-applications-using-ai-techniques-akshay-
kulkarni/
ebookmeta.com

Aspects of Value Frederick Charles Gruber (Editor)

https://ebookmeta.com/product/aspects-of-value-frederick-charles-
gruber-editor/

ebookmeta.com
Paul Miriam The Yoder Sisters Mail Order Brides Book 6 1st
Edition M K Moore

https://ebookmeta.com/product/paul-miriam-the-yoder-sisters-mail-
order-brides-book-6-1st-edition-m-k-moore-2/

ebookmeta.com

Computer Vision ECCV 2020 16th European Conference Glasgow


UK August 23 28 2020 Proceedings Part VI Andrea Vedaldi

https://ebookmeta.com/product/computer-vision-eccv-2020-16th-european-
conference-glasgow-uk-august-23-28-2020-proceedings-part-vi-andrea-
vedaldi/
ebookmeta.com

The Terrorism Survival Guide 201 Travel Tips on How Not to


Become a Victim Revised and Updated Andy Lightbody

https://ebookmeta.com/product/the-terrorism-survival-guide-201-travel-
tips-on-how-not-to-become-a-victim-revised-and-updated-andy-lightbody/

ebookmeta.com

Yoga Of Gita Expounded By Saint Dnyaneshwar Inner Secrets


Of Rajayoga Saint Dnyaneshwar On Kundalini Yoga Practice
VOL 2 1st Edition Vibhakar Vitthal Lele
https://ebookmeta.com/product/yoga-of-gita-expounded-by-saint-
dnyaneshwar-inner-secrets-of-rajayoga-saint-dnyaneshwar-on-kundalini-
yoga-practice-vol-2-1st-edition-vibhakar-vitthal-lele/
ebookmeta.com

Dynamics Information and Complexity in Quantum Systems 2nd


Edition Fabio Benatti

https://ebookmeta.com/product/dynamics-information-and-complexity-in-
quantum-systems-2nd-edition-fabio-benatti/

ebookmeta.com
Inside Wikipedia How It Works and How You Can Be an Editor
Paul A Thomas

https://ebookmeta.com/product/inside-wikipedia-how-it-works-and-how-
you-can-be-an-editor-paul-a-thomas/

ebookmeta.com
Natural Language
Processing
Recipes
Unlocking Text Data with Machine Learning
and Deep Learning Using Python

Second Edition

Akshay Kulkarni
Adarsha Shivananda
Natural Language
Processing Recipes
Unlocking Text Data with
Machine Learning and Deep Learning
Using Python
Second Edition

Akshay Kulkarni
Adarsha Shivananda
Natural Language Processing Recipes: Unlocking Text Data with Machine Learning
and Deep Learning Using Python
Akshay Kulkarni Adarsha Shivananda
Bangalore, Karnataka, India Bangalore, Karnataka, India

ISBN-13 (pbk): 978-1-4842-7350-0     ISBN-13 (electronic): 978-1-4842-7351-7


https://doi.org/10.1007/978-1-4842-7351-7

Copyright © 2021 by Akshay Kulkarni and Adarsha Shivananda


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Celestin Suresh John
Development Editor: Laura Berendson
Coordinating Editor: Shrikant Vishwakarma
Cover designed by eStudioCalamar
Cover image designed by Pexels
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite
4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, email orders-ny@springer-sbm.
com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner)
is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware
corporation.
For information on translations, please e-mail [email protected]; for reprint, paperback,
or audio rights, please e-mail [email protected], or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/978-­1-­4842-­7350-­0. For more
detailed information, please visit http://www.apress.com/source-­code.
Printed on acid-free paper
To our families
Table of Contents
About the Authors����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii


Acknowledgments��������������������������������������������������������������������������������������������������xix

Introduction������������������������������������������������������������������������������������������������������������xxi

Chapter 1: Extracting the Data��������������������������������������������������������������������������������� 1


Introduction����������������������������������������������������������������������������������������������������������������������������������� 1
Client Data������������������������������������������������������������������������������������������������������������������������������������ 1
Free Sources��������������������������������������������������������������������������������������������������������������������������������� 2
Web Scraping�������������������������������������������������������������������������������������������������������������������������������� 2
Recipe 1-1. Collecting Data���������������������������������������������������������������������������������������������������������� 2
Problem����������������������������������������������������������������������������������������������������������������������������������� 3
Solution����������������������������������������������������������������������������������������������������������������������������������� 3
How It Works��������������������������������������������������������������������������������������������������������������������������� 3
Recipe 1-2. Collecting Data from PDFs����������������������������������������������������������������������������������������� 4
Problem����������������������������������������������������������������������������������������������������������������������������������� 4
Solution����������������������������������������������������������������������������������������������������������������������������������� 5
How It Works��������������������������������������������������������������������������������������������������������������������������� 5
Recipe 1-3. Collecting Data from Word Files�������������������������������������������������������������������������������� 6
Problem����������������������������������������������������������������������������������������������������������������������������������� 6
Solution����������������������������������������������������������������������������������������������������������������������������������� 6
How It Works��������������������������������������������������������������������������������������������������������������������������� 6
Recipe 1-4. Collecting Data from JSON���������������������������������������������������������������������������������������� 7
Problem����������������������������������������������������������������������������������������������������������������������������������� 7
Solution����������������������������������������������������������������������������������������������������������������������������������� 7
How It Works��������������������������������������������������������������������������������������������������������������������������� 8

v
Table of Contents

Recipe 1-5. Collecting Data from HTML�������������������������������������������������������������������������������������� 10


Problem��������������������������������������������������������������������������������������������������������������������������������� 10
Solution��������������������������������������������������������������������������������������������������������������������������������� 10
How It Works������������������������������������������������������������������������������������������������������������������������� 10
Recipe 1-6. Parsing Text Using Regular Expressions������������������������������������������������������������������ 13
Problem��������������������������������������������������������������������������������������������������������������������������������� 13
Solution��������������������������������������������������������������������������������������������������������������������������������� 13
How It Works������������������������������������������������������������������������������������������������������������������������� 14
Recipe 1-7. Handling Strings������������������������������������������������������������������������������������������������������ 21
Problem��������������������������������������������������������������������������������������������������������������������������������� 21
Solution��������������������������������������������������������������������������������������������������������������������������������� 21
How It Works������������������������������������������������������������������������������������������������������������������������� 22
Recipe 1-8. Scraping Text from the Web������������������������������������������������������������������������������������� 23
Problem��������������������������������������������������������������������������������������������������������������������������������� 24
Solution��������������������������������������������������������������������������������������������������������������������������������� 24
How It Works������������������������������������������������������������������������������������������������������������������������� 24

Chapter 2: Exploring and Processing Text Data������������������������������������������������������ 31


Recipe 2-1. Converting Text Data to Lowercase������������������������������������������������������������������������� 32
Problem��������������������������������������������������������������������������������������������������������������������������������� 32
Solution��������������������������������������������������������������������������������������������������������������������������������� 32
How It Works������������������������������������������������������������������������������������������������������������������������� 32
Recipe 2-2. Removing Punctuation��������������������������������������������������������������������������������������������� 34
Problem��������������������������������������������������������������������������������������������������������������������������������� 34
Solution��������������������������������������������������������������������������������������������������������������������������������� 34
How It Works������������������������������������������������������������������������������������������������������������������������� 34
Recipe 2-3. Removing Stop Words���������������������������������������������������������������������������������������������� 36
Problem��������������������������������������������������������������������������������������������������������������������������������� 36
Solution��������������������������������������������������������������������������������������������������������������������������������� 36
How It Works������������������������������������������������������������������������������������������������������������������������� 37

vi
Table of Contents

Recipe 2-4. Standardizing Text��������������������������������������������������������������������������������������������������� 38


Problem��������������������������������������������������������������������������������������������������������������������������������� 38
Solution��������������������������������������������������������������������������������������������������������������������������������� 38
How It Works������������������������������������������������������������������������������������������������������������������������� 39
Recipe 2-5. Correcting Spelling�������������������������������������������������������������������������������������������������� 40
Problem��������������������������������������������������������������������������������������������������������������������������������� 40
Solution��������������������������������������������������������������������������������������������������������������������������������� 40
How It Works������������������������������������������������������������������������������������������������������������������������� 40
Recipe 2-6. Tokenizing Text�������������������������������������������������������������������������������������������������������� 42
Problem��������������������������������������������������������������������������������������������������������������������������������� 42
Solution��������������������������������������������������������������������������������������������������������������������������������� 42
How It Works������������������������������������������������������������������������������������������������������������������������� 42
Recipe 2-7. Stemming���������������������������������������������������������������������������������������������������������������� 44
Problem��������������������������������������������������������������������������������������������������������������������������������� 44
Solution��������������������������������������������������������������������������������������������������������������������������������� 44
How It Works������������������������������������������������������������������������������������������������������������������������� 44
Recipe 2-8. Lemmatizing������������������������������������������������������������������������������������������������������������ 45
Problem��������������������������������������������������������������������������������������������������������������������������������� 46
Solution��������������������������������������������������������������������������������������������������������������������������������� 46
How It Works������������������������������������������������������������������������������������������������������������������������� 46
Recipe 2-9. Exploring Text Data�������������������������������������������������������������������������������������������������� 47
Problem��������������������������������������������������������������������������������������������������������������������������������� 47
Solution��������������������������������������������������������������������������������������������������������������������������������� 47
How It Works������������������������������������������������������������������������������������������������������������������������� 48
Recipe 2-10. Dealing with Emojis and Emoticons���������������������������������������������������������������������� 52
Problem��������������������������������������������������������������������������������������������������������������������������������� 53
Solution��������������������������������������������������������������������������������������������������������������������������������� 53
How It Works������������������������������������������������������������������������������������������������������������������������� 53
Problem��������������������������������������������������������������������������������������������������������������������������������� 54
Solution��������������������������������������������������������������������������������������������������������������������������������� 54
How It Works������������������������������������������������������������������������������������������������������������������������� 54

vii
Table of Contents

Problem��������������������������������������������������������������������������������������������������������������������������������� 55
Solution��������������������������������������������������������������������������������������������������������������������������������� 55
How It Works������������������������������������������������������������������������������������������������������������������������� 55
Problem��������������������������������������������������������������������������������������������������������������������������������� 56
Solution��������������������������������������������������������������������������������������������������������������������������������� 56
How It Works������������������������������������������������������������������������������������������������������������������������� 57
Problem��������������������������������������������������������������������������������������������������������������������������������� 58
Solution��������������������������������������������������������������������������������������������������������������������������������� 58
How It Works������������������������������������������������������������������������������������������������������������������������� 58
Recipe 2-11. Building a Text Preprocessing Pipeline������������������������������������������������������������������ 59
Problem��������������������������������������������������������������������������������������������������������������������������������� 59
Solution��������������������������������������������������������������������������������������������������������������������������������� 59
How It Works������������������������������������������������������������������������������������������������������������������������� 60

Chapter 3: Converting Text to Features������������������������������������������������������������������ 63


Recipe 3-1. Converting Text to Features Using One-­Hot Encoding��������������������������������������������� 64
Problem��������������������������������������������������������������������������������������������������������������������������������� 64
Solution��������������������������������������������������������������������������������������������������������������������������������� 64
How It Works������������������������������������������������������������������������������������������������������������������������� 64
Recipe 3-2. Converting Text to Features Using a Count Vectorizer��������������������������������������������� 65
Problem��������������������������������������������������������������������������������������������������������������������������������� 65
Solution��������������������������������������������������������������������������������������������������������������������������������� 66
How It Works������������������������������������������������������������������������������������������������������������������������� 66
Recipe 3-3. Generating n-grams������������������������������������������������������������������������������������������������� 67
Problem��������������������������������������������������������������������������������������������������������������������������������� 67
Solution��������������������������������������������������������������������������������������������������������������������������������� 67
How It Works������������������������������������������������������������������������������������������������������������������������� 68
Recipe 3-4. Generating a Co-occurrence Matrix������������������������������������������������������������������������� 69
Problem��������������������������������������������������������������������������������������������������������������������������������� 69
Solution��������������������������������������������������������������������������������������������������������������������������������� 70
How It Works������������������������������������������������������������������������������������������������������������������������� 70

viii
Table of Contents

Recipe 3-5. Hash Vectorizing������������������������������������������������������������������������������������������������������ 72


Problem��������������������������������������������������������������������������������������������������������������������������������� 72
Solution��������������������������������������������������������������������������������������������������������������������������������� 72
How It Works������������������������������������������������������������������������������������������������������������������������� 72
Recipe 3-6. Converting Text to Features Using TF-­IDF���������������������������������������������������������������� 73
Problem��������������������������������������������������������������������������������������������������������������������������������� 73
Solution��������������������������������������������������������������������������������������������������������������������������������� 73
How It Works������������������������������������������������������������������������������������������������������������������������� 74
Recipe 3-7. Implementing Word Embeddings����������������������������������������������������������������������������� 75
Problem��������������������������������������������������������������������������������������������������������������������������������� 76
Solution��������������������������������������������������������������������������������������������������������������������������������� 77
How It Works������������������������������������������������������������������������������������������������������������������������� 77
Recipe 3-8. Implementing fastText��������������������������������������������������������������������������������������������� 84
Problem��������������������������������������������������������������������������������������������������������������������������������� 84
Solution��������������������������������������������������������������������������������������������������������������������������������� 84
How It Works������������������������������������������������������������������������������������������������������������������������� 84
Recipe 3-9. Converting Text to Features Using State-­of-­the-Art Embeddings���������������������������� 87
Problem��������������������������������������������������������������������������������������������������������������������������������� 87
Solution��������������������������������������������������������������������������������������������������������������������������������� 87
ELMo�������������������������������������������������������������������������������������������������������������������������������������� 88
Sentence Encoders���������������������������������������������������������������������������������������������������������������� 89
Open-AI GPT�������������������������������������������������������������������������������������������������������������������������� 91
How It Works������������������������������������������������������������������������������������������������������������������������� 91

Chapter 4: Advanced Natural Language Processing��������������������������������������������� 107


Recipe 4-1. Extracting Noun Phrases��������������������������������������������������������������������������������������� 109
Problem������������������������������������������������������������������������������������������������������������������������������� 109
Solution������������������������������������������������������������������������������������������������������������������������������� 109
How It Works����������������������������������������������������������������������������������������������������������������������� 109
Recipe 4-2. Finding Similarity Between Texts��������������������������������������������������������������������������� 110
Solution������������������������������������������������������������������������������������������������������������������������������� 110
How It Works����������������������������������������������������������������������������������������������������������������������� 110

ix
Table of Contents

Recipe 4-3. Tagging Part of Speech������������������������������������������������������������������������������������������ 113


Problem������������������������������������������������������������������������������������������������������������������������������� 113
Solution������������������������������������������������������������������������������������������������������������������������������� 113
How It Works����������������������������������������������������������������������������������������������������������������������� 113
Recipe 4-4. Extracting Entities from Text���������������������������������������������������������������������������������� 116
Problem������������������������������������������������������������������������������������������������������������������������������� 116
Solution������������������������������������������������������������������������������������������������������������������������������� 116
How It Works����������������������������������������������������������������������������������������������������������������������� 116
Recipe 4-5. Extracting Topics from Text������������������������������������������������������������������������������������ 118
Problem������������������������������������������������������������������������������������������������������������������������������� 118
Solution������������������������������������������������������������������������������������������������������������������������������� 118
How It Works����������������������������������������������������������������������������������������������������������������������� 118
Recipe 4-6. Classifying Text������������������������������������������������������������������������������������������������������ 121
Problem������������������������������������������������������������������������������������������������������������������������������� 121
Solution������������������������������������������������������������������������������������������������������������������������������� 121
How It Works����������������������������������������������������������������������������������������������������������������������� 122
Recipe 4-7. Carrying Out Sentiment Analysis��������������������������������������������������������������������������� 125
Problem������������������������������������������������������������������������������������������������������������������������������� 125
Solution������������������������������������������������������������������������������������������������������������������������������� 125
How It Works����������������������������������������������������������������������������������������������������������������������� 125
Recipe 4-8. Disambiguating Text���������������������������������������������������������������������������������������������� 127
Problem������������������������������������������������������������������������������������������������������������������������������� 127
Solution������������������������������������������������������������������������������������������������������������������������������� 127
How It Works����������������������������������������������������������������������������������������������������������������������� 127
Recipe 4-9. Converting Speech to Text������������������������������������������������������������������������������������� 128
Problem������������������������������������������������������������������������������������������������������������������������������� 129
Solution������������������������������������������������������������������������������������������������������������������������������� 129
How It Works����������������������������������������������������������������������������������������������������������������������� 129
Recipe 4-10. Converting Text to Speech����������������������������������������������������������������������������������� 131
Problem������������������������������������������������������������������������������������������������������������������������������� 131

x
Table of Contents

Solution������������������������������������������������������������������������������������������������������������������������������� 131
How It Works����������������������������������������������������������������������������������������������������������������������� 131
Recipe 4-11. Translating Speech���������������������������������������������������������������������������������������������� 132
Problem������������������������������������������������������������������������������������������������������������������������������� 132
Solution������������������������������������������������������������������������������������������������������������������������������� 132
How It Works����������������������������������������������������������������������������������������������������������������������� 132

Chapter 5: Implementing Industry Applications��������������������������������������������������� 135


Recipe 5-1. Implementing Multiclass Classification����������������������������������������������������������������� 135
Problem������������������������������������������������������������������������������������������������������������������������������� 136
Solution������������������������������������������������������������������������������������������������������������������������������� 136
How It Works����������������������������������������������������������������������������������������������������������������������� 136
Recipe 5-2. Implementing Sentiment Analysis������������������������������������������������������������������������� 143
Problem������������������������������������������������������������������������������������������������������������������������������� 143
Solution������������������������������������������������������������������������������������������������������������������������������� 143
How It Works����������������������������������������������������������������������������������������������������������������������� 143
Recipe 5-3. Applying Text Similarity Functions������������������������������������������������������������������������� 154
Problem������������������������������������������������������������������������������������������������������������������������������� 154
Solution������������������������������������������������������������������������������������������������������������������������������� 155
How It Works����������������������������������������������������������������������������������������������������������������������� 155
Recipe 5-4. Summarizing Text Data������������������������������������������������������������������������������������������ 165
Problem������������������������������������������������������������������������������������������������������������������������������� 166
Solution������������������������������������������������������������������������������������������������������������������������������� 166
How It Works����������������������������������������������������������������������������������������������������������������������� 166
Recipe 5-5. Clustering Documents������������������������������������������������������������������������������������������� 172
Problem������������������������������������������������������������������������������������������������������������������������������� 172
Solution������������������������������������������������������������������������������������������������������������������������������� 172
How It Works����������������������������������������������������������������������������������������������������������������������� 172
Recipe 5-6. NLP in a Search Engine����������������������������������������������������������������������������������������� 178
Problem������������������������������������������������������������������������������������������������������������������������������� 178
Solution������������������������������������������������������������������������������������������������������������������������������� 178
How It Works����������������������������������������������������������������������������������������������������������������������� 179

xi
Table of Contents

Recipe 5-7. Detecting Fake News��������������������������������������������������������������������������������������������� 181


Problem������������������������������������������������������������������������������������������������������������������������������� 181
Solution������������������������������������������������������������������������������������������������������������������������������� 182
How It Works����������������������������������������������������������������������������������������������������������������������� 182
Recipe 5-8. Movie Genre Tagging��������������������������������������������������������������������������������������������� 195
Problem������������������������������������������������������������������������������������������������������������������������������� 195
Solution������������������������������������������������������������������������������������������������������������������������������� 196
How It Works����������������������������������������������������������������������������������������������������������������������� 197

Chapter 6: Deep Learning for NLP������������������������������������������������������������������������ 213


Introduction to Deep Learning�������������������������������������������������������������������������������������������������� 213
Convolutional Neural Networks������������������������������������������������������������������������������������������������� 215
Data������������������������������������������������������������������������������������������������������������������������������������������� 215
Architecture������������������������������������������������������������������������������������������������������������������������������ 216
Convolution������������������������������������������������������������������������������������������������������������������������������� 216
Nonlinearity (ReLU)������������������������������������������������������������������������������������������������������������������� 216
Pooling�������������������������������������������������������������������������������������������������������������������������������������� 217
Flatten, Fully Connected, and Softmax Layers�������������������������������������������������������������������������� 217
Backpropagation: Training the Neural Network������������������������������������������������������������������������ 218
Recurrent Neural Networks������������������������������������������������������������������������������������������������������ 218
Training RNN: Backpropagation Through Time (BPTT)�������������������������������������������������������������� 219
Long Short-Term Memory (LSTM)��������������������������������������������������������������������������������������������� 219
Recipe 6-1. Retrieving Information������������������������������������������������������������������������������������������� 220
Problem������������������������������������������������������������������������������������������������������������������������������� 221
Solution������������������������������������������������������������������������������������������������������������������������������� 221
How It Works����������������������������������������������������������������������������������������������������������������������� 222
Recipe 6-2. Classifying Text with Deep Learning���������������������������������������������������������������������� 227
Problem������������������������������������������������������������������������������������������������������������������������������� 227
Solution������������������������������������������������������������������������������������������������������������������������������� 227
How It Works����������������������������������������������������������������������������������������������������������������������� 228

xii
Table of Contents

Recipe 6-3. Next Word Prediction��������������������������������������������������������������������������������������������� 240


Problem������������������������������������������������������������������������������������������������������������������������������� 241
Solution������������������������������������������������������������������������������������������������������������������������������� 241
How It Works����������������������������������������������������������������������������������������������������������������������� 241
Recipe 6-4. Stack Overflow question recommendation������������������������������������������������������������ 248
Problem������������������������������������������������������������������������������������������������������������������������������� 249
Solution������������������������������������������������������������������������������������������������������������������������������� 249
How It Works����������������������������������������������������������������������������������������������������������������������� 249

Chapter 7: Conclusion and Next-Gen NLP������������������������������������������������������������� 263


Recipe 7-1. Recent advancements in text to features or distributed representations������������� 265
Problem������������������������������������������������������������������������������������������������������������������������������� 265
Solution������������������������������������������������������������������������������������������������������������������������������� 265
Recipe 7-2. Advanced deep learning for NLP��������������������������������������������������������������������������� 265
Problem������������������������������������������������������������������������������������������������������������������������������� 265
Solution������������������������������������������������������������������������������������������������������������������������������� 265
Recipe 7-3. Reinforcement learning applications in NLP��������������������������������������������������������� 266
Problem������������������������������������������������������������������������������������������������������������������������������� 266
Solution������������������������������������������������������������������������������������������������������������������������������� 266
Recipe 7-4. Transfer learning and pre-trained models������������������������������������������������������������� 267
Problem������������������������������������������������������������������������������������������������������������������������������� 267
Solution������������������������������������������������������������������������������������������������������������������������������� 268
Recipe 7-5. Meta-learning in NLP��������������������������������������������������������������������������������������������� 273
Problem������������������������������������������������������������������������������������������������������������������������������� 273
Solution������������������������������������������������������������������������������������������������������������������������������� 273
Recipe 7-6. Capsule networks for NLP������������������������������������������������������������������������������������� 274
Problem������������������������������������������������������������������������������������������������������������������������������� 274
Solution������������������������������������������������������������������������������������������������������������������������������� 274

Index��������������������������������������������������������������������������������������������������������������������� 277

xiii
About the Authors
Akshay Kulkarni is a renowned AI and machine learning
evangelist and thought leader. He has consulted several
Fortune 500 and global enterprises on driving AI and
data science–led strategic transformation. Akshay has
rich experience in building and scaling AI and machine
learning businesses and creating significant impact. He
is currently a data science and AI manager at Publicis
Sapient, where he is part of strategy and transformation
interventions through AI. He manages high-priority
growth initiatives around data science and works on
various artificial intelligence engagements by applying
state-of-the-art techniques to this space.
Akshay is also a Google Developers Expert in machine learning, a published author
of books on NLP and deep learning, and a regular speaker at major AI and data science
conferences.
In 2019, Akshay was named one of the top “40 under 40 data scientists” in India.
In his spare time, he enjoys reading, writing, coding, and mentoring aspiring data
scientists. He lives in Bangalore, India, with his family.

Adarsha Shivananda is a lead data scientist at Indegene


Inc.’s product and technology team, where he leads a
group of analysts who enable predictive analytics and AI
features to healthcare software products. These are mainly
multichannel activities for pharma products and solving
the real-time problems encountered by pharma sales reps.
Adarsha aims to build a pool of exceptional data scientists
within the organization to solve greater health care problems
through brilliant training programs. He always wants to stay
ahead of the curve.

xv
About the Authors

His core expertise involves machine learning, deep learning, recommendation


systems, and statistics. Adarsha has worked on various data science projects across
multiple domains using different technologies and methodologies. Previously, he
worked for Tredence Analytics and IQVIA.
He lives in Bangalore, India, and loves to read, ride, and teach data science.

xvi
Other documents randomly have
different content
expenses, including legal fees. YOU AGREE THAT YOU HAVE NO
REMEDIES FOR NEGLIGENCE, STRICT LIABILITY, BREACH OF
WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE
PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE THAT THE
FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving it,
you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or entity
that provided you with the defective work may elect to provide a
replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.
1.F.6. INDEMNITY - You agree to indemnify and hold the
Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and distribution
of Project Gutenberg™ electronic works, harmless from all liability,
costs and expenses, including legal fees, that arise directly or
indirectly from any of the following which you do or cause to occur:
(a) distribution of this or any Project Gutenberg™ work, (b)
alteration, modification, or additions or deletions to any Project
Gutenberg™ work, and (c) any Defect you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many small
donations ($1 to $5,000) are particularly important to maintaining tax
exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.

Project Gutenberg™ eBooks are often created from several printed


editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.

You might also like