- Cognitive Computing with IBM Watson
- Rob High Tanmay Bakshi
- 533字
- 2021-06-24 15:02:36
Context variables
Before we go further, we need to discuss context variables. Any robust conversational agent will benefit from context. Context enables memory between turns in the conversation and enables anaphora—reducing the awkward need to repeat words, especially nouns, used earlier in the exchange. Context is represented within the dialog as a set of developer-defined context variables, represented with the $ prefix, and passed between the application and the conversation service through a JSON structure.
Keep in mind that the Watson Assistant conversational API is stateless—that is, it doesn't maintain any memory of prior calls to the service, and therefore any state, such as context, must be passed back and forth between your application and the service. This will become more obvious when we show how your application can call the service API, later in this chapter.
In the preceding example, the dialog node will check for the existence of the @Accounts entity in the user's utterance. If it finds it, the value of the @Accounts entity will be assigned to the $FromAccount context variable.
If that slot @Accounts entity is not found, the dialog node will prompt the user with the What account do you want to debit? question, all of which you will enter into the slot fields. Let's try it out.
Enter transfer funds in the Try it out tool:

Notice, that Watson recognized that the utterance is intended to mean #Funds-Transfer, and that it didn't find any @Accounts entities, so it prompted for it. You can now respond to that with savings. Watson realized that you are still responding to the #Funds-Transfer intent, and that you expressed an @Accounts entity of savings:

Now, if you press the Manage Context button at the top of the panel, you will see that the $FromAccount context variable was filled in. The $timezone context variable is always filled in automatically by Watson:

Now, we can return to editing the dialog node to create slots for the target account and amount to transfer:

The same entity type is sought to fill in the $FromAccount and $ToAccount context variables. Watson is smart enough to realize these should represent two different instances of the @Accounts entity.
We can finish out the node by instructing Watson to acknowledge the transfer by filling in the Then respond with: field of the node with something such as Thank you. We will transfer $$Amount from $FromAccount to $ToAccount:

We can then try it out in various ways, as follows:

You can fill in multiple slots with the same utterance.
While Watson remains quite robust with this simple example—able to understand your intent even when expressed in a variety of different ways—it's also not entirely infallible. For example, if you reverse the from and to accounts in your expression, as follows, Watson can get confused:

However, the Watson tooling is quite sophisticated. There are a variety of techniques that can be used to overcome this type of confusion. We won't go into the details at this time, but we do encourage you to explore the tooling and the wide range of educational materials posted on the Web to learn more.
- 公有云容器化指南:騰訊云TKE實戰與應用
- Python絕技:運用Python成為頂級數據工程師
- Visual Studio 2015 Cookbook(Second Edition)
- Access 2007數據庫應用上機指導與練習
- 企業大數據系統構建實戰:技術、架構、實施與應用
- 商業分析思維與實踐:用數據分析解決商業問題
- 醫療大數據挖掘與可視化
- 數據庫系統原理及應用教程(第4版)
- 數據庫應用系統開發實例
- Power BI智能數據分析與可視化從入門到精通
- 數據庫技術及應用
- 爬蟲實戰:從數據到產品
- 活用數據:驅動業務的數據分析實戰
- 大數據技術原理與應用:概念、存儲、處理、分析與應用
- Web Services Testing with soapUI