Book Image

AI Blueprints

By : Dr. Joshua Eckroth, Eric Schoen
Book Image

AI Blueprints

By: Dr. Joshua Eckroth, Eric Schoen

Overview of this book

AI Blueprints gives you a working framework and the techniques to build your own successful AI business applications. You’ll learn across six business scenarios how AI can solve critical challenges with state-of-the-art AI software libraries and a well thought out workflow. Along the way you’ll discover the practical techniques to build AI business applications from first design to full coding and deployment. The AI blueprints in this book solve key business scenarios. The first blueprint uses AI to find solutions for building plans for cloud computing that are on-time and under budget. The second blueprint involves an AI system that continuously monitors social media to gauge public feeling about a topic of interest - such as self-driving cars. You’ll learn how to approach AI business problems and apply blueprints that can ensure success. The next AI scenario shows you how to approach the problem of creating a recommendation engine and monitoring how those recommendations perform. The fourth blueprint shows you how to use deep learning to find your business logo in social media photos and assess how people interact with your products. Learn the practical techniques involved and how to apply these blueprints intelligently. The fifth blueprint is about how to best design a ‘trending now’ section on your website, much like the one we know from Twitter. The sixth blueprint shows how to create helpful chatbots so that an AI system can understand customers’ questions and answer them with relevant responses. This book continuously demonstrates a working framework and strategy for building AI business applications. Along the way, you’ll also learn how to prepare for future advances in AI. You’ll gain a workflow and a toolbox of patterns and techniques so that you can create your own smart code.
Table of Contents (14 chapters)
AI Blueprints
Foreword
Contributors
Preface
Other Books You May Enjoy
Index

Preface

Artificial intelligence (AI) is the hot new thing. Though AI has been around for 50 years, recent dramatic advances in the kinds of problems it can solve and the availability of open source software have opened it up to all programmers and organizations. AI technology can magnify the capabilities of an organization and its software, or open entirely new pursuits. For example, in Chapter 5, A Blueprint for Detecting Your Logo in Social Media, we show how to use deep learning to detect a company's logos in photos shared publicly on Twitter. Without such an AI tool, these photos would probably never be noticed, and the company would not be able to identify how their products and services connect with individuals' everyday lives. The data is there. Twitter, Reddit, news services, and others have public APIs that expose their continuous feeds of comments, photos, videos, news articles, and more. But nobody has time to look at all of that, and searches and filters do not work on photos. AI completely changes the rules.

My goal with this book is to change your expectation of where AI can be used in your applications, while giving you the power to build your own AI-powered applications. By covering a broad range of applications and technologies, I hope to show that there is not one single kind of AI (such as deep learning), nor a single kind of application.

We cover applications in planning (Chapter 2, A Blueprint for Planning Cloud Infrastructure), natural language processing (Chapter 3, A Blueprint for Making Sense of Feedback and Chapter 7, A Blueprint for Understanding Queries and Generating Responses), recommendation engines (Chapter 4, A Blueprint for Recommending Products and Services), deep learning (Chapter 5, A Blueprint for Detecting Your Logo in Social Media), logic programming (Chapter 7, A Blueprint for Understanding Queries and Generating Responses), and trend and anomaly detection (Chapter 6, A Blueprint for Discovering Trends and Recognizing Anomalies).

These applications show AI can help an organization with logistics and automation, customer relations, and marketing. These applications are not designed to replace human workers – instead, each project automates tedious aspects of work and provides new insights to knowledge workers. For example, Chapter 3, A Blueprint for Making Sense of Feedback shows how to analyze social media comments and news articles to gather detailed data about sentiment (positive or negative) about certain topics of interest. With this data, marketing experts can gauge whether a marketing campaign was successful, for example, or make an informed judgment about when to introduce a new product.

