Intent resolution#

Intent resolution from ambiguous commands and context cues (robots, assistants, interfaces).

A user’s intent is one of K options (“fetch the red cup”, “fetch the blue cup”, …). Each context cue (a word, a gesture, a gaze direction, the time of day) carries a likelihood over intents. Classical Bayesian updating multiplies the likelihoods, so the order in which cues arrive does not matter.

QuantumIntentResolver represents belief as amplitudes \(\psi = \sqrt{\text{prior}}\) and applies each cue c as a Kraus operator

\[K_c = R(\theta_c)\,\mathrm{diag}\bigl(\sqrt{L_c}\bigr)\,R(\theta_c)^T,\]

where \(R(\theta_c)\) rotates the intent basis by the cue’s incompatibility angle \(\theta_c\), in the plane of the cue’s two most likely intents. With every \(\theta_c = 0\) the posterior is exactly Bayes’ rule; \(\theta_c \neq 0\) makes cues incompatible, so their order matters, as in question-order effects. The angles can be fitted to observed choices.

Examples

>>> from quantum_mind.applications.intent import QuantumIntentResolver
>>> r = QuantumIntentResolver(['red cup', 'blue cup', 'bowl'])
>>> _ = r.add_cue('points left', [0.70, 0.20, 0.10], theta=0.5)
>>> _ = r.add_cue('looks right', [0.25, 0.60, 0.15], theta=0.5)
>>> r.posterior(['points left', 'looks right']).round(3)
array([0.482, 0.498, 0.02 ])
>>> round(r.order_effect('points left', 'looks right'), 3)
0.079

Classes

QuantumIntentResolver

Quantum-like intent resolver; it reduces to BayesIntentResolver when every angle is 0.

BayesIntentResolver

Classical baseline: posterior proportional to the prior times the cue likelihoods.

class QuantumIntentResolver(intents, prior=None)[source]#

Bases: BayesIntentResolver

Quantum-like intent resolver; it reduces to BayesIntentResolver when every angle is 0.

Parameters:
  • intents (sequence of str) – Names of the K possible intents.

  • prior (array_like, optional) – Prior over intents; the initial amplitudes are its square roots.

add_cue(name, likelihood, theta=0.0)[source]#

Register a cue as a Kraus operator.

Parameters:
  • name (str) – Cue name.

  • likelihood (array_like) – Non-negative likelihood of the cue under each intent.

  • theta (float, optional) – Incompatibility angle in radians (0: the cue commutes with every other cue).

Returns:

QuantumIntentResolver – self.

posterior(cues)[source]#

Intent probabilities \(|\psi|^2\) after applying the cues in order.

Parameters:

cues (sequence of str) – Names of registered cues, in the order they arrived.

Returns:

numpy.ndarray

resolve(cues)[source]#

Most likely intent after the cues.

Parameters:

cues (sequence of str) – Names of registered cues, in order.

Returns:

  • intent (str) – Most likely intent.

  • probability (float) – Its posterior probability.

  • entropy (float) – Entropy of the posterior in bits (high values suggest asking for clarification).

class BayesIntentResolver(intents, prior=None)[source]#

Bases: object

Classical baseline: posterior proportional to the prior times the cue likelihoods.

Parameters:
  • intents (sequence of str) – Names of the K possible intents.

  • prior (array_like, optional) – Prior over intents (normalised); uniform by default.

Variables:

cues (dict) – Registered cues, by name.

add_cue(name, likelihood, theta=0.0)[source]#

Register a cue.

Parameters:
  • name (str) – Cue name.

  • likelihood (array_like) – Non-negative likelihood of the cue under each intent.

  • theta (float, optional) – Ignored here (classical cues commute); used by QuantumIntentResolver.

Returns:

BayesIntentResolver – self, so calls can be chained.

posterior(cues)[source]#

Intent probabilities after a sequence of cues.

Parameters:

cues (sequence of str) – Names of registered cues.

Returns:

numpy.ndarray – Posterior over intents (independent of the order of cues).

order_effect(a, b)[source]#

Size of the order effect between two cues.

Parameters:
  • a (str) – Cue names.

  • b (str) – Cue names.

Returns:

float – Total variation distance between the posteriors for orders (a, b) and (b, a); always 0 for the Bayesian resolver.