This is an automated email from the ASF dual-hosted git repository. aradzinski pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft-website.git
The following commit(s) were added to refs/heads/master by this push: new 4b2527f WIP. 4b2527f is described below commit 4b2527f18071f618e3743904d352e228ad1f7d04 Author: Aaron Radzinski <aradizn...@apache.org> AuthorDate: Wed Jul 28 13:20:22 2021 -0700 WIP. --- _includes/latest_ver_blog_warn.html | 2 +- _scss/misc.scss | 4 +- _scss/short-term-memory.scss | 11 ++- intent-matching.html | 8 ++- short-term-memory.html | 130 +++++++++++++++--------------------- 5 files changed, 73 insertions(+), 82 deletions(-) diff --git a/_includes/latest_ver_blog_warn.html b/_includes/latest_ver_blog_warn.html index c46cfed..d6a99bc 100644 --- a/_includes/latest_ver_blog_warn.html +++ b/_includes/latest_ver_blog_warn.html @@ -20,6 +20,6 @@ <p> At the moment of this writing, the project undergoes incubation at <a target=asf href="https://apache.org/">Apache Software Foundation</a>, the <a href="/download.html">latest version</a> of NLPCraft is <b>{{site.latest_version}}</b>. In some rare cases, APIs might have changed - since the this article was written. Consult the latest <a href="/docs.html">documentation</a> for up to date information. + since this article was written. Consult the latest <a href="/docs.html">documentation</a> for up-to-date information. </p> </div> \ No newline at end of file diff --git a/_scss/misc.scss b/_scss/misc.scss index 612744b..ca433a1 100644 --- a/_scss/misc.scss +++ b/_scss/misc.scss @@ -357,6 +357,8 @@ $bq-success-border-color: $brand-success; .max-width { width: 100%; } + +.not-code {} a[target=javadoc]:not(.not-code) { font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; word-break: keep-all; @@ -370,7 +372,7 @@ pre.console { } code { - font-size: 100%; + font-size: 105%; white-space: nowrap !important; color: #C0392B; diff --git a/_scss/short-term-memory.scss b/_scss/short-term-memory.scss index e73387d..e6ca988 100644 --- a/_scss/short-term-memory.scss +++ b/_scss/short-term-memory.scss @@ -52,15 +52,24 @@ display: block; } + i { + font-size: 90%; + color: #ccc; + } + span { + vertical-align: top; min-width: 50px; display: inline-block; padding: 3px 6px; border: 1px solid #C5D2F7 !important; border-radius: 2px; text-align: center; - font-weight: 200; letter-spacing: 0.02em; + + b { + color: $color-wisteria; + } } } } diff --git a/intent-matching.html b/intent-matching.html index 4dc8f3f..f39d14d 100644 --- a/intent-matching.html +++ b/intent-matching.html @@ -182,6 +182,7 @@ id: intent_matching <thead> <tr> <td>Option</td> + <td>Type</td> <td>Description</td> <td>Default Value</td> </tr> @@ -189,6 +190,7 @@ id: intent_matching <tbody> <tr> <td><code>ordered</code></td> + <td><code>Boolean</code></td> <td> Whether or not this intent is ordered. For ordered intent the specified order of terms is important for matching this intent. @@ -201,6 +203,7 @@ id: intent_matching </tr> <tr> <td><code>unused_free_words</code></td> + <td><code>Boolean</code></td> <td> Whether or not free words - that are unused by intent matching - should be ignored (value <code>true</code>) or reject the intent match (value <code>false</code>). @@ -212,6 +215,7 @@ id: intent_matching </tr> <tr> <td><code>unused_sys_toks</code></td> + <td><code>Boolean</code></td> <td> Whether or not unused <a href="/data-model.html#builtin">system tokens</a> should be ignored (value <code>true</code>) or reject the intent match (value <code>false</code>). @@ -221,16 +225,18 @@ id: intent_matching </tr> <tr> <td><code>unused_usr_toks</code></td> + <td><code>Boolean</code></td> <td> Whether or not unused user-defined tokens should be ignored (value <code>true</code>) or reject the intent match (value <code>false</code>). By default, tne unused user tokens are not ignored since it is assumed that user would - defined his or her own tokens on purpose and construct the intent logic appropriate. + define his or her own tokens on purpose and construct the intent logic appropriate. </td> <td><code>false</code></td> </tr> <tr> <td><code>allow_stm_only</code></td> + <td><code>Boolean</code></td> <td> Whether or not the intent can match when all of the matching tokens came from STM. By default, this special case is disabled (value <code>false</code>). However, in specific intents diff --git a/short-term-memory.html b/short-term-memory.html index 255294b..c70973d 100644 --- a/short-term-memory.html +++ b/short-term-memory.html @@ -22,16 +22,18 @@ id: short_term_memory --> <div id="short-term-memory" class="col-md-8 second-column"> - <section id="stm"> + <section id="overview"> <h2 class="section-title">Conversation <span class="amp">&</span> STM <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> <p> NLPCraft provides automatic conversation management right out of the box that is fully integrated with - <a href="/intent-matching.html">intent matching</a>. Conversation management is based on the idea of short-term memory (STM). STM is automatically - maintained by NLPCraft per each user and data model combination. Essentially, NLPCraft "remembers" - the context of the conversation and can supply the currently missing elements from STM - to the intent matching algorithm for the conversational terms. + <a href="/intent-matching.html">intent matching</a>. Conversation management is based on the idea of short-term memory (STM) - + the mechanism by which NLPCraft "remembers" the context of the conversation for a certain amount of time and certain + depth of the conversation. STM is automatically maintained by NLPCraft per each user and data model combination. + Intent matching algorithm can "recall" the missing tokens from STM when trying to find a match for the + conversational terms. </p> <p> + Why is this so important? Maintaining conversation state is necessary for effective context resolution, so that users could ask, for example, the following sequence of questions using example weather model: </p> @@ -45,13 +47,13 @@ id: short_term_memory </p> <div class="stm-state"> <div class="stm"> - <label>STM Before:</label> + <label><b>STM</b> Before:</label> <span> </span> </div> <div class="stm"> - <label>STM After:</label> + <label><b>STM</b> After:</label> <span>weather</span> - <span>London</span> + <span>london</span> <span>today</span> </div> </div> @@ -67,15 +69,15 @@ id: short_term_memory </p> <div class="stm-state"> <div class="stm"> - <label>STM Before:</label> + <label><b>STM</b> Before:</label> <span>weather</span> <span>London</span> <span>today</span> </div> <div class="stm"> - <label>STM After:</label> + <label><b>STM</b> After:</label> <span>weather</span> - <span><b>Berlin</b></span> + <span><b>berlin</b><br/><i>london</i></span> <span>today</span> </div> </div> @@ -90,16 +92,16 @@ id: short_term_memory </p> <div class="stm-state"> <div class="stm"> - <label>STM Before:</label> + <label><b>STM</b> Before:</label> <span>weather</span> <span>Berlin</span> <span>today</span> </div> <div class="stm"> - <label>STM After:</label> - <span><b>forecast</b></span> - <span>Berlin</span> - <span><b>Next week</b></span> + <label><b>STM</b> After:</label> + <span><b>forecast</b><br/><i>weather</i></span> + <span>berlin</span> + <span><b>next week</b><br/><i>today</i></span> </div> </div> </dt> @@ -109,24 +111,14 @@ id: short_term_memory Conversation management implementation is also smart enough to clear STM after certain period of time, i.e. it “forgets” the conversational context after few minutes of inactivity. Note also that conversational context can also be cleared explicitly - via <a href="https://github.com/apache/incubator-nlpcraft/blob/master/openapi/nlpcraft_swagger.yml" target="github">REST API</a>. + via <a href="https://app.swaggerhub.com/apis-docs/Apache-NLPCraft/apache-nlpcraft/{{site.latest_version}}" target="swaggerhub">REST API</a> + or from the <a class="not-code" target="javadoc" href="/apis/latest/org/apache/nlpcraft/model/NCConversation.html">code</a>. </p> - </section> - <section> - {% include latest_ver_blog_warn.html %} <p> - In this blog, I'll try to give a high-level overview of STM - Short-Term Memory, a technique used to - maintain conversational context in NLPCraft. Maintaining the proper conversation context - remembering - what the current conversation is about - is essential for all human interaction and thus essential for - computer-based natural language understanding. To my knowledge, NLPCraft provides one of the most advanced - implementations of STM, especially considering how tightly it is integrated with NLPCraft's unique - intent-based matching (Google's <a target=google href="https://cloud.google.com/dialogflow/">DialogFlow</a> is very similar yet). - </p> - <p> - Let's dive in. + To understand the algorithm behind the STM management let's back up a few steps... </p> </section> - <section> + <section id="parsing"> <h2 class="section-title">Parsing User Input <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> <p> One of the key objectives when parsing user input sentence for Natural Language Understanding (NLU) is to @@ -159,8 +151,8 @@ id: short_term_memory sentence since without a context the missing information cannot be obtained and the sentenced cannot be interpreted. </p> </section> - <section> - <h2 class="section-title">Semantic Entities <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> + <section id="ne"> + <h2 class="section-title">Named Entities <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> <p> Let's take a closer look at the named entities from the above examples: </p> @@ -209,7 +201,7 @@ id: short_term_memory </p> </div> </section> - <section> + <section id="incomplete"> <h2 class="section-title">Incomplete Sentences <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> <p> Assuming previously asked questions about the weather in Tokyo (in the span of the ongoing conversation) one @@ -229,10 +221,10 @@ id: short_term_memory </ul> <p> These are incomplete sentences. This type of short-hands cannot be interpreted without prior context (neither - by humans or by machines) since by themselves they are missing necessary information. + by humans nor by machines) since by themselves they are missing necessary information. In the context of the conversation, however, these incomplete sentences work. We can simply provide one or two entities and rely on the <em>"listener"</em> to recall the rest of missing information from a - <em>short-term memory</em>, a.k.a conversation context. + short-term memory. </p> <p> In NLPCraft, the intent-matching logic will automatically try to find missing information in the @@ -241,14 +233,14 @@ id: short_term_memory found explicitly in the user input. </p> </section> - <section> + <section id="stm"> <h2 class="section-title">Short-Term Memory <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> <p> The short-term memory is exactly that... a memory that keeps only small amount of recently used information and that evicts its contents after a short period of inactivity. </p> <p> - Let's look at the example from a real life. If you would call your friend in a couple of hours asking <code>"What about a day after?"</code> + Let's look at the example from a real life. If you called your friend in a couple of hours asking <code>"What about a day after?"</code> (still talking about weather in Kyoto) - he'll likely be thoroughly confused. The conversation is timed out, and your friend has lost (forgotten) its context. You will have to explain again to your confused friend what is that you are asking about... </p> @@ -257,7 +249,7 @@ id: short_term_memory what happens if we switch the topic before this timeout elapsed? </p> </section> - <section> + <section id="ctx-switch"> <h2 class="section-title">Context Switch <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> <p> Resetting the context by the timeout is, obviously, not a hard thing to do. What can be trickier is to detect @@ -270,7 +262,7 @@ id: short_term_memory </p> <ul> <li> - <code>"How much mocha latter at Starbucks?"</code><br/> + <code>"How much is mocha latter at Starbucks?"</code><br/> At this point we should forget all about previous conversation about weather and assume going forward that we are talking about coffee in Starbucks. </li> @@ -287,11 +279,16 @@ id: short_term_memory Despite somewhat obvious logic the implementation of context switch is not an exact science. Sometimes, you can have a "soft" context switch where you don't change the topic of the conversation 100% but yet sufficiently enough to forget at least some parts of the previously collected context. NLPCraft has a built-in algorithm - to detect the hard switch in the conversation. It also exposes API to perform a selective reset on the + to detect the hard switch in the conversation. It also exposes + <a class="not-code" target="javadoc" href="/apis/latest/org/apache/nlpcraft/model/NCConversation.html">API</a> to perform a selective reset on the conversation in case of "soft" switch. </p> + <p> + See <a class="javadoc" href="/apis/latest/org/apache/nlpcraft/model/NCConversation.html">NCConversion</a> interface + for API details for STM management. + </p> </section> - <section> + <section id="override"> <h2 class="section-title">Overriding Entities <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> <p> As we've seen above one named entity can replace or override an older entity in the STM, e.g. <code>"Peet's"</code> @@ -348,7 +345,7 @@ id: short_term_memory </li> </ul> </section> - <section> + <section id="rule"> <h2 class="section-title">Overriding Rule <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> <p> Here's the rule we developed at NLPCraft and have been successfully using in various models: @@ -440,12 +437,8 @@ id: short_term_memory </ul> </li> </ul> - <p> - And so on... easy, huh 😇 In fact, the logic is indeed relatively straightforward. It also follows - common sense where the logic produced by this rule matches the expected human behavior. - </p> </section> - <section> + <section id="switch"> <h2 class="section-title">Explicit Context Switch <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> <p> In some cases you may need to explicitly clear the conversation STM without relying on algorithmic behavior. @@ -474,43 +467,24 @@ id: short_term_memory in the NLPCraft model. </p> <p> - In NLPCraft you can also explicitly reset conversation context through API or by switching the model on the request. - </p> - </section> - <section> - <h2 class="section-title">Summary <a href="#"><i class="top-link fas fa-fw fa-angle-double-up"></i></a></h2> - <p> - Let’s collect all our thoughts on STM into a few bullet points: + In NLPCraft you can also explicitly reset conversation context through + <a class="not-code" target="javadoc" href="/apis/latest/org/apache/nlpcraft/model/NCConversation.html">API</a> + or by switching the model on the request. </p> - <ul> - <li> - Missing entities in incomplete sentences can be auto-recalled from STM. - </li> - <li> - Newly detected type/category entity is likely indicating the change of topic. - </li> - <li> - The key property of STM is its short-time storage and overriding rule. - </li> - <li> - The explicit context switch is an important mechanism. - </li> - </ul> - <div class="bq info"> - <b> - Short-Term Memory - </b> - <p> - It is uncanny how properly implemented STM can make conversational interface <b>feel like a normal human - conversation</b>. It allows to minimize the amount of parasitic dialogs and Q&A driven interfaces - without unnecessarily complicating the implementation of such systems. - </p> - </div> </section> </div> <div class="col-md-2 third-column"> <ul class="side-nav"> <li class="side-nav-title">On This Page</li> + <li><a href="#overview">Conversation <span class="amp">&</span> STM</a></li> + <li><a href="#parsing">Parsing User Input</a></li> + <li><a href="#ne">Named Entities</a></li> + <li><a href="#incomplete">Incomplete Sentences</a></li> + <li><a href="#stm">Short-Term-Memory</a></li> + <li><a href="#ctx-switch">Context Switch</a></li> + <li><a href="#override">Overriding Entities</a></li> + <li><a href="#rule">Overriding Rule</a></li> + <li><a href="#switch">Context Switch</a></li> {% include quick-links.html %} </ul> </div>