The time for AI is now. We are presently in an era where the (justified) hype for AI is strong. Consider these hypothetical headlines: "Hospital begins using AI to help with cancer diagnosis," "University uses AI to ensure on-time graduation," "Marketing firm builds AI to better target consumers," "Airline streamlines boarding process with AI." Each headline refers to some improvement, and AI is suggested to be the cause of the improvement. But what if we had replaced "uses AI" or "builds AI" with "adds staff" or "hires firm"? For example, "Airline streamlines boarding process with more gate agents and roped walkways..." It would feel like more of the same, not a revolutionary new approach.

There is something about AI that gives it a mysterious, optimistic, dreamy quality. AI can do anything! And whatever it does, it will be completely novel! Even if AI determined that a streamlined airplane boarding process can be accomplished by more roped walkways, travelers would likely marvel at the result.

"AI found this to be the optimal configuration!" In some sense, the more alien the result, the more likely we are to believe it came from AI and it is indeed optimal.

But they're not wrong. AI is different. AI is perpetually new. AI always promises that something we could not do yesterday can now be done with ease. Again, they're not wrong, though the hype can run away with itself sometimes.

I hope this book shows that AI is the future, it is available now, and it is here to stay.

Who this book is for

This book is targeted at software engineers who are familiar with Java and Python and wish to learn how to use artificial intelligence and machine learning in their code. This book is not just a list of techniques and algorithms, however. Every example project includes a detailed discussion of integration and deployment strategies and techniques for continuous evaluation of the AI after it is deployed. The projects and suggested workflow target small/medium businesses and startup companies that wish to introduce advanced capabilities and automation into an existing platform.

What this book covers

Chapter 1, The AI Workflow, introduces the AI workflow, which is a series of four steps in a mature process for building and deploying AI. This chapter also discusses the role of AI in context of a larger software system. The chapter ends with an introduction to each of the projects developed in Chapter 2, A Blueprint for Planning Cloud Infrastructure to Chapter 7, A Blueprint for Understanding Queries and Generating Responses.

Chapter 2, A Blueprint for Planning Cloud Infrastructure, shows how to use the open source OptaPlanner constraint solver planning engine to create a plan for cloud computing resources.

Given a time and money budget and a set of computing tasks to complete, this chapter develops a Java-based solution for the optimal number of cloud resources to complete the tasks in the shortest time and lowest budget. Benchmarks are detailed to show that the solution is accurate. Each step of the AI workflow is addressed to help readers prepare to deploy the solution.

Chapter 3, A Blueprint for Making Sense of Feedback, shows how to acquire feedback from customers and the general public about a company's products and services, and how to identify the sentiment, or general mood, of the feedback for particular products, services, or categories. The Twitter and Reddit APIs are demonstrated for acquiring feedback.

Two approaches are demonstrated for sentiment analysis: a dictionary-based approach and a method using machine learning with the CoreNLP library. The sentiment data is then visualized with plotly.js in a dashboard view for real-time updates. Each step of the AI workflow is addressed to help readers prepare to deploy the solution.

Chapter 4, A Blueprint for Recommending Products and Services, shows how to build and deploy a recommendation engine for products and services. Given a history of all user activity (purchases, clicks, ratings), a system is designed that can produce appropriate recommendations for individual users. An overview of the relevant mathematics is included, and the Python implicit library is used for building the solution. A continuous evaluation methodology is detailed to ensure the recommender continues to provide appropriate recommendations after it is deployed. Each step of the AI workflow is addressed to help readers prepare to deploy the solution.

Chapter 5, A Blueprint for Detecting Your Logo in Social Media, shows how to build a convolutional neural network (CNN) to detect logos in other people's photos. Using the Python library TensorFlow, readers are shown how to take an existing pre-trained object recognition model such as Xception and refine it for detecting specific objects using a small training set of images. We also demonstrate the use of YOLO and compare results.

Then the Twitter API code from Chapter 3, A Blueprint for Making Sense of Feedback is reused to acquire images from social media, and the detector is run on these images to pick out photos of interest. A short introduction to CNNs and deep learning is included. Each step of the AI workflow is addressed to help readers prepare to deploy the solution.

