pikesaku’s blog

個人的な勉強メモです。記載内容について一切の責任は持ちません。

Amazon Lexをやってみた

Amazon Lexとは?

 
Amazon Deep Learning技術による自然言語解析、音声認識機能
 音声認識サービスであるAlexaのベース技術
 
Webサービスとして利用可能
 開発者は実装が大変な自然言語解析、音声認識部分はLexに任せればOK
 会話の目的を実現するビジネスロジックを実装すれば、会話を入出力にするアプリを作れる。
 
 

機能概要

 
・目的のある会話から目的を実現する機能
 
 以下が基本動作
 ①会話から発言者の目的を認識
 ②目的実現に必要な情報が不足してる場合は、発言者から聞き出す。
 ③収集した情報を元に目的を実現
 
 目的のない会話ができるMicrosoftりんなのような機能ではない。
 基本的には人工無脳的なもの。会話認識にAI技術を活用。
 
AWS Lambdaサービスとの連携
 
 会話で得た情報を利用し事前作成済みプログラム(Lambda関数)を実行できる。
 連携機能がビルトインされており容易に実装可能
 
 ①他システム連携によりダイナミックな会話が可能。
 ②目的実現まで自動化が可能
 
・メッセージングアプリFaceBook Messenger、Slack、Twilioとの連携
 
 ChatBotとしての利用可能。
 Botに実現したい目的を伝えれば、必要な情報をヒヤリングし目的を実現してくれる。
 連携機能がビルトインされており容易に実装可能
 

メッセージングアプリと連携したChatBot技術の重要性について

 
 ChatBot技術は情報発信、マーケティング手段として注目されてる。
  
 ASCII.jp:AIをビジネスの味方にする「Microsoft Bot Framework」とは
  
 【理由】
 スマホアプリはあまり利用されてない。
 LINEなどのメッセージングアプリの利用者は伸びてる。
 →ChatBotはメッセージングアプリ経由で情報発信・マーケティングが可能な為、注目されている。
 
 

実現可能な会話の例

 
 例1)
 質問者: 明日の天気は?
 回答者: 何県何市の天気ですか?
 →「天気を知る」を目的と認識し、実現に必要な情報を聞き出す。
 
 質問者: 〜県〜市です。
 回答者: 雨です。
 →回答前に、天気予報サービスから情報を得て回答
 
 例2)
 ※歯科医院の予約の会話
 患者: ホワイトニングの予約をしたい
 受付: 何日が希望ですか?
 
 患者: 明日
 受付: 明日はNGです。明後日の10時からはいかがでしょうか?30分かかります。
 →予約管理システムと連携して、予約可能な時間を提案
 
 患者: OKです。
 受付: では明後日10時から30分で予約しますが、よろしいでしょうか?
 →確認
 
 患者: OKです。
 受付: 予約しました。
 →予約管理システムに登録し目的実現
 
 

類似技術

 
MicroSoft Bot Framework(LUIS)
IBM Watson
Google Assistant
Apple Siri
FaceBook Wit.ai
  
 などなど。違いはよく調べきれてません。考察としては、、、、
 
 Lexは2017/5/3時点で日本語未対応
 上記技術は基本的にAPI公開されており、プロバイダが異なってもサービス間連携は可能。
 例) FaceBook Bot機能が、Amazon Lambda機能と連携する等
 →LexのLambda連携はAmazon独自の強みでない。連携がビルトインの為、実装が容易である点は強み。
 
 AWS、Alexaを強化するボットフレームワーク「Amazon Lex」をローンチ - THE BRIDGE(ザ・ブリッジ)
 →Amazonが今後、最大のクラウドプロバイダである点を生かしシステム間連携(コネクタ)で差別化を測るかも。
 
 

利用料金

 
 料金 - Amazon Lex | AWS
 利用料金説明。最初の一年間は無料利用枠あり。
 
 

前置きが長くなったが、まずはやってみる!

 

メモ

 
 ビルトインで以下のサンプル設定があり、これを使うと簡易動作検証は容易
 ・BookTrip 旅行予約の会話
 ・OrderFlowers 花購入の会話
 ・ScheduleAppointment 歯医者治療予約の会話
 実用するにはlambda連携は必須。
 AWSコンソールにチャットインターフェースがあり、動作試験が可能。
 しかしAWSコンソールは未対応機能あり(レスポンスカード等)。
 未対応機能はFaceBook Messenger等で動作確認する必要あり。
 
 

歯医者治療予約Botの作成・動作確認(lambda連携なし)

 

Bot作成

f:id:pikesaku:20170504171045p:plain
 

Bot設定

f:id:pikesaku:20170504175140p:plain
 

Bot動作確認(AWSコンソール)

f:id:pikesaku:20170504180204p:plain
 
・会話例
 右矢印: ユーザー発言
 左矢印: Bot発言
 
例1)

> I would like to book an appointment
< What type of appointment would you like to schedule?
> Cleaning
< When should I schedule your Cleaning?
> Tommorow
< At what time on 2017-05-05?
> 11:00 a.m
< 11:00 is available, should I go ahead and book your appointment?
> Yes
< ReadyForFulfillment AppointmentType:Cleaning Time:11:00 Date:2017-05-05

 
例2)

> Book a Cleaning
< When should I schedule your Cleaning?
> Tommorow
< At what time on 2017-05-05?
> 11:00 a.m
< 11:00 is available, should I go ahead and book your appointment?
> Yes
< ReadyForFulfillment AppointmentType:Cleaning Time:11:00 Date:2017-05-05

 
例3)

