Building an Enterprise Chatbot

THThiNganHang
0 lượt tải
399
0

Nội dung tài liệu

Trang 1

Building an Enterprise Chatbot Work with Protected Enterprise Data Using Open Source Frameworks — Abhishek Singh Karthik Ramasubramanian Shrey Shivam

Trang 2

Building an Enterprise Chatbot Work with Protected Enterprise Data Using Open Source Frameworks Abhishek Singh Karthik Ramasubramanian Shrey Shivam

Trang 3

Building an Enterprise Chatbot: Work with Protected Enterprise Data Using Open Source Frameworks Abhishek Singh Karthik Ramasubramanian New Delhi, Delhi, India New Delhi, Delhi, India Shrey Shivam Donegal, Donegal, Ireland ISBN-13 (pbk): 978-1-4842-5033-4 ISBN-13 (electronic): 978-1-4842-5034-1 https://doi.org/10.1007/978-1-4842-5034-1 Copyright © 2019 by Abhishek Singh, Karthik Ramasubramanian, Shrey Shivam 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: Matthew Moodie Coordinating Editor: Aditee Mirashi Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail 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 rights@apress.com, or visit 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 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-5033-4. For more detailed information, please visit www.apress.com/source-code. Printed on acid-free paper

Trang 4

Abhishek and Karthik dedicate this book to their parents for their unwavering support and love. Shrey dedicates this book in memory of his grandparents, the late Mr. Ravindra Narayan Singh and late Dr. Ganga Prasad Singh, for being the source of his inspiration and pride.

Trang 5

Table of Contents About the Authors������������������������������������������������������������������������������xiii About the Technical Reviewer ����������������������������������������������������������xvii Acknowledgments�����������������������������������������������������������������������������xix Introduction���������������������������������������������������������������������������������������xxi Chapter 1: Processes in the Banking and Insurance Industries�����������1 Banking and Insurance Industries ������������������������������������������������������������������������1 A Customer-Centric Approach in Financial Services���������������������������������������������6 Benefits from Chatbots for a Business �����������������������������������������������������������������9 Chatbots in the Insurance Industry���������������������������������������������������������������������10 Automated Underwriting �������������������������������������������������������������������������������12 Instant Quotations �����������������������������������������������������������������������������������������13 AI-Based Personalized Experience����������������������������������������������������������������13 Simplification of the Insurance Buying Process��������������������������������������������13 Registering a Claim���������������������������������������������������������������������������������������13 Finding an Advisor�����������������������������������������������������������������������������������������13 Answering General Queries���������������������������������������������������������������������������14 Policy Status��������������������������������������������������������������������������������������������������14 Instant Notifications ��������������������������������������������������������������������������������������14 New Policy or Plan Suggestions��������������������������������������������������������������������14 Conversational Chatbot Landscape���������������������������������������������������������������������14 Summary�������������������������������������������������������������������������������������������������������������17 v

Trang 6

Table of ConTable of ConTTenenTTss Chapter 2: Identifying the Sources of Data�����������������������������������������19 Chatbot Conversations����������������������������������������������������������������������������������������19 General Conversations�����������������������������������������������������������������������������������20 Specific Conversations����������������������������������������������������������������������������������20 Training Chatbots for Conversations�������������������������������������������������������������������21 Self-Generated Data��������������������������������������������������������������������������������������22 Customer Interactions�����������������������������������������������������������������������������������23 Customer Service Experts�����������������������������������������������������������������������������25 Open Source Data������������������������������������������������������������������������������������������26 Crowdsourcing ����������������������������������������������������������������������������������������������26 Personal Data in Chatbots�����������������������������������������������������������������������������������27 Introduction to the General Data Protection Regulation (GDPR)��������������������������29 Data Protected Under the GDPR ��������������������������������������������������������������������29 Data Protection Stakeholders������������������������������������������������������������������������30 Customer Rights Under the GDPR������������������������������������������������������������������30 Chatbot Compliance to GDPR ������������������������������������������������������������������������32 Summary�������������������������������������������������������������������������������������������������������������33 Chapter 3: Chatbot Development Essentials���������������������������������������35 Customer Service-Centric Chatbots��������������������������������������������������������������������35 Business Context�������������������������������������������������������������������������������������������36 Policy Compliance �����������������������������������������������������������������������������������������38 Security, Authentication, and Authorization���������������������������������������������������39 Accuracy of User Input Translation to Systems ���������������������������������������������41 Chatbot Development Approaches����������������������������������������������������������������������42 Rules-Based Approach����������������������������������������������������������������������������������43 AI-Based Approach����������������������������������������������������������������������������������������45 Conversational Flow��������������������������������������������������������������������������������������������47 vi

