Cre­at­ing your first chat­bot

net magazine - - FEATURES -

To cre­ate your first chat­bot, we’ll use Google’s new Dialogflow toolset. It har­nesses pow­er­ful ma­chine learn­ing as well as speech-to-text. It can be in­cor­po­rated right into your web­site as a wid­get or cus­tomised to your needs.

Cr eate an ac­count

Go to dialogflow.com and cre­ate your ac­count. Sign in and agree to the per­mis­sions to en­able Dialogflow to have ac­cess to your ac­count.

Cr eate an agent

Dialogflow uses the term ‘agent’ to rep­re­sent in­stances of your AI. Think of the agent as the vir­tual in­tel­li­gence you are cre­at­ing. You could have many agents work­ing for you, each with its own per­son­al­ity and pur­pose.

Click on the ‘Cre­ate Agent’ but­ton and en­ter a name for your agent: ‘HAL 9000’.

Cr eate an in­tent

First, you need to cre­ate an In­tent. We are defin­ing the ‘in­ten­tion’ of the user’s in­puts. Click ‘Cre­ate In­tent’ and name it ‘open doors’. Press ‘Save’.

Train the AI for this in­tent

Train the AI for this in­tent by pro­vid­ing phrases that a user might use. The NLP AI will use these and de­rived vari­a­tions to train the agent. Add the fol­low­ing train­ing phrases in the ‘Train­ing phrases’ win­dow and add as many of your own as you like: ‘Open the Pod bay doors, Hal.’ ‘Open the doors.’ ‘Let me in, Hal!’

Add re­spons es

Next, you need to add some re­sponses that the agent will re­spond with. You en­ter these in the ‘Re­sponses’ win­dow. Try out some like this: ‘I’m afraid I can’t do that, Dave.’’ ‘I can’t do that right now.’ Then press ‘Add Re­sponses’ and ‘Save’ up at the top again. You’ll see no­ti­fi­ca­tions that the agent is be­ing trained and then it is ready.

Test out the chat­bot

On the right-hand side of the screen is a test­ing tool. The chat­bot will use Google’s speech-to-text ser­vice to trans­late your voice into text if you try that out. You should see the re­sults of your re­quest and the re­sponse the AI agent se­lected. Very cool!

Cr eate and use an ‘e en­tity

En­ti­ties are con­cepts that can be de­fined and reused in the agent’s re­sponses as vari­ables.

Let’s train the AI to un­der­stand when a user is ex­press­ing an emo­tion then use that in its re­sponse to the user.

On the left-hand menu, click ‘En­ti­ties’. Type ‘emo­tion’ for the name of your new en­tity. Keep ‘De­fine syn­onyms’ checked.

Click in the ta­ble be­low and type ‘an­gry’ as the first emo­tion. Then click to the right of that and add syn­onyms such as ‘mad’, ‘up­set’, and so on.

Then add an­other en­try for ‘scared’ and use syn­onyms ‘afraid,’ ‘ter­ri­fied’, etc., that you like. Press ‘Save’ when done.

This has now trained the Agent to un­der­stand that ‘an­gry’ and ‘scared’ are emo­tions a user may com­mu­ni­cate. All those syn­onyms are vari­a­tions that might oc­cur. The AI will gen­er­ate some as well.

Cr eate a new in­tent

Now we are go­ing to cre­ate a new in­tent to use the ‘emo­tion’ en­tity we have cre­ated. Call this in­tent ‘emo­tions’ and click ‘Save’.

Next add new train­ing phrases such as ‘you’re scar­ing me’, ‘you’re mak­ing me mad’, and ‘I’m very an­gry,’ us­ing vari­a­tions of an­gry and scared key­words. This will train the agent to un­der­stand the var­i­ous ways that a user may phrase this emo­tional state­ment.

You’ll no­tice the sys­tem high­lights the scared and an­gry words for you. It’s al­ready flag­ging these as en­ti­ties. It has also added an en­try into the ‘Ac­tions and pa­ram­e­ters’ win­dow. This en­ables you to use these en­ti­ties in your re­sponses, too.

Add a re­spons e us­ing the new ‘emo­tion’ en­tity

In the Re­sponses win­dow, add new re­sponses that use this new en­tity. Note the ‘$’ to de­note the ‘$emo­tion’ En­tity. Try adding these re­sponses: ‘I am sorry you are feel­ing $emo­tion, Dave.’ ‘Feel­ing $emo­tion is a hu­man re­sponse, Dave.’

The tech­nol­ogy cre­ates fan­tas­tic op­por­tu­ni­ties but it also comes with a need for re­spon­si­ble, eth­i­cal use

Click ‘Add Re­sponses’ and press the ‘Save’ but­ton at the top of the screen to save the en­tire In­tent.

Test your chat­bot again

Try say­ing or typ­ing the fol­low­ing phrases in the test­ing tool. ‘You’re mak­ing me very an­gry Hal.’ “You’re freak­ing me out.” No­tice how it re­sponded us­ing ‘scared’ with the se­cond one? It used our syn­onym, ‘freaked out’ to know that we meant scared. Very cool.

Feel free to play around with this as well as add some more in­tents and re­sponses that you like and then we’ll add this to a web page.

Ac­ti­vate web in­te­gra­tion

To add it to your web page, click ‘In­te­gra­tions’ on the left-hand menu. Then click on the ‘Web Demo’ box to turn that op­tion on.

A pop-up will ap­pear that shows you a di­rect link so you can use to test your in­te­gra­tion out right away. It will also dis­play a code snip­pet that you can use to drop the wid­get into your own web site. Copy that snip­pet to the clip­board so you can paste it into your site.

Cr eate a ba­sic web page and add the sn ip­pet

Cre­ate a ba­sic HMTL page and in­clude that code snip­pet next. Try out the fol­low­ing code and up­load it to your server or run it on your lo­cal server. Re­place the snip­pet be­low with the one you copied from your Dialogflow agent: <! DOCTYPE html> <html> <head> < ti­tle>NET - AI Chat­bot</ ti­tle> </ head> <body> <iframe al­low=”mi­cro­phone;” width=” 350” height=”430” src=” https:// con­sole. dialogflow. com/api- client/demo/ em­bed­ded/ bb­d27d04-5546- 4b62- 85a5c373575a33aa”> </ iframe> </ body> </ html> Part­ing thoughts Ar­ti­fi­cial In­tel­li­gence (AI) en­ables us to cre­ate new ways of look­ing at ex­ist­ing prob­lems, from re­think­ing en­vi­ron­men­tal strate­gies to how we learn. Your projects – whether apps, web sites or games – can lever­age AI to make them more en­gag­ing, eas­ier to use and have more valu­able re­sults. The tech­nol­ogy cre­ates fan­tas­tic op­por­tu­ni­ties but it also comes with a need for re­spon­si­ble, eth­i­cal use. Seek ways to en­hance ex­pe­ri­ences and make life bet­ter as you learn and grow.

Above Train the AI for an in­tent by pro­vid­ing phrases that a user might use Above right Click­ing on Web Demo will dis­play a code snip­pet you can use to drop the wid­get into your own web­site

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.