> Book an appointment
< What type of appointment would you like to schedule?
> HogeHoge
< When should I schedule your HogeHoge?
> After 1 day
< When should I schedule your HogeHoge?
> 1 day later
< At what time do you want to schedule the HogeHoge?
> am 11:00
< At what time on 2017-05-05?
> 11:00 a.m
< 11:00 is available, should I go ahead and book your appointment?
> Yes
< ReadyForFulfillment AppointmentType:HogeHoge Time:11:00 Date:2017-05-05

 
例4)

> Hello
< I didn't understand you, what would you like me to do?
> appointment
< I didn't understand you, what would you like me to do?
> an appointment
< What type of appointment would you like to schedule?

 
例5)

I am appointment
I didn't understand you, what would you like me to do?
I am an appointment
What type of appointment would you like to schedule?

 
例6)

> Hello
< I didn't understand you, what would you like me to do?
> I want you to understand me
< I didn't understand you, what would you like me to do?
> I am sad
< Sorry, I'm not able to assist at this time

 
わかったこと
・デフォルトは一般会話に完全未対応
・目的認識までの会話でAIが活用されてるかは微妙?完全無脳な感じ。 
・lambda連携無効な為、実用的ではなし。
 
 

歯医者治療予約Botの作成・動作確認(lambra・Slack連携あり)

 参考URL
 Using Lambda Functions - Amazon Lex
 Example Bot: ScheduleAppointment - Amazon Lex
 

Bot作成

f:id:pikesaku:20170504201513p:plain
 

lambda設定

以下URLから設定
https://console.aws.amazon.com/lambda/
 
f:id:pikesaku:20170504202509p:plain
 
f:id:pikesaku:20170504202909p:plain
 
f:id:pikesaku:20170504203330p:plain
 
f:id:pikesaku:20170504203611p:plain
 
f:id:pikesaku:20170504203835p:plain
 
f:id:pikesaku:20170504204434p:plain
 

lambda連携用Bot設定

 
f:id:pikesaku:20170504211236p:plain
f:id:pikesaku:20170504211243p:plain
 
f:id:pikesaku:20170504224317p:plain 
 

Bot動作確認(AWSコンソール)

f:id:pikesaku:20170504212117p:plain
 

Slack設定

以下URLに従い設定
Integrating an Amazon Lex Bot with Slack - Amazon Lex
 
Step1,2は画面省略する。Step3以降の画面は以下の通り。
 
Slack App作成
f:id:pikesaku:20170504215436p:plain
 
Slack Botユーザー設定
f:id:pikesaku:20170504221944p:plain
 
f:id:pikesaku:20170504222218p:plain
 
f:id:pikesaku:20170504222726p:plain
 
f:id:pikesaku:20170504221642p:plain
 
f:id:pikesaku:20170504224744p:plain
 

Slack連携用Bot設定

以下URLに従い設定
Step 4: Integrate the Slack Application with the Amazon Lex Bot - Amazon Lex
 
f:id:pikesaku:20170504225908p:plain
 
f:id:pikesaku:20170504230100p:plain
 

Slack設定

以下URLに従い設定
Step 5: Complete Slack Integration - Amazon Lex
 
f:id:pikesaku:20170504231109p:plain
 
f:id:pikesaku:20170504232007p:plain
 
f:id:pikesaku:20170504232837p:plain
 
f:id:pikesaku:20170504233957p:plain
 
f:id:pikesaku:20170504235206p:plain
 
f:id:pikesaku:20170504235506p:plain
 

動作確認(Slack)

f:id:pikesaku:20170505002158p:plain
 
レスポンスカードがうまく動かない。。。。。。
f:id:pikesaku:20170505002712p:plain
 
もう疲れたので、手入力で会話動作の確認をする。
 
・会話例
 右矢印: ユーザー発言
 左矢印: Bot発言
 
例1)

> Book an appoint
< What type of appointment would you like to schedule?
> hogehoge
< I did not recognize that, can I book you a root canal, cleaning, or whitening?
> cleaning
< When would you like to schedule your cleaning?
< 5-5 (Fri)  
< 5-8 (Mon)
< 5-9 (Tue)
< 5-10 (Wed)
< 5-11 (Thu)
> 5-7
< Our office is not open on the weekends, can you provide a work day?
< 5-5 (Fri)  
< 5-8 (Mon)
< 5-9 (Tue)
< 5-10 (Wed)
< 5-11 (Thu)
> 5/8
< What time on 2017-05-08 works for you? We have availabilities at 11:30 a.m., 1:00 p.m. and 4:30 p.m.
< What time works best for you?
< 11:30 a.m.
< 1:00 p.m.
< 4:30 p.m.
> 12:00 a.m
< Our business hours are ten a.m. to five p.m.  What time works best for you?
< What time works best for you?
< 11:30 a.m.
< 1:00 p.m.
< 4:30 p.m.
> 1:00 p.m
< 1:00 p.m. is available, should I go ahead and book your cleaning?
> No
< Okay, I will not schedule an appointment.

 
lambda関数が入力チェックしており、動作が柔軟になっている。
 
 

最後に

 
lanbda連携動作の仕組みの把握が必要。
今度、以下URLの内容把握に取り組む。
Details of Information Flow - Amazon Lex
サンプル用lambda関数プログラムの中身も確認する。
目的を2つ以上組み合わせると、実用的になりそう。
SlackBotとの会話から簡易なAWSインフラの管理作業(インスタンスデプロイや各種情報取得等)を実行できそう。
API・Web操作を知らなくても、Botに目的伝えれば目的実現をアシストしてくれるのはいいかも。