Trang 7

Table of ConTable of ConTTenenTTss Key Terms in Chatbots ����������������������������������������������������������������������������������������49 Utterance�������������������������������������������������������������������������������������������������������49 Intent�������������������������������������������������������������������������������������������������������������50 Entity �������������������������������������������������������������������������������������������������������������50 Channel ���������������������������������������������������������������������������������������������������������51 Human Takeover��������������������������������������������������������������������������������������������51 Use Case: 24x7 Insurance Agent�������������������������������������������������������������������������52 Summary�������������������������������������������������������������������������������������������������������������53 Chapter 4: Building a Chatbot Solution�����������������������������������������������55 Business Considerations�������������������������������������������������������������������������������������55 Chatbots vs� Apps������������������������������������������������������������������������������������������56 Growth of Messenger Applications����������������������������������������������������������������57 Direct Contact vs� Chat����������������������������������������������������������������������������������57 Business Benefits of Chatbots����������������������������������������������������������������������������58 Cost Savings��������������������������������������������������������������������������������������������������58 Customer Experience ������������������������������������������������������������������������������������59 Success Metrics��������������������������������������������������������������������������������������������������60 Customer Satisfaction Index��������������������������������������������������������������������������60 Completion Rate��������������������������������������������������������������������������������������������60 Bounce Rate��������������������������������������������������������������������������������������������������61 Managing Risks in Chatbots Service ������������������������������������������������������������������61 Third-Party Channels�������������������������������������������������������������������������������������61 Impersonation������������������������������������������������������������������������������������������������62 Personal Information�������������������������������������������������������������������������������������62 Confirmation Check���������������������������������������������������������������������������������������63 vii

Trang 8

Table of ConTable of ConTTenenTTss Generic Solution Architecture for Private Chatbots���������������������������������������������63 Workflow Description ������������������������������������������������������������������������������������64 Key Features��������������������������������������������������������������������������������������������������67 Technology Stack ������������������������������������������������������������������������������������������68 Maintenance��������������������������������������������������������������������������������������������������68 Summary�������������������������������������������������������������������������������������������������������������69 Chapter 5: Natural Language Processing, Understanding, and Generation �����������������������������������������������������������������������������������71 Chatbot Architecture�������������������������������������������������������������������������������������������73 Popular Open Source NLP and NLU Tools������������������������������������������������������������76 NLTK ��������������������������������������������������������������������������������������������������������������77 spaCy�������������������������������������������������������������������������������������������������������������77 CoreNLP���������������������������������������������������������������������������������������������������������79 gensim�����������������������������������������������������������������������������������������������������������80 TextBlob���������������������������������������������������������������������������������������������������������81 fastText����������������������������������������������������������������������������������������������������������82 Natural Language Processing�����������������������������������������������������������������������������82 Processing Textual Data ��������������������������������������������������������������������������������83 Word Search Using Regex�����������������������������������������������������������������������������85 Word Search Using the Exact Word���������������������������������������������������������������86 NLTK ��������������������������������������������������������������������������������������������������������������87 spaCy�������������������������������������������������������������������������������������������������������������94 CoreNLP�������������������������������������������������������������������������������������������������������106 TextBlob�������������������������������������������������������������������������������������������������������110 Multilingual Text Processing������������������������������������������������������������������������113 Natural Language Understanding ���������������������������������������������������������������������116 Sentiment Analysis��������������������������������������������������������������������������������������117 Language Models����������������������������������������������������������������������������������������118 viii

Trang 9

