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 d4193a8 WIP.
d4193a8 is described below
commit d4193a858cef948bd9e1b566096cf2613ab9fac3
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sun Nov 15 20:34:13 2020 -0800
WIP.
---
_scss/misc.scss | 1 +
blogs/short_term_memory.html | 247 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 227 insertions(+), 21 deletions(-)
diff --git a/_scss/misc.scss b/_scss/misc.scss
index 6376d90..819c67d 100644
--- a/_scss/misc.scss
+++ b/_scss/misc.scss
@@ -356,6 +356,7 @@ pre.console {
code {
white-space: nowrap !important;
color: #C0392B;
+ font-size: 100% !important;
i {
font-style: normal;
diff --git a/blogs/short_term_memory.html b/blogs/short_term_memory.html
index 19d827a..c9951cd 100644
--- a/blogs/short_term_memory.html
+++ b/blogs/short_term_memory.html
@@ -29,29 +29,26 @@ publish_date: July 26, 2019
<section id="">
<p>
- <img alt="" class="img-fluid" src="/images/stm1.png">
- </p>
- <p>
- In this blog, I’ll try to give a high-level overview of STM -
Short-Term Memory, a technique used to
+ 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).
+ 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.
+ Let's dive in.
</p>
</section>
<section>
<h2 class="section-title">Parsing User Input</h2>
<p>
One of the key objectives when parsing user input sentence for Natural
Language Understanding (NLU) is to
- detect all possible semantic entities, a.k.a <em>named entities</em>.
Let’s consider a few examples:
+ detect all possible semantic entities, a.k.a <em>named entities</em>.
Let's consider a few examples:
</p>
<ul>
<li>
- <code>"What’s the current weather in Tokyo?"</code><br/>
+ <code>"What's the current weather in Tokyo?"</code><br/>
This sentence is fully sufficient for the processing
since it contains the topic <code>weather</code> as well as all
necessary parameters
like time (<code>current</code>) and location (<code>Tokyo</code>).
@@ -62,13 +59,13 @@ publish_date: July 26, 2019
question - what is it about Tokyo?
</li>
<li>
- <code>"What’s the weather?"</code><br/>
+ <code>"What's the weather?"</code><br/>
This is also unclear since we are missing important parameters
of location and time for our request.
</li>
</ul>
<p>
- Sometimes we can use default values like the current user’s location
and the current time (if they are missing).
+ Sometimes we can use default values like the current user's location
and the current time (if they are missing).
However, this can easily lead to the wrong interpretation if the
conversation has an existing context.
</p>
<p>
@@ -79,7 +76,7 @@ publish_date: July 26, 2019
<section>
<h2 class="section-title">Semantic Entities</h2>
<p>
- Let’s take a closer look at the named entities from the above examples:
+ Let's take a closer look at the named entities from the above examples:
</p>
<ul>
<li>
@@ -165,8 +162,8 @@ publish_date: July 26, 2019
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>
- (still talking about weather in Kyoto) - he’ll likely be thoroughly
confused. The conversation is timed out, and
+ 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>
+ (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>
<p>
@@ -183,7 +180,7 @@ publish_date: July 26, 2019
automating this task by the computer is anything but effortless...
</p>
<p>
- Let’s continue our weather-related conversation. All of a sudden, we
ask about something completely different:
+ Let's continue our weather-related conversation. All of a sudden, we
ask about something completely different:
</p>
<ul>
<li>
@@ -192,24 +189,232 @@ publish_date: July 26, 2019
that we are talking about coffee in Starbucks.
</li>
<li>
- <code>"What about Peet’s?"</code><br/>
- We are talking about latter at Peet’s.
+ <code>"What about Peet's?"</code><br/>
+ We are talking about latter at Peet's.
</li>
<li>
<code>"...and croissant?"</code><br/>
- Asking about Peet’s crescent-shaped fresh rolls.
+ Asking about Peet's crescent-shaped fresh rolls.
</li>
</ul>
<p>
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
+ 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
- conversation in case of “soft” switch.
+ conversation in case of "soft" switch.
</p>
</section>
<section>
- <h2
+ <h2 class="section-title">Overriding Entities</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>
+ replaced <code>"Starbucks"</code> in our previous questions. <b>The
actual algorithm that governs this logic is one
+ of the most important part of STM implementation.</b> In human
conversations we perform this logic seemingly
+ subconsciously — but the computer algorithm to do it is not that
trivial. Let's see how it is done in NLPCraft.
+ </p>
+ <p>
+ One of the important supporting design decision is that an entity can
belong to one or more groups. You can think of
+ groups as types, or classes of entities (to be mathematically precise
these are the categories). The entity's
+ membership in such groups is what drives the rule of overriding.
+ </p>
+ <p>
+ Let's look at the specific example.
+ </p>
+ <p>
+ Consider a data model that defined 3 entities:
+ </p>
+ <ul>
+ <li>
+ <code>"sell"</code> (with synonym <code>"sales"</code>)
+ </li>
+ <li>
+ <code>"buy"</code> (with synonym <code>"purchase"</code>)
+ </li>
+ <li>
+ <code>"best_employee"</code> (with synonyms like
<code>"best"</code>, <code>"best employee"</code>, <code>"best
colleague"</code>)
+ </li>
+ </ul>
+ <p>
+ Our task is to support for following conversation:
+ </p>
+ <ul>
+ <li>
+ <code>"Give me the sales data"</code><br/>
+ We return sales information since we detected <code>"sell"</code>
entity by its synonym <code>"sales"</code>.
+ </li>
+ <li>
+ <code>"Who was the best?"</code><br/>
+ We return the best salesmen since we detected
<code>"best_employee"</code> and we should pick <code>"sell"</code> entity from
the STM.
+ </li>
+ <li>
+ <code>"OK, give me the purchasing report now."</code><br/>
+ This is a bit trickier. We should return general purchasing data
and not a best purchaser employee.
+ It feels counter-intuitive but we should NOT take
<code>"best_employee"</code> entity from STM and, in fact, we should remove it
from STM.
+ </li>
+ <li>
+ <code>"...and who's the best there?"</code><br/>
+ Now, we should return the best purchasing employee. We detected
<code>"best_employee"</code> entity and we should pick <code>"buy"</code>
entity from STM.
+ </li>
+ <li>
+ <code>"One more time - show me the general purchasing data
again"</code><br/>
+ Once again, we should return a general purchasing report and
ignore (and remove) <code>"best_employee"</code> from STM.
+ </li>
+ </ul>
+</section>
+<section>
+ <h2 class="section-title">Overriding Rule</h2>
+ <p>
+ Here's the rule we developed at NLPCraft and have been successfully
using in various models:
+ </p>
+ <div class="bq success">
+ <b>Overriding Rule</b>
+ <p>
+ The entity will override other entity or entities in STM that
belong to the same group set or its superset.
+ </p>
+ </div>
+ <p>
+ In other words, an entity with a smaller group set (more specific one)
will override entity with the same
+ or larger group set (more generic one).
+ Let's consider an entity that belongs to the following groups:
<code>{G1, G2, G3}</code>. This entity:
+ </p>
+ <ul>
+ <li>
+ WILL override existing entity belonging to <code>{G1, G2,
G3}</code> groups (same set).
+ </li>
+ <li>
+ WILL override existing entity belonging to <code>{G1, G2, G3,
G4}</code> groups (superset).
+ </li>
+ <li>
+ WILL NOT override existing entity belonging to <code>{G1,
G2}</code> groups.
+ </li>
+ <li>
+ WIL NOT override existing entity belonging to <code>{G10,
G20}</code> groups.
+ </li>
+ </ul>
+ <p>
+ Let's come back to our sell/buy/best example. To interpret the
questions we've outlined above we need to
+ have the following 4 intents:
+ </p>
+ <ul>
+ <li><code>id=sale term={id=='sale'}</code></li>
+ <li><code>id=best_sale_person term={id=='sale'}
term={id==best_employee}</code></li>
+ <li><code>id=buy term={id=='buy'}</code></li>
+ <li><code>id=buy_best_person term={id=='buy'}
term={id==best_employee}</code></li>
+ </ul>
+ <p>
+ (this is actual <a href="/intent-matching.html#syntax">Intent DSL</a>
used by NLPCraft -
+ <code>term</code> here is basically what's often referred to as a slot
in other systems).
+ </p>
+ <p>
+ We also need to properly configure groups for our entities (names of
the groups are arbitrary):
+ </p>
+ <ul>
+ <li>Entity <code>"sell"</code> belongs to group <b>A</b></li>
+ <li>Entity <code>"buy"</code> belongs to group <b>B</b></li>
+ <li>Entity <code>"best_employee"</code> belongs to groups <b>A</b> and
<b>B</b></li>
+ </ul>
+ <p>
+ Let’s run through our example again with this configuration:
+ </p>
+ <ul>
+ <li>
+ <code>"Give me the sales data"</code>
+ <ul>
+ <li>We detected entity from group <b>A</b>.</li>
+ <li>STM is empty at this point.</li>
+ <li>Return general sales report.</li>
+ <li>Store <code>"sell"</code> entity with group <b>A</b> in
STM.</li>
+ </ul>
+ </li>
+ <li>
+ <code>"Who was the best?"</code>
+ <ul>
+ <li>We detected entity belonging to groups <b>A</b> and
<b>B</b>.</li>
+ <li>STM has entity belonging to group <b>A</b>.</li>
+ <li><b>{A, B}</b> does NOT override <b>{A}</b>.</li>
+ <li>Return best salesmen report.</li>
+ <li>Store detected <code>"best_employee"</code> entity.</li>
+ <li>STM now has two entities with <b>{A}</b> and <b>{A, B}</b>
group sets.</li>
+ </ul>
+ </li>
+ <li>
+ <code>"OK, give me the purchasing report now."</code>
+ <ul>
+ <li>We detected <code>"buy"</code> entity with group
<b>A</b>.</li>
+ <li>STM has two entities with <b>{A}</b> and <b>{A, B}</b>
group sets.</li>
+ <li><b>{A}</b> overrides both <b>{A}</b> and <b>{A,
B}</b>.</li>
+ <li>Return general purchasing report.</li>
+ <li>Store <code>"buy"</code> entity with group <b>A</b> in
STM.</li>
+ </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>
+ <h2 class="section-title">Explicit Context Switch</h2>
+ <p>
+ In some cases you may need to explicitly clear the conversation STM
without relying on algorithmic behavior.
+ It happens when current and new topic of the conversation share some
of the same entities. Although at first
+ it sounds counter-intuitive there are many examples of that in day to
day life.
+ </p>
+ <p>
+ Let’s look at this sample conversation:
+ </p>
+ <ul>
+ <li>
+ <b>Q</b>: <code>"What the weather in Tokyo?"</code><br/>
+ <b>A</b>: Current weather in Tokyo...
+ </li>
+ <li>
+ <b>Q</b>: <code>"Let’s do New York after all then!"</code><br/>
+ <b>A</b>: Without an explicit conversation reset we would return
current New York weather 🤔
+ </li>
+ </ul>
+ <p>
+ The second question was about going to New York (booking tickets,
etc.). In real life - your
+ counterpart will likely ask what you mean by "doing New York after
all" and you’ll have to explain
+ the abrupt change in the topic.
+ You can avoid this confusion by simply saying: "Enough about weather!
Let’s talk about this weekend plans" - after
+ which the second question becomes clear. That sentence is an explicit
context switch which you can also detect
+ 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</h2>
+ <p>
+ Let’s collect all our thoughts on STM into a few bullet points:
+ </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>