2019 Cloud Computing Predictions
2018 was a banner year in cloud computing, with Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP) all continuing to launc...Learn More
Chatbots are a powerful example of artificial intelligence (AI) in use today. Just think about Google Assistant and how intelligent the platform became thanks to machine learning. But, what is a chatbot? How do you create a custom bot for your website? Which technologies can you use to build it? In this blog post, you will find the answers to these questions through practical examples. Using Python and Dialogflow frameworks, you’ll build a cloud infrastructure for astoundingly intelligent chatbots. At the end of this tutorial, your chatbot will be able to understand the intents of your users and give them the information they are searching for, taking advantage of Google AI.
Chatbots are software systems created to interact with humans through chat. The first chatbots were able to create simple conversations based on a complex system of rules. The limits of these systems have been overcome by chatbots that use AI and machine learning to interpret the intents of their interlocutor.
Chatbots can help in many practical cases and drastically reduce management costs. There are many examples that have become well-known successful use cases. For example, retailer H&M uses them to guide users through their purchase process on their website. In general, many support systems use chatbots to achieve operational efficiency, including answering common questions or helping users solve repetitive tasks. And some of them are very complex, such as those offering commercial offers or giving advice as a robo-advisor.
Using a chatbot in your company can offer many advantages:
There are many types of chatbots that can be found online. Some of them do not require programming skills, much less knowledge of machine learning or natural language processing. Examples of this kind of chatbots are Rasa, Octane Ai, Massively, or ManyChat. However, the incredible rise of machine learning systems makes chatbots evolve. If you are interested in learning more, I recommend starting from one of our Learning Paths on how to use artificial intelligence cloud systems.
There are also very common systems that use AIML (Artificial Intelligence Markup Language) to model smart conversational systems. Today, the most widely used chatbots are those made available by major vendors such as Google, AWS and Microsoft. We all know Alexa, Cortana, and Google Assistant. You should carefully consider their service offerings when you are choosing the technology stack for your chatbot. All three of these big vendors provide reliable and scalable cloud computing services that will help you to implement and customize your chatbot according to your needs. By now, most famous platforms to easily create text or voice-based bots are the following:
Among all the services taken into consideration, Dialogflow is certainly one of the most impressive. The power of Google’s machine learning makes the difference: the natural language processing (NLP) engine is among the best on the market. As indeed its slogan recites: “Dialogflow is user-friendly, intuitive and makes sense”. It is also very easy to integrate with Google Cloud Speech-to-Text and third-party services such as Google Assistant, Amazon Alexa, and Facebook Messenger.
This tutorial is now divided into two parts. The first part shows you how you can configure the chatbot and does not require programming skills as it will be entirely done in the Google console. The second part shows you how to integrate the chatbot with your services and it requires a basic knowledge of Python.
Setting up Dialogflow is very easy:
Dialogflow is based on two main concepts: intent and context. The intent is to accurately identify the purpose of the sentence that the user has sent to the bot. On the other side, the context is used to give coherence and fluency to the discussion, preserving the key concepts that have already been used in the conversation.
A further key concept is that of the entities, which allow you to identify common or parametrically recurring concepts in the discussion. There are a number of predefined types of entities that the system provides ready to use, such as dates or colors. Using these values you can make the chatbot very versatile.
For this tutorial, however, we will show a basic example and focus on intents only.
Once you created the agent, let’s start by defining some intents through the Dialogflow interface. The first thing I suggest to do is always use the graphical interface on the right to test our real-time chatbot.
As you can see in the Figure 4, just write in the “Try it now” form to get an answer. If you have not yet defined any intent, the system will use the fallback intent. In this way, you will prevent the discussion from coming to a standstill. Actually, this is a big advantage for us, but please pay attention and use this feature intelligently to bring the conversation to the right intent.
Now browse the “Default fallback intent”. Take a look at the full list of all “Responses”. They have already been defined for you. When the intent is matched, the chatbot engine randomly selects an item as the answer. Now it’s time to create one or more intents: use the console ensuring to also fill in the “Training phrases” form. In fact, these are the sentences that you expect from the user and that will trigger the intent. The more detailed you are in compiling sentences, the more precise the chatbot will be in identifying the intent. Finally, proceed by inserting more intents and always remember to progressively test the results using the helper on the right.
After each change you make and test, remember to save your progress by clicking on the “Save” button, so the machine learning model can train.
As you can see, it is possible to reach a good result even with the configuration of intents only. The Google NLP engine is doing most of the job for you. If you’re feeling confident (and if your use case requires it) you can start adding a context to your intents. You can even pass parameters between one intent and another, maintaining the context of the discussion. When you are satisfied with the level achieved, we will proceed with the next step: integrating the bot into our site!
There are two ways that you can integrate a Dialogflow chatbot into your website: using a widget or using Python.
The easiest way to integrate Dialogflow into an HTML page is to use the iframe. Select “Integrations” from the menu on the left and make sure that “Web Demo” is enabled. Simply copy and paste the HTML code to view the agent directly on your site.
The following script allows you to call Dialogflow using Python 3. You can find the client on GitHub for free. The script initializes a client session that takes the intent as input and finally returns a response, the so-called “fulfillment”, and the corresponding confidence as a decimal value. The sentence for which we want to get an answer is saved in the variable named “text_to_be_analyzed”. Edit the script by adding your sentence. Using Python, it is easy to create more custom logic. For example, you can catch a particular intent and then trigger a custom action.
"""Install the following requirements: dialogflow 0.5.1 google-api-core 1.4.1 """ import dialogflow from google.api_core.exceptions import InvalidArgument DIALOGFLOW_PROJECT_ID = 'google-project-id' DIALOGFLOW_LANGUAGE_CODE = 'en-US' GOOGLE_APPLICATION_CREDENTIALS = '1234567abcdef.json' SESSION_ID = 'current-user-id' text_to_be_analyzed = "Hi! I'm David and I'd like to eat some sushi, can you help me?" session_client = dialogflow.SessionsClient() session = session_client.session_path(DIALOGFLOW_PROJECT_ID, SESSION_ID) text_input = dialogflow.types.TextInput(text=text_to_be_analyzed, language_code=DIALOGFLOW_LANGUAGE_CODE) query_input = dialogflow.types.QueryInput(text=text_input) try: response = session_client.detect_intent(session=session, query_input=query_input) except InvalidArgument: raise print("Query text:", response.query_result.query_text) print("Detected intent:", response.query_result.intent.display_name) print("Detected intent confidence:", response.query_result.intent_detection_confidence) print("Fulfillment text:", response.query_result.fulfillment_text)
As you can see, the function requires a session_id. This is nothing but a value that allows us to recognize the session in which you are working. For this purpose, I suggest that you use the ID of the user to retrieve it easily.
Finally, in order for the Python code work properly, you will need a fresh token to call the artificial intelligence of our chatbot. In fact, the V2 (version 2) of the Dialogflow API relies on an authentication system based on a private key associated with the Google Cloud Platform Service Account, instead of the access tokens. Please follow the tutorial here to accomplish this step. Through this simple procedure, it will be possible to obtain a private key in the JSON format. Be sure to store the file in a safe place because if you lose the key, you will have to generate a new one by going through the whole procedure again.
In my opinion, the great power of this tool lies in the ability for you to design your own business logic through the use of an intuitive console and easily integrate external modules. Moreover, Dialogflow can scale to thousands of users, being built on Google Cloud Platform, the scalable cloud infrastructure provided by Google.
Here, then, my list of Dialogflow pros and cons for you.
If you’re starting now with Dialogflow and this post has piqued your interest, I highly recommend you starting with the “prebuild agents”. These are customizable agents specialized in different areas of knowledge that you can simply import into your chatbot. Then you can set up a webhook as described in this post and get the agent responding. All the intents and even entities of the agent are editable and ready to use. Feel free to add more functionalities directly from the Google Cloud Platform or enhance your algorithms with NLP.
Google Cloud Next ’19 was the flagship Google Cloud Platform developers conference, held in San Francisco’s Moscone Center. I was lucky enough to attend it with Cloud Academy, and got the chance to check out tons of breakout sessions and get great insight firsthand. Next ’19 was my...
The meal was fantastic, the service was friendly and professional, the setting was cozy, and the company was engaging. As the evening ended, however, there was a slight hiccup as my credit card was declined. There was more than enough money in my account to cover the cost of the (very d...
On Monday, Microsoft kicked off its Ignite conference, an annual gathering of developers and IT professionals. Over the next week, attendees will learn about upcoming Microsoft innovations in IoT, artificial intelligence, machine learning, and cloud (all while getting some good networki...
A Comparison of Machine Learning Services on AWS, Azure, and Google CloudArtificial intelligence and machine learning are steadily making their way into enterprise applications in areas such as customer support, fraud detection, and business intelligence. There is every reason to beli...
The demand for continuous delivery has changed the approach to development and release tools, especially in keeping up with the high demand of DevOps and agile development practices. This has coincided with the emergence of artificial intelligence (AI) and subsequent AI-driven automated...
A 2017 IDC White Paper "recommend[s] that organizations that want to get the most out of cloud should train a wide range of stakeholders on cloud fundamentals and provide deep training to key technical teams" (emphasis ours). Regular readers of the Cloud Academy blog know we've been tal...
Cloud is a pathway to innovation. Where yesterday’s cloud deployments were about moving an on-premises infrastructure in your data center to a cloud environment, companies today are using cloud platforms to build new features for their products and services that are integrated at a soft...
Introduction to Machine Learning on AWSThis is your quick-start guide for building and deploying with Amazon Machine Learning. By the end of this learning path, you will be able to apply supervised and unsupervised learning, ML algorithms, deep learning, and deep neural networks on AW...
A common question in the medical field is:Is it possible to distinguish one class of samples from another, based on some set of measurements?Research investigating this and related medical questions have spurred innovation in medicine and the application of statistical methods and m...
This week, we’ve got lots of new content to share with you on Cloud Academy! Explore our newest learning paths, video courses, and hands-on labs on AWS, Microsoft Azure, and Google Cloud Platform on security, cloud architecture, containers, and many more topics.Learning PathsAWS Sec...
What is Amazon Machine Learning and how does it work"Amazon Machine Learning is a service that makes it easy for developers of all skill levels to use machine learning technology.”UPDATES: I've published a new hands-on lab on Cloud Academy! You can give it a try for free and st...
The phrase machine learning seems to appear alongside every new technology or service. Despite its popularity, many people still don’t understand exactly what machine learning means, nor how to make practical use of it.Today, we will explain the basics of machine learning, introduce...