Table of ConTable of ConTTenenTTss Information Extraction Using OpenIE�����������������������������������������������������������133 Topic Modeling Using Latent Dirichlet Allocation�����������������������������������������136 Natural Language Generation ���������������������������������������������������������������������������141 Markov Chain-Based Headline Generator����������������������������������������������������142 SimpleNLG���������������������������������������������������������������������������������������������������145 Deep Learning Model for Text Generation ���������������������������������������������������152 Applications ������������������������������������������������������������������������������������������������������168 Topic Modeling Using spaCy, NLTK, and gensim Libraries���������������������������169 Gender Identification�����������������������������������������������������������������������������������175 Document Classification������������������������������������������������������������������������������179 Intent Classification and Question Answering���������������������������������������������184 Summary�����������������������������������������������������������������������������������������������������������191 Chapter 6: A Novel In-House Implementation of a Chatbot Framework��������������������������������������������������������������������������193 Introduction to IRIS �������������������������������������������������������������������������������������������194 Intents, Slots, and Matchers �����������������������������������������������������������������������������195 Intent Class��������������������������������������������������������������������������������������������������197 IntentMatcherService Class�������������������������������������������������������������������������198 The getIntent Method of the IntentMatcherService class����������������������������201 Matched Intent Class�����������������������������������������������������������������������������������205 Slot Class�����������������������������������������������������������������������������������������������������207 IRIS Memory������������������������������������������������������������������������������������������������������212 Long- and Short-Term Sessions������������������������������������������������������������������212 The Session Class����������������������������������������������������������������������������������������213 Dialogues as Finite State Machines������������������������������������������������������������������219 State������������������������������������������������������������������������������������������������������������221 Shields���������������������������������������������������������������������������������������������������������222 ix

Trang 10

Table of ConTable of ConTTenenTTss Transition�����������������������������������������������������������������������������������������������������223 State Machine ���������������������������������������������������������������������������������������������224 Building a Custom Chatbot for an Insurance Use Case�������������������������������������230 Creating the Intents�������������������������������������������������������������������������������������233 IrisConfiguration������������������������������������������������������������������������������������������243 Managing State �������������������������������������������������������������������������������������������271 Exposing a REST Service�����������������������������������������������������������������������������273 Adding a Service Endpoint ��������������������������������������������������������������������������277 Summary�����������������������������������������������������������������������������������������������������������278 Chapter 7: Introduction to Microsoft Bot, RASA, and Google Dialogflow�����������������������������������������������������������������������������281 Microsoft Bot Framework���������������������������������������������������������������������������������281 Introduction to QnA Maker���������������������������������������������������������������������������282 Introduction to LUIS�������������������������������������������������������������������������������������290 Introduction to RASA�����������������������������������������������������������������������������������������292 RASA Core ���������������������������������������������������������������������������������������������������294 RASA NLU����������������������������������������������������������������������������������������������������295 Introduction to Dialogflow���������������������������������������������������������������������������������296 Summary�����������������������������������������������������������������������������������������������������������301 Chapter 8: Chatbot Integration Mechanism��������������������������������������303 Integration with Third-Party APIs����������������������������������������������������������������������303 Market Trends����������������������������������������������������������������������������������������������304 Stock Prices�������������������������������������������������������������������������������������������������310 Weather Information������������������������������������������������������������������������������������316 Connecting to an Enterprise Data Store������������������������������������������������������������321 Integration Module��������������������������������������������������������������������������������������������325 x

Trang 11

Table of ConTable of ConTTenenTTss Demonstration of AskIris Chatbot in Facebook Messenger ������������������������������338 Account Balance������������������������������������������������������������������������������������������338 Claim Status������������������������������������������������������������������������������������������������339 Weather Today���������������������������������������������������������������������������������������������340 Frequently Asked Questions������������������������������������������������������������������������341 Context Switch Example������������������������������������������������������������������������������342 Summary�����������������������������������������������������������������������������������������������������������344 Chapter 9: Deployment and a Continuous Improvement Framework ���������������������������������������������������������������������������������������345 Deployment to the Cloud�����������������������������������������������������������������������������������345 As a Stand-Alone Spring Boot JAR on AWS EC2������������������������������������������346 As a Docker Container on AWS EC2�������������������������������������������������������������349 As an ECS Service���������������������������������������������������������������������������������������352 Smart IRIS Alexa Skill Creation in Less Than 5 Minutes������������������������������������357 Continuous Improvement Framework���������������������������������������������������������������368 Intent Confirmation (Double-Check)������������������������������������������������������������369 Predict Next Intent���������������������������������������������������������������������������������������371 A Human in the Loop�����������������������������������������������������������������������������������373 Summary�����������������������������������������������������������������������������������������������������������375 Index�������������������������������������������������������������������������������������������������377 xi

