はじめに
昨年の11月に、Amazon Lexで会話ログの選択的なキャプチャ(Selective Conversation Log Capture)ができるようになっていたため、内容を確認しました。
「会話ログの選択的なキャプチャ」とは、テキストまたは音声形式の会話を、会話全体ではなく、必要な部分のみログとして記録する機能のことです。
対象範囲は、Lexのインテントとスロットです。
セキュリティやプライバシー上の懸念から会話全体のログを記録できない場合に役立ちます。
- 金融機関や医療機関など、機密性の高い個人情報を扱う業界での利用
- コールセンターなどで、プライバシー情報が含まれる可能性のある会話
こうした要件を満たしながら、トラブルシューティングに不可欠な会話のログを必要最小限で選択的に記録できます。
会話ログの選択的なキャプチャを有効にするには、Amazon Lex V2 コンソールで機能を有効にし、必要なセッション属性を有効にする必要があります。
会話ログの選択的なキャプチャには次のオプションを選択できます。
- テキストのみ
- 音声のみ
- テキストと音声
試してみた
Lexのボットを構築後、会話ログを有効化し、テストします。
その後、以下のドキュメントを参考に会話ログの選択的なキャプチャを有効化して、テストし、ログが選択的に取得できるか確認します。
ボット構築
Lexのボットを構築します。
インテント名は、free
、サンプル発話は、テスト
とします。
スロットは2つ作成しています。どちらも自由入力形式のAMAZON.FreeFormInput
です。
- 名前:
freeinput1
- プロンプト:1点目のお問い合わせ内容をお伝えください
- 名前:
freeinput2
- プロンプト:2点目のお問い合わせ内容をお伝えください
確認プロンプトは以下の通りです。
1点目は、「{freeinput1}」。2点目は、「{freeinput2}」
これでBuildし構築完了です。
会話ログの有効化
会話ログを有効化します。
今回は、テキストログを有効化します。現段階では、会話ログの選択的なキャプチャはチェックしません。(Selectively log utterances)
これで一旦テストしてみます。
会話ログは保存されていましたので、後で選択的なキャプチャと比較します。
会話ログの選択的なキャプチャ
今回のアップデート内容である会話ログの選択的なキャプチャ有効にします。
会話ログのSelectively log utterances
を有効化します。
インテントに戻り、[初期応答]から[詳細オプション]をクリックします。
セッション属性に、テキスト形式と音声形式に合わせて、ログを記録したいインテントやスロットを指定して以下を記載します。
[x-amz-lex:enable-audio-logging:intent:slot] = "true"
[x-amz-lex:enable-text-logging:intent:slot] = "true"
インテントとスロットの値どちらも*
と指定はできます。
今回は、スロット1(freeinput1
)のみログを記録したいため、以下を記載しました。
[x-amz-lex:enable-text-logging:free:freeinput1] = "true"
注意点
ドキュメントには、入力形式が以下のようになっていました。
x-amz-lex:enable-audio-logging:intent:slot = "true"
x-amz-lex:enable-text-logging:intent:slot = "true"
AWSにはフィードバック済みですが、セッション属性は、角括弧 ("[ ]")で囲む必要があります。そのため、ドキュメント通りですとInvalid session attribute name.
というエラーになりますので注意してください。
再度Buildしてテストしてみます。
会話ログの比較
会話ログの選択的なキャプチャを利用しない場合、4つの会話がログに記録されました。
- インテントのトリガー
- freeinput1スロット
- freeinput2スロット
- 確認プロンプト
実際のログは以下の通りです。
インテントのトリガー (クリックすると展開します)
{
"timestamp": "2024-03-26T05:50:36.344Z",
"messages": [
{
"contentType": "PlainText",
"content": "1点目のお問い合わせ内容をお伝えください"
}
],
"messageVersion": "2.0",
"sessionId": "540835513398187",
"dialogEventLogs": [
{
"nextStep": {
"sessionAttributes": {
"x-amz-lex:enable-text-logging:free:freeinput1": "true"
},
"dialogAction": {
"type": "ElicitSlot",
"slotToElicit": "freeinput1"
}
},
"dialogStepLabel": "Intent/free/StartIntent"
}
],
"requestId": "7caffb17-de87-4224-8f69-f71248ea8ae2",
"isTestWorkbenchTraffic": false,
"inputMode": "Text",
"operationName": "RecognizeText",
"interpretations": [
{
"nluConfidence": "1.00",
"interpretationSource": "Lex",
"intent": {
"name": "free",
"state": "InProgress",
"confirmationState": "None",
"slots": {
"freeinput1": null,
"freeinput2": null
}
}
},
{
"interpretationSource": "Lex",
"intent": {
"name": "FallbackIntent",
"slots": {}
}
}
],
"developerOverride": false,
"bot": {
"name": "cm-hirai-test",
"version": "DRAFT",
"id": "5KMU82IFR2",
"aliasName": "TestBotAlias",
"aliasId": "TSTALIASID",
"localeId": "ja_JP"
},
"sessionState": {
"sessionAttributes": {
"x-amz-lex:enable-text-logging:free:freeinput1": "true"
},
"originatingRequestId": "7caffb17-de87-4224-8f69-f71248ea8ae2",
"intent": {
"name": "free",
"state": "InProgress",
"confirmationState": "None",
"slots": {
"freeinput1": null,
"freeinput2": null
}
},
"dialogAction": {
"type": "ElicitSlot",
"slotToElicit": "freeinput1"
}
},
"inputTranscript": "テスト",
"missedUtterance": false,
"utteranceContext": {}
}
freeinput1スロット (クリックすると展開します)
{
"timestamp": "2024-03-26T05:50:40.492Z",
"messages": [
{
"contentType": "PlainText",
"content": "2点目のお問い合わせ内容をお伝えください"
}
],
"messageVersion": "2.0",
"sessionId": "540835513398187",
"dialogEventLogs": [
{
"nextStep": {
"sessionAttributes": {},
"dialogAction": {
"type": "ElicitSlot",
"slotToElicit": "freeinput2"
}
},
"dialogStepLabel": "Intent/free/Slot/freeinput1/Success"
}
],
"requestId": "bc1fd41e-0224-49be-935f-451f890b05c5",
"isTestWorkbenchTraffic": false,
"inputMode": "Text",
"operationName": "RecognizeText",
"interpretations": [
{
"nluConfidence": "1.00",
"intent": {
"name": "free",
"state": "InProgress",
"confirmationState": "None",
"slots": {
"freeinput1": {
"value": {
"originalValue": "テスト1",
"interpretedValue": "テスト1",
"resolvedValues": []
},
"shape": "Scalar"
},
"freeinput2": null
}
},
"interpretationSource": "Lex"
}
],
"developerOverride": false,
"bot": {
"name": "cm-hirai-test",
"version": "DRAFT",
"id": "5KMU82IFR2",
"aliasName": "TestBotAlias",
"aliasId": "TSTALIASID",
"localeId": "ja_JP"
},
"sessionState": {
"sessionAttributes": {
"x-amz-lex:enable-text-logging:free:freeinput1": "true"
},
"intent": {
"name": "free",
"state": "InProgress",
"confirmationState": "None",
"slots": {
"freeinput1": {
"value": {
"originalValue": "テスト1",
"interpretedValue": "テスト1",
"resolvedValues": []
},
"shape": "Scalar"
},
"freeinput2": null
}
},
"originatingRequestId": "7caffb17-de87-4224-8f69-f71248ea8ae2",
"dialogAction": {
"type": "ElicitSlot",
"slotToElicit": "freeinput2"
}
},
"inputTranscript": "テスト1",
"missedUtterance": false,
"utteranceContext": {}
}
freeinput2スロット (クリックすると展開します)
{
"timestamp": "2024-03-26T05:50:43.411Z",
"messages": [
{
"contentType": "PlainText",
"content": "1点目は、「テスト1」。2点目は、「テスト2」"
}
],
"messageVersion": "2.0",
"sessionId": "540835513398187",
"dialogEventLogs": [
{
"nextStep": {
"dialogAction": {
"type": "ConfirmIntent"
},
"sessionAttributes": {}
},
"dialogStepLabel": "Intent/free/Slot/freeinput2/Success"
}
],
"requestId": "a39cc855-1ce9-4056-8e6c-48c7f9f4c4c3",
"isTestWorkbenchTraffic": false,
"inputMode": "Text",
"operationName": "RecognizeText",
"interpretations": [
{
"interpretationSource": "Lex",
"intent": {
"name": "free",
"state": "InProgress",
"confirmationState": "None",
"slots": {
"freeinput1": {
"value": {
"originalValue": "テスト1",
"interpretedValue": "テスト1",
"resolvedValues": []
},
"shape": "Scalar"
},
"freeinput2": {
"value": {
"originalValue": "テスト2",
"interpretedValue": "テスト2",
"resolvedValues": []
},
"shape": "Scalar"
}
}
}
}
],
"developerOverride": false,
"bot": {
"name": "cm-hirai-test",
"version": "DRAFT",
"id": "5KMU82IFR2",
"aliasName": "TestBotAlias",
"aliasId": "TSTALIASID",
"localeId": "ja_JP"
},
"sessionState": {
"sessionAttributes": {
"x-amz-lex:enable-text-logging:free:freeinput1": "true"
},
"dialogAction": {
"type": "ConfirmIntent"
},
"originatingRequestId": "7caffb17-de87-4224-8f69-f71248ea8ae2",
"intent": {
"name": "free",
"state": "InProgress",
"confirmationState": "None",
"slots": {
"freeinput1": {
"value": {
"originalValue": "テスト1",
"interpretedValue": "テスト1",
"resolvedValues": []
},
"shape": "Scalar"
},
"freeinput2": {
"value": {
"originalValue": "テスト2",
"interpretedValue": "テスト2",
"resolvedValues": []
},
"shape": "Scalar"
}
}
}
},
"inputTranscript": "テスト2",
"missedUtterance": false,
"utteranceContext": {}
}
確認プロンプト (クリックすると展開します)
{
"timestamp": "2024-03-26T05:50:45.996Z",
"messageVersion": "2.0",
"sessionId": "540835513398187",
"dialogEventLogs": [
{
"nextStep": {
"sessionAttributes": {},
"dialogAction": {
"type": "EndConversation"
}
},
"dialogStepLabel": "Intent/free/ConfirmIntent/Success"
}
],
"requestId": "5cf4692c-c6d2-4520-8c09-83cb38aa483e",
"isTestWorkbenchTraffic": false,
"inputMode": "Text",
"operationName": "RecognizeText",
"interpretations": [
{
"nluConfidence": "1.00",
"interpretationSource": "Lex",
"intent": {
"name": "free",
"state": "ReadyForFulfillment",
"confirmationState": "Confirmed",
"slots": {
"freeinput1": {
"value": {
"originalValue": "テスト1",
"interpretedValue": "テスト1",
"resolvedValues": []
},
"shape": "Scalar"
},
"freeinput2": {
"value": {
"originalValue": "テスト2",
"interpretedValue": "テスト2",
"resolvedValues": []
},
"shape": "Scalar"
}
}
}
},
{
"interpretationSource": "Lex",
"intent": {
"name": "FallbackIntent",
"slots": {}
}
}
],
"developerOverride": false,
"bot": {
"name": "cm-hirai-test",
"version": "DRAFT",
"id": "5KMU82IFR2",
"aliasName": "TestBotAlias",
"aliasId": "TSTALIASID",
"localeId": "ja_JP"
},
"sessionState": {
"sessionAttributes": {
"x-amz-lex:enable-text-logging:free:freeinput1": "true"
},
"originatingRequestId": "7caffb17-de87-4224-8f69-f71248ea8ae2",
"dialogAction": {
"type": "Close"
},
"intent": {
"name": "free",
"state": "ReadyForFulfillment",
"confirmationState": "Confirmed",
"slots": {
"freeinput1": {
"value": {
"originalValue": "テスト1",
"interpretedValue": "テスト1",
"resolvedValues": []
},
"shape": "Scalar"
},
"freeinput2": {
"value": {
"originalValue": "テスト2",
"interpretedValue": "テスト2",
"resolvedValues": []
},
"shape": "Scalar"
}
}
}
},
"inputTranscript": "はい",
"missedUtterance": false,
"utteranceContext": {}
}
会話ログの選択的なキャプチャで、スロット1のみを指定した場合、以下のみがログに記録されていました。
- freeinput1スロット
{
"timestamp": "2024-03-26T05:56:40.162Z",
"messages": [
{
"contentType": "PlainText",
"content": "2点目のお問い合わせ内容をお伝えください"
}
],
"messageVersion": "2.0",
"sessionId": "540835513398559",
"dialogEventLogs": [
{
"nextStep": {
"dialogAction": {
"type": "ElicitSlot",
"slotToElicit": "freeinput2"
},
"sessionAttributes": {}
},
"dialogStepLabel": "Intent/free/Slot/freeinput1/Success"
}
],
"requestId": "0dba6b3f-a41e-4ea4-99d7-1d4b5d87308b",
"isTestWorkbenchTraffic": false,
"inputMode": "Text",
"operationName": "RecognizeText",
"interpretations": [
{
"nluConfidence": "1.00",
"interpretationSource": "Lex",
"intent": {
"name": "free",
"state": "InProgress",
"confirmationState": "None",
"slots": {
"freeinput1": {
"value": {
"originalValue": "テスト1",
"interpretedValue": "テスト1",
"resolvedValues": []
},
"shape": "Scalar"
},
"freeinput2": null
}
}
}
],
"developerOverride": false,
"bot": {
"name": "cm-hirai-test",
"version": "DRAFT",
"id": "5KMU82IFR2",
"aliasName": "TestBotAlias",
"aliasId": "TSTALIASID",
"localeId": "ja_JP"
},
"sessionState": {
"sessionAttributes": {
"x-amz-lex:enable-text-logging:free:freeinput1": "true"
},
"dialogAction": {
"type": "ElicitSlot",
"slotToElicit": "freeinput2"
},
"originatingRequestId": "6acd8adc-8232-42ce-8044-2cf6ce50589c",
"intent": {
"name": "free",
"state": "InProgress",
"confirmationState": "None",
"slots": {
"freeinput1": {
"value": {
"originalValue": "テスト1",
"interpretedValue": "テスト1",
"resolvedValues": []
},
"shape": "Scalar"
},
"freeinput2": null
}
}
},
"inputTranscript": "テスト1",
"missedUtterance": false,
"utteranceContext": {}
}
ちなみに、messagesが2点目のお問い合わせ内容をお伝えください
の理由は、次に返すメッセージを指しているためです。
スロット1と2を指定したパターン
会話ログの選択的なキャプチャに、以下の通りスロット1と2を指定した場合、2つのみがログに記録されます。
- freeinput1スロット
- freeinput2スロット
[x-amz-lex:enable-text-logging:free:freeinput1] = "true"
[x-amz-lex:enable-text-logging:free:freeinput2] = "true"
全選択したパターン
会話ログの選択的なキャプチャにインテント名free
を指定しつつ、スロット名を全選択(*
)とした場合、4つの会話がログに記録されました。
- インテントのトリガー
- freeinput1スロット
- freeinput2スロット
- 確認プロンプト
[x-amz-lex:enable-text-logging:free:*] = "true"
指定しないパターン
セッション属性を空にした場合、ログは記録されませんでした。
ドキュメントにも記載があります。
選択会話ログキャプチャが有効で、プレフィックス x-amz-lex: のセッション属性が存在しないenable-audio-logging 場合、すべての発話のログ記録はデフォルトで無効になります。
最後に
今回は、Amazon Lexのアップデートである会話ログの選択的なキャプチャを試してみました。
セキュリティやプライバシー上の懸念から会話のログを選択的に記録する必要がある場合、役立つアップデートですので、参考になれば幸いです。