Documentation
¶
Overview ¶
Package classifier labels the owner's messages to the embedded agent: what the message asks for (the act facet: command, question, task, correction, approval, chat) and which slot it belongs to (the slot facet: the app's slots and general).
It runs in shadow by default: the agent records each turn's classification beside the turn in the context trace. With the setting surface.agent_selector at "classifier", a sure slot answer overrules the window in front (the agent's classifiedSelector). The trace is also what it learns from: the slot a turn was given, and above all a slot the owner pinned after it, which says the choice was wrong. The replay report (Replay) says whether its answers beat the focus selector on that record (docs/agent.md).
The judges are libs core/util/classify's: the pack's rules and priors (act.json, and slot rules made from each slot's views, modes and name), and a naive Bayes model per facet. All of them run in microseconds, so the same call serves a keystroke and a submit.
It also labels tone (the affect facet: neutral, frustrated, urgent, positive) with libs' lexicon judge. With a decider set (JEV through a decision gateway), ClassifyAsync adds a model's answer to every facet; that is the async tier, run after the turn, off the path.
Index ¶
- Constants
- func Context(sit module.Situation) map[string]string
- func SlotFacet(all []kernel.BoundSlot) (classify.FacetSpec, bool)
- func SlotLabel(t slots.TraceTurn) (label string, weight float64, corrected bool)
- type Classifier
- func (c *Classifier) ActDocs() float64
- func (c *Classifier) Classify(ctx context.Context, sit module.Situation, all []kernel.BoundSlot, ...) (classify.Result, error)
- func (c *Classifier) ClassifyAsync(ctx context.Context, sit module.Situation, all []kernel.BoundSlot, ...) (classify.Result, error)
- func (c *Classifier) Correct(text, slot string)
- func (c *Classifier) Embedder() classify.Embedder
- func (c *Classifier) FitCentroids(ctx context.Context, all []kernel.BoundSlot) error
- func (c *Classifier) HasAsync() bool
- func (c *Classifier) Learn(t slots.TraceTurn)
- func (c *Classifier) LearnAct(text, act string)
- func (c *Classifier) RefitDue() bool
- func (c *Classifier) SetDecider(d decide.Decider, o classify.DecisionOptions)
- func (c *Classifier) SetEmbedder(e classify.Embedder)
- func (c *Classifier) SlotDocs() float64
- func (c *Classifier) SlotExamples(all []kernel.BoundSlot) []classify.Example
- type ReplayMiss
- type ReplayReport
Constants ¶
const ( Act = "act" Slot = "slot" Affect = "affect" )
The facets.
Variables ¶
This section is empty.
Functions ¶
func SlotFacet ¶
SlotFacet is the slot facet for a set of slots: one label per slot and general, priors from what is in front (a view the slot names, the module behind the view, a mode the slot names) and text rules from the slot's and its module's names. With no slot of a module's own there is nothing to choose and no facet.
Types ¶
type Classifier ¶
type Classifier struct {
// contains filtered or unexported fields
}
Classifier is safe for concurrent use.
func New ¶
func New() (*Classifier, error)
New returns a classifier with the built-in act pack and empty models seeded from its examples.
func (*Classifier) ActDocs ¶
func (c *Classifier) ActDocs() float64
ActDocs is how much the act model has learned.
func (*Classifier) Classify ¶
func (c *Classifier) Classify(ctx context.Context, sit module.Situation, all []kernel.BoundSlot, id, text string) (classify.Result, error)
Classify labels text in the situation. all is the app's slots.
func (*Classifier) ClassifyAsync ¶
func (c *Classifier) ClassifyAsync(ctx context.Context, sit module.Situation, all []kernel.BoundSlot, id, text string) (classify.Result, error)
ClassifyAsync is Classify with the async tier: the decider's answer joins the rest. It makes a network call; run it off the turn's path.
func (*Classifier) Correct ¶
func (c *Classifier) Correct(text, slot string)
Correct adds an owner's correction of the newest turn's slot.
func (*Classifier) Embedder ¶
func (c *Classifier) Embedder() classify.Embedder
Embedder is the embedder set, or nil.
func (*Classifier) FitCentroids ¶
FitCentroids fits the slot centroid on SlotExamples (a call through the embedder). With no slot facet (an app with no slots of its own) there is nothing to fit.
func (*Classifier) HasAsync ¶
func (c *Classifier) HasAsync() bool
HasAsync reports whether a decider is set.
func (*Classifier) Learn ¶
func (c *Classifier) Learn(t slots.TraceTurn)
Learn adds one traced turn to the slot model.
func (*Classifier) LearnAct ¶
func (c *Classifier) LearnAct(text, act string)
LearnAct adds an owner's confirmation of a message's act.
func (*Classifier) RefitDue ¶ added in v0.4.0
func (c *Classifier) RefitDue() bool
RefitDue reports whether enough has been learned since the last fit to fit again.
func (*Classifier) SetDecider ¶
func (c *Classifier) SetDecider(d decide.Decider, o classify.DecisionOptions)
SetDecider turns on the async tier: d is asked about every facet at classify.Async. A nil d turns it off.
func (*Classifier) SetEmbedder ¶
func (c *Classifier) SetEmbedder(e classify.Embedder)
SetEmbedder adds a centroid judge on the slot facet at classify.Async, over e. A sentence-embedding model groups texts by topic, not by what they ask for, so the slot (which kind of work) is the facet it can tell; act and affect are left to rules, the n-gram models and the decider. It votes nothing until FitCentroids has run.
func (*Classifier) SlotDocs ¶
func (c *Classifier) SlotDocs() float64
SlotDocs is how much the slot model has learned.
func (*Classifier) SlotExamples ¶ added in v0.4.0
func (c *Classifier) SlotExamples(all []kernel.BoundSlot) []classify.Example
SlotExamples are what the slot centroid is fitted on: each slot's own description (its About, name and module), and the newest texts the slot was given or corrected to.
type ReplayMiss ¶
type ReplayMiss struct {
Text string `json:"text"`
Selector string `json:"selector"`
Owner string `json:"owner"`
Got string `json:"got"`
P float64 `json:"p"`
}
ReplayMiss is a corrected turn the classifier also got wrong.
type ReplayReport ¶
type ReplayReport struct {
Turns int `json:"turns"`
// Agreement is how often the classifier's slot (answered or not) matched the selector's.
Agreement float64 `json:"agreement"`
// Answered is how often the slot facet did not abstain.
Answered float64 `json:"answered"`
// Corrected counts turns the owner re-pinned; on them the selector was wrong.
Corrected int `json:"corrected"`
// CorrectedHits is how many of those the classifier's top slot got right.
CorrectedHits int `json:"corrected_hits"`
// Acts counts the act facet's answers ("" for an abstention).
Acts map[string]int `json:"acts"`
// Misses are corrected turns the classifier got wrong too, up to 20.
Misses []ReplayMiss `json:"misses,omitempty"`
}
ReplayReport is how a fresh classifier would have done on the trace, against the focus selector, turn by turn in order: each turn is classified before it is learned, so every answer is a prediction about a turn the model has not seen.
The gold slot is the one the owner pinned after the turn, else the one the selector gave. So on uncorrected turns the selector is right by definition and Agreement says how often the classifier agrees with it; Corrected is the only place either can be scored fairly.