Trang 12

About the Authors Abhishek Singh is on a mission to profess the de facto language of this millennium, the numbers. He is on a journey to bring machines closer to humans, for a better and more beautiful world by generating opportunities with artificial intelligence and machine learning. He leads a team of data science professionals solving pressing problems in food security, cyber security, natural disasters, healthcare, and many more areas, all with the help of data and technology. Abhishek is in the process of bringing smart IoT devices to smaller cities in India so that people can leverage technology for the betterment of life. He has worked with colleagues from many parts of the United States, Europe, and Asia, and strives to work with more people from various backgrounds. In seven years at big corporations, he has stress-tested the assets of U.S. banks at Deloitte, solved insurance pricing models at Prudential, made telecom experiences easier for customers at Celcom, and created core SaaS data products at Probyto. He is now creating data science opportunities with his team of young minds. He actively participates in analytics-related thought leadership, authoring, public speaking, meetups, and training in data science. He is a staunch supporter of responsible use of AI to remove biases and fair use of AI for a better society. Abhishek completed his MBA from IIM Bangalore, a B.Tech. in Mathematics and Computing from IITGuwahati, and has a PG Diploma in Cyber Law from NALSAR University, Hyderabad. xiii

Trang 13

aaboubouTT TThehe aauuTThorshors Karthik Ramasubramanian has over seven years of practice in data science and business analytics in retail, FMCG, e-commerce, and information technology for a multi-national and two unicorn startups. He is a researcher and problem solver with a diverse set of experiences in the data science lifecycle, starting from a data problem discovery to creating a data science prototype/product. On the descriptive side of data science, he designed, developed, and spearheaded many A/B experiment frameworks for improving product features, conceptualized funnel analysis for understanding user interactions and identifying the friction points within a product, and designed statistically robust metrics and visual dashboards. On the predictive side, he developed intelligent chatbots which understand human-like interactions, customer segmentation models, recommendation systems, identified medical specialization from a patient query for telemedicine, and other projects. He actively participates in analytics-related thought leadership, authoring blogs and books, public speaking, meet-ups, and training and mentoring for data science. Karthik completed his M.Sc. in Theoretical Computer Science at PSG College of Technology, India, where he pioneered the application of machine learning, data mining, and fuzzy logic in his research work on the computer and network security. xiv

Trang 14

aaboubouTT TThehe aauuTThorshors Shrey Shivam has extensive experience in leading the design, development, and delivery of solutions in the field of data engineering, stream analytics, machine learning, graph databases, and natural language processing. In his seven years of experience, he has worked with various conglomerates, startups, and big corporations, and has gained relevant exposure to digital media, e-commerce, investment banking, insurance, and a suite of transaction-led marketplaces across the music, food, lifestyle, news, legal, and travel domains. He is a keen learner and is actively engaged in designing the next generation of systems powered by artificial intelligence-based analytical and predictive models. He has taken up various roles in product management, data analytics, digital growth, system architecture, and full stack engineering. In this era of rapid acceptance and adoption of new and emerging technologies, he believes in strong technical fundamentals and advocates continuous improvement through self-learning. Shrey is currently leading a team of machine learning and big data engineers across the U.S., Europe, and India to build robust and scalable big data pipelines to implement various statistical and predictive models. Shrey completed his BTech in Information Technology from Cochin University of Science and Technology, India. xv

Trang 15

About the Technical Reviewer Santanu Pattanayak currently works at GE, Digital as a Staff Data Scientist and is the author of Pro Deep Learning with TensorFlow - A Mathematical Approach to Advanced Artificial Intelligence in Python. He has 12 years of overall work experience with 8 years of experience in the data analytics/ data science field. He also has a background in development and database technologies. Prior to joining GE, Santanu worked at companies such as RBS, Capgemini, and IBM. He graduated with a degree in Electrical Engineering from Jadavpur University, Kolkata and is an avid math enthusiast. Santanu is currently pursuing a master’s degree in Data Science from Indian Institute of Technology (IIT), Hyderabad. He also devotes time to data science hackathons and Kaggle competitions where he ranks within the top 500 across the globe. Santanu was born and brought up in West Bengal, India and currently resides in Bangalore, India with his wife. xvii

