A Developer's Guide to Building AI Applications
Total Page:16
File Type:pdf, Size:1020Kb
A Developer’s Guide to Building AI Applications Create Your First Intelligent Bot with Microsoft AI Anand Raman and Wee Hyong Tok Beijing Boston Farnham Sebastopol Tokyo A Developer’s Guide to Building AI Applications by Anand Raman and Wee Hyong Tok Copyright © 2018 O’Reilly Media, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online edi‐ tions are also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/institutional sales department: 800-998-9938 or [email protected]. Editor: Nicole Tache Interior Designer: David Futato Production Editor: Nicholas Adams Cover Designer: Karen Montgomery Copyeditor: Octal Publishing, Inc. Illustrator: Rebecca Demarest May 2018: First Edition Revision History for the First Edition 2018-05-24: First Release The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. A Developer’s Guide to Building AI Applications, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsi‐ bility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. This work is part of a collaboration between O’Reilly and Microsoft. See our statement of editorial independence. 978-1-492-03784-2 [LSI] Table of Contents A Developer’s Guide to Building AI Applications. 1 Introduction 1 The Intersection of Cloud, Data, and AI 4 The Microsoft AI Platform 9 Developing an Intelligent Chatbot 11 Adding “Plug and Play” Intelligence to Your Bot 33 Building an Enterprise App to Gain Bot Insights: The Conference Buddy Dashboard 36 Paving the Road Ahead 43 iii A Developer’s Guide to Building AI Applications Introduction Artificial Intelligence is rapidly becoming a mainstream technology that is help‐ ing transform and empower us in unexpected ways. Let us take a trip to remote Nepal to see a fascinating example. Like the vast majority of Nepalese, Melisha Ghimere came from a remote village from a family of subsistence farmers who raised cows, goats, and water buffalos. Seven years ago, she watched her relatively wealthy uncle and aunt lose a lot of their herd to an outbreak of anthrax; they were never to recover their economic footing. Melisha went on to college think‐ ing about the plight of her family. In college, she worked to develop a predictive early warning solution to help farmers. With a team of four students, they researched livestock farming, veterinary practices, and spoke to farmers. They built a prototype for a monitoring device that tracks temperature, sleep patterns, stress levels, motion, and the activity of farm animals. Melisha’s AI system pre‐ dicts the likely health of each animal based on often subtle changes in these observations. Farmers are able to track their animals, receive alerts, and actiona‐ ble recommendations. Although her project is still in its infancy, the field tests have shown the solution was about 95% accurate in predicting risks to an ani‐ mal’s health. Melisha and her team were able to help a family prevent a deadly outbreak of an anthrax infection by identifying a diseased cow, before symptoms were evident to the farmer. Melisha’s team was a regional finalist in Microsoft’s Imagine Cup competition in 2016.1 Let me give you another example much closer to home, the power of AI in trans‐ forming the retail experience. Lowes Innovation Labs has now created a unique prototype shopping experience for home remodeling. For example, a customer 1 The Future Computed—Artificial Intelligence and its role in society—Microsoft 1 can now walk in and share her dream kitchen photos with a design specialist. Using an AI-powered application, the design specialist gains deep insight into the customer’s style and preference. The application generates a match from the Lowe’s dream kitchen collection, and the design of the kitchen is then shown in very realistic holographic mixed-reality through a Hololens.2 The customer can now visualize, explore, and change the design to his taste in the mixed reality environment in real time. Applications like these are vanguards of the revolution in retail experiences that AI will bring for consumers. Healthcare is another field that is at the cusp of a revolution. With the power of AI and a variety of data sources from genomics, electronic medical records, med‐ ical literature, and population data, scientists are now able to predict health emergencies, diagnose better, and optimize care. A unique example in this area comes from Cochrane, a highly reputed nonprofit organization dedicated to gathering and summarizing the best evidence from research to help doctors make informed choices about treatment. Cochrane conducts systematic reviews, which digests and analyzes explosively growing medical literature, and reduces it into fairly short and manageable pieces of work to give doctors the best possible guidance on the effects of healthcare interventions. For example, a recent system‐ atic review of medical studies looked at whether steroids can help with the matu‐ ration of premature babies’ lungs. The review showed conclusively that steroids can help save the babies’ lives. This intervention has helped hundreds of thou‐ sands of premature babies. However, such reviews are very labor intensive and can take two to three years to complete. Cochrane’s Project Transform was born out of the need to make systematic reviews more efficient, give more timely and relevant guidance to doctors, and therefore help save more lives. Project Trans‐ form uses AI to manipulate and analyze the literature and data very efficiently and therefore allow researchers to understand the data and interpret the findings. It creates a perfect partnership between human and machine, where a significant amount of the heavy overhead of systematic reviews is reduced, and the human analysis skills can be directed where they are most needed for timeliness and quality. There’s no field that will be left untouched by the transformational power of AI. I can point you to fields as diverse as astronomy where AI has accelerated the pace of new discoveries, and the area of conservation where ecologists and conserva‐ tionists are working with AI-powered tools to help track, study, and protect elu‐ sive and endangered animals. 2 http://www.lowesinnovationlabs.com/hololens 2 | A Developer’s Guide to Building AI Applications A lot of times we become bogged down in the discussions of the appro‐ priate algorithm or tools, but the real power of AI resides in the ideas and questions that precede it. It’s the conservationist pondering on how to create sustainable habitats, the doc‐ tor wondering how to better serve their patient, the astronomer’s and citizen sci‐ entist’s curiosity that expands our collective consciousness to the outer limits of the universe. AI has the potential to empower the noblest of human causes, and we are just at the beginning. The field is still nascent, and yet these breakthroughs highlight the explosive power of AI in reshaping our daily experiences, how we do business, and how we live our lives. Five decades ago, the early inventors in AI could only dream of what most con‐ sumers take for granted today. From voice-powered assistants like Cortana, Siri, or Alexa, to smartphones and self-driving cars, we seem to be living in “sci-fi” pages. What do the next two decades hold for us? Five decades? At Microsoft, we have made it our mission to advance AI innovations by democratizing AI tools in the same way that we democratized the power of computing in the mainframe era by envisioning a personal computer in every home, school, and workplace. As educator and computing pioneer Alan Kay said, “The best way to predict the future is to create it.” In the same spirit, we are writing this book to give develop‐ ers a start on creating the future with AI. In this book, we will show you how to create your first AI application in the cloud, and in the process learn about the wealth of AI resources and capabilities that are now rapidly becoming available to programmers. The application we create will be an AI-infused Bot, a “Confer‐ ence Buddy,” that helps create a novel Question and Answer experience for the attendees and speakers participating in a conference. As we build this Bot, you will get a glimpse into how AI can help understand conversations, perceive vast amounts of information, and respond intelligently. In the process, you will also get a glimpse into the landscape of AI tools and emerging developments in the field. We selected a chatbot as our example because it is a relatively easy entry point into AI, and in the process we highlight resources and links to help you dig deeper. Chatbots are also ubiquitous, with interesting implementations, and transforming the way in which we interact with computers. We also give you a wider lens on the landscape of AI tools and a glimpse into exciting new develop‐ ments in the field. Here’s a roadmap to the contents of this book: Introduction | 3 “The Intersection of Cloud, Data, and AI” In the rest of this section, we will introduce AI and the powerful intersection of data, cloud, and AI tools that is creating a paradigm shift, helping enable systems of intelligence.