Contents
Truth vs Fiction 2
History and Evolution 3
The Current State of Affairs 4
Commoditization of AI 4
Microsoft and AI 5
Basic Concepts 6
Machine Learning 9
Language 12
Speech 13
Computer Vision 14
Microsoft’s Cognitive Services 17
Vision18Speech 18
Language 19
Knowledge 19
Search 20
Recap 21
Prerequisites for Using Cognitive Services 24
Setting Up the Development Environment 24
Getting an Azure Subscription Key for Cognitive Services 24
Step 1: Set Up an Azure Account 25
Step 2: Create a New Cognitive Services Account 27
Step 3: Get the Subscription Key(s) 29
Testing the API 30
What You Want To Do 31
How To Do It 31
Creating Your First AI-based Application 33
The Code 34
The Walkthrough 36
The Result 38
Making Your Application More Interesting 39
Extracting Text Out of Images 39
The Code 39
The Walkthrough 41
The Result 42
Recap 43
What Is a Conversational User Interface? 47
A Brief History 47
In the Very Beginning: the Command-Line Interface (CLI) 47
And Then Came the Graphical User Interface 49
And UI Evolved Yet Again: Conversational User Interface 51
AI’s Role in CUI 52
Pitfalls of CUI 53
A Hybrid UI (CUI+GUI) May Be the Future 55
Design Principles 57
Microsoft Bot Framework 58
Creating a CUI Application Using Bot Framework 58
Step 0: Prep Your Development Environment 59
Step 1: Create a New Bot Application Project 60
Step 2: First and Default Messages 60
Step 3: Running, Testing, and Debugging Your Bot 62
Step 3: Appointment Scheduling 65
Step 4: Handling System Messages 68
Next Steps 68 Recap 69
What Is NLU? 72
History of Natural Language Understanding 74
Why Natural Language Is Difficult for Machines to Understand 77
Complexities in Natural Language 77
Statistical Models as a Solution Are Insufficient 79
A Promising Future 80
Language Understanding Intelligent Service (LUIS) 80
Architecture of a LUIS-Based Software Application 81
Behind the Scenes 84
Extensive Training Is the Key 85
Getting an Azure Subscription for LUIS 86
Getting Subscription Keys on Azure Portal 87
Applying Subscription Keys in LUIS 88
Demo: Definition App 89 Notes 91
Recap 92
■Chapter 5: Exploring a Cognitive Language Model 93
The Bing Spell Check API 93
What Is It? 95
How To Use It 96
Integration with LUIS 99
The Text Analytics API 101
Language Detection 102
Key Phrase Extraction 105
Sentiment Analysis 108
Topic Detection 110
Usage Ideas 113
The Web Language Model (WebLM) API 114
Word Breaking 116
Joint Probability 117
Conditional Probability 119
Next Word Prediction 120
The Linguistic Analysis API 121
Sentence Separation and Tokenization 122
Part-of-Speech Tagging 125
Constituency Parsing 127
Recap 130
Planning Your App 131
What Should the Bot Be Able to Do? 132
What Information Does the Bot Need from the User? 132
What Should Be Done in LUIS? 132
What Should Be Done in the Bot Framework? 134
Creating a LUIS App 134
Adding Intents 135
Adding/Labeling Utterances 135
Publishing Your App 137
Adding Entities 139
Simple Entities 141
Composite Entities 142
Hierachical Entities 145
Prebuilt Entities 147
Adding a Phrase List 149
Suggested Next Steps 150
Active Learning Through Suggested Utterances 150
Using LUIS Programmatic API for Automation 151
Integrating LUIS with the Bot Framework 151
Creating a Project in Visual Studio 151
Handling an Entity-less Intent 152
Setting Up Your Bot to Use HealthCheckupDialog 153
Testing the Bot in an Emulator 153
Handling an Entity-Full Intent 154
Handling an Intent with Composite Entities 156
Handling the None Intent 158
Adding Your Bot to Skype 158
Publishing Your Bot 158
Registering Your Bot 159
Recap 160
Ways to Interact with Speech 162
The Cognitive Search API 163
Speech Recognition 164
Getting Started 164
Getting the JSON Web Token First 164
The Consume Speech API 166
Speech Synthesis 167
Speech Recognition Internals 170
Custom Speech Service 171
Custom Acoustic Model 171
Custom Language Model 180
Pronunciation Data 182
Custom Speech-to-Text Endpoint 183
Speaker Recognition 185
Speaker Verification vs Speaker Identification 186
Enrollment-Verification 186
Speaker Verification 189
Enrollment–Identification 190
Speaker Recognition-Identification 191
Operation Status 191
Summary 192
Search Is Everywhere 193
Pervasive, Predictive, Proactive (The Three Ps of Search) 195
History of Bing 196
What’s So Unique About Bing? 197
Search APIs 197
Bing Autosuggest API 198
How to Consume the Bing Autosuggest API 199
The Bing Image Search API 202
How to Consume the Bing Image Search API 203
Bing News Search API 208
Bing Video Search API 211
How to Consume the Bing Video Search API 212
Bing Web Search API 215
How to Consume the Bing Web Search API 216
Summary 219
■Chapter 9: Working with Recommendations 221
Understanding the Basics 222
Frequent Brought Together (FBT) Recommendations 223
Item-to-Item Recommendations 224
Recommendations Based on Past History 224
How Do These Recommendations Work? 225
Recommendation Models and Types 229
Recommendation Build 230
Frequent Brought Together (FBT) Build 234
Ranking Recommendation 236
SAR (Smart Adaptive Recommendations) Build 238
Setting Rules in Build 240
Offline Evaluation 241
Recommendation UI 242
Summary 246
Why Is AI So Popular? 247
Improved Computing Power 248
Inventions in AI Algorithms 249
Data Is the New Currency 249
Emergence of Cloud Computing 251
Services vs Solutions? 251
Cognitive Categories 252
Challenges and the Future of NLU 252
Challenges and Future of Speech 253
Challenges and the Future of Search 253
Challenges and the Future of Recommendations 254
AI First 255
Intelligent Edge 255
Tasks, not Jobs, Will Be Eliminated 256
So Where Do We Go From Here? 258
Index 261
Introduction
This book will introduce you to the world of artificial intelligence. Normally, developers think of AI implementation as a tough task involving writing complex algorithms and hundreds of lines of code. This book aims to remove the anxiety by creating a cognitive application with a few lines of code. There is a wide range of Cognitive Services APIs available. This book focuses on some of the most useful and powerful ways that your application can make intelligent use of Microsoft Cognitive API. Microsoft has given developers a better experience and enabled them through Microsoft Cognitive APIs.The book covers genuine insights into AI concepts. Speech, language, and search are such deep-dive domains that each of these concepts would require a separate book. This book attempts to explain each of the concepts by first explaining why and what before delving into the how of any API. The book also provides extensive examples to make it easier to put the new concepts into practice. Artificial Intelligence for .NET: Speech, Language, and Search will show you how to start building amazing capabilities into your applications today.This book starts by introducing you to artificial intelligence via its history, terminology, and techniques. The book then introduces you to all of the Microsoft Cognitive APIs and tools before building your first smart Cognitive application step by step using Visual Studio. The book then introduces concepts around the conversational user interface (CUI), and then you create your first bot using the Microsoft Bot Framework. The book also provides great context for understanding and best practices about planning your application using the Bot Framework.The book also provides a deep understanding about natural language understanding (NLU) and natural language processing (NLP), which let computer programs interpret humans the way they do each other. The book goes into detail about the Microsoft Language Understanding Intelligent Service (LUIS) and its concepts, as well as on how to design, consume, and apply LUIS before creating a LUIS project from scratch. The book also provides detailed steps on testing, training, and publishing a LUIS application before deploying and using it in a Bot Framework.Speech is the most natural form of interaction. This book provides a deep walk-through of the Speech API and how to use the API for speech recognition and speech synthesis. The book then provides a deep understanding of how to use the custom speech service previously known as CRIS and a step-by-step plan for creating your first language model, an audio model, and deploying it, and using the custom speech service. The book also provides detail into understanding speaker recognition.The book then explains all Bing Search APIs in detail and how to leverage Bing search offerings in your applications. The book also goes in detail about the concepts behind and types of recommendations, and then uses each of them to fetch recommendations in a step-by-step approach. The book ends by giving you a glimpse into the future of AI and what to expect soon. In other words, the book can be treated as a guide to help you drive your next steps.
In this book, you will :
• Explore the underpinnings of artificial intelligence through practical examples and scenarios
• Get started building an AI-based application in Visual Studio
• Build a text-based conversational interface for direct user interaction
• Use the Cognitive Services Speech API to recognize and interpret speech
• Look at different models of language, including natural language processing, and how to apply them in your Visual Studio application
• Reuse Bing search capabilities to better understand a user’s intention
• Work with recommendation engines and integrate them into your apps
Who This Book Is For
Artificial intelligence is the buzzword of the current industry. People are talking about AI. With this disruption going on everywhere, developers can get confused about where and how to get started with AI. The release of the Microsoft Cognitive APIs offers a wide range of new functionality for developers. This book is targeted towards novice and intermediate readers who are curious about artificial intelligence. Developers and architects with previous experience or no experience with .NET who want to apply the new Cognitive APIs to their applications will benefit greatly from the discussion and code samples in this book. This book also serves as a great resource for application developers and architects new to AI and/or the core concepts of using some of the Cognitive APIs.
Prerequisites
To get the most out of this book, you just need the .NET Framework and an Internet connection. I recommend using Microsoft Visual Studio 2017 as the development environment to experiment with the code samples, which you can find in the Source Code section of the Apress website.
Obtaining Updates for This Book
As you read through this text, you may find the occasional grammatical or code error (although I sure hope not). If this is the case, my sincere apologies. Being human, I am sure that a glitch or two may be present, regardless of my best efforts. You can obtain the current errata list from the Apress website (located once again on the home page for this book), as well as information on how to notify me of any errors you might find.