Trang 16

Acknowledgments We are grateful to our teachers at various universities and their continued support in our professional lives. Abhishek Singh thanks his colleagues at Probyto who inspire him to write impactful content for better use of AI for public use; the idea of this book evolved through discussions with his colleagues and his work in the EU market. A special mention goes to his parents, Mr. Charan Singh and Mrs. Jayawati, for their intriguing insights on how to think about general human use of AI. Their support and demand for the simplistic design of solutions using AI-generated data inspires his day-to-day design of data products. Karthik is immensely grateful to his parents, Mr. S Ramasubramanian and Mrs. Kanchana, for their unwavering support throughout his life and during the development of this book. This book was made possible by hundreds of researchers who shared their life’s work as open-source offerings. He thanks all such researchers who make this world better and passionately share their work with everyone. Lastly, a large part of his work and success comes from his mentors and colleagues from work, where he continuously learns and improves. Shrey is hugely grateful to his parents, Mr. Vijay Pratap Singh and Mrs. Bharti Singh, for their love, care, and sacrifice in helping him fulfill his dreams. He expresses gratitude to his uncle, Mr. Tarun Singh, for being a pillar of strength. Shrey also thanks his past and current colleagues, including Dipesh Singh and Jaspinder Singh Virdee, for their continuous encouragement and support in taking up challenging and innovative ideas to execution. xix

Trang 17

aCaCknowledgmenknowledgmenTTss Finally, this book would not have been possible without the support of the Apress team: Aditee, Celestin, Matthew, and the production support staff. We also acknowledge and thank our Technical Reviewer (TR) for their critical reviews that helped to make the book even better. xx

Trang 18

Introduction There are numerous frameworks and propriety off-the-shelf chatbot offerings, but most do not clearly map out the much-needed control of data by an organization. Often the propriety offerings take an organization’s private data for training on the cloud and provide the outcome as a model. In this book, we will focus on data privacy and control over the development process. The chatbot that you will learn how to develop could be completely built in-house using open-source JAVA frameworks and NLP libraries in Python. The beginning of the book helps you understand the processes in the banking industry and delves into identifying the sources of data to mine for the intent from customer queries. The second part focuses on natural language processing, understanding, and generation, which are demonstrated using Python. These three concepts are the core components of a chatbot. In the final part, you take up the development of a chatbot called IRIS using open-source frameworks written in JAVA. The following are the key topics this book offers: • Identify the business processes where chatbots could be used in an industry and suitably guide the design in a solution architecture • Focus on building a chatbot for one industry and one use-case, rather than building a ubiquitous and generic chatbot • Natural language understanding, processing, and generation xxi

Trang 19

InInTTroduroduCTICTIonon • Learn how to deploy a complete in-house-built chatbot using an open source technology stack like RASA and Botpress (such chatbots avoid sharing any PIIs with any third-party tools) • Develop a chatbot called IRIS from scratch by customizing an existing open-source chatbot framework • Use APIs for chatbot integration with internal data sources • Deployment and continuous improvement framework through representational learning We hope you enjoy the journey. xxii

Trang 20

CHAPTER 1 Processes in the Banking and Insurance Industries According to Darwin’s On the Origin of Species, it is not the most intellectual of the species that survives; it is not the strongest that survives; the species that survives is the one that is best able to adapt and adjust to the changing environment in which it finds itself. The same analogy can apply to enterprises and their survival opportunities in the 21st century. In this digital era, it is of utmost importance for enterprises to adapt to the latest trends and technology advancements. With this book, we intend to prepare you with an emerging skill of building chatbots in the financial services domain, with a specific use case of an insurance agent (replicable to a bank assistant as well). Banking and Insurance Industries Banks and insurers have been in existence for a long time and facilitate economic activities for us. Banking and insurance play essential roles in the economic growth of a country and society. Both institutions provide the essential services of commercial transactions and covering risks. © Abhishek Singh, Karthik Ramasubramanian, Shrey Shivam 2019 1 A. Singh et al., Building an Enterprise Chatbot, https://doi.org/10.1007/978-1-4842-5034-1_1

Hiển thị 20 trang đầu. Tải tài liệu để xem đầy đủ.

Bình luận (0)

Đăng nhập để tham gia bình luận

Chưa có bình luận nào. Hãy là người đầu tiên!