Chapter 6, A Blueprint for Discovering Trends and Recognizing Anomalies, explains how to discover and track trends on a blog, storefront, or social media platform, as well as recognizing anomalous events that defy the trends. Using statistical models and anomaly detection algorithms, code is developed with the Python library scikit-learn. Different approaches are compared to address different use cases. Each step of the AI workflow is addressed to help readers prepare to deploy the solution.

Chapter 7, A Blueprint for Understanding Queries and Generating Responses, shows how to build and deploy an automated helpdesk chatbot. Using the Rasa Python library and Prolog coding, two custom chatbots are developed that examine the user's question and construct an appropriate answer using natural language generation. The Prolog code helps us develop a logical reasoning agent that is able to answer complex questions. Each step of the AI workflow is addressed to help readers prepare to deploy the solution.

Chapter 8, Preparing for Your Future and Surviving the Hype Cycle, examines the current state and near future of artificial intelligence. It examines the hype cycle and the dramatic shifts in popular interest in AI over the years and provides guidance for how to be successful in such unpredictable environments. The chapter includes advice for how to identify new approaches and advances in AI and how to decide whether or not these advances are relevant for real business needs.

What you need for this book

This book uses state-of-the-art techniques and software libraries. For whatever reason, the original development of these libraries is typically done on Linux or macOS machines before being ported to Windows. Thus, it is possible some libraries might be difficult to install on a Windows machine, though Microsoft's Ubuntu on Windows 10 technology is helping close this gap. For example, TensorFlow has supported Windows for several years but difficulties installing it remained even in 2017 (https://github.com/tensorflow/tensorflow/issues/42).

Libraries are rapidly changing, so there is little use in detailing installation procedures in this Preface. A list of required libraries for each chapter are provided on this book's code repository: https://github.com/PacktPublishing/ProgrammingAIBusinessApplications. Installation procedures differ for each library and sometimes change as new versions are released. These instructions may be found on the library's linked homepage.

I intentionally chose to use state-of-the-art libraries even though they undergo rapid development and change. This change is usually for the better, but sometimes new versions break existing code or cannot be installed without some effort. However, I felt that it would not be helpful to write a book about old technology. For example, all Python applications in this book use Python 3.6 (or later) even though many may still work with minor changes in a Python 2.7 environment. Likewise, we use TensorFlow 1.10, the latest release at the time of writing. Books with code designed for TensorFlow 0.12, for example, will need significant updates, even though 0.12 was released less than two years ago.

Speaking of TensorFlow, if you have a GPU, you will find the code we develop in Chapter 5, A Blueprint for Detecting Your Logo in Social Media to be significantly more efficient, and better (more expensive) GPUs give even more performance gains. Even so, TensorFlow will still work with just a CPU.

Download the example code files

You can download the example code files for this book from your account at http://www.packt.com. If you purchased this book elsewhere, you can visit http://www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at http://www.packt.com.

  2. Select the SUPPORT tab.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box and follow the on-screen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/ProgrammingAIBusinessApplications. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781788992879_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example; "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

[default]
exten => s,1,Dial(Zap/1|30)
exten => s,2,Voicemail(u100)
exten => s,102,Voicemail(b100)
exten => i,1,Voicemail(s0)

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[default]
exten => s,1,Dial(Zap/1|30)
exten => s,2,Voicemail(u100)
exten => s,102,Voicemail(b100)
exten => i,1,Voicemail(s0)

Any command-line input or output is written as follows:

# cp /usr/src/asterisk-addons/configs/cdr_mysql.conf.sample
     /etc/asterisk/cdr_mysql.conf

Bold: Indicates a new term, an important word, or words that you see on the screen, for example, in menus or dialog boxes, also appear in the text like this. For example: "Select System info from the Administration panel."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at .

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book we would be grateful if you would report this to us. Please visit, http://www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.