Skip to main content

StateMachineInstruction

StateMachineInstruction defines the single-state instruction used when each input maps to one output state. It maps one or more input TokenSets to a state string selected from your samples.

Key characteristics:

  • Output is created automatically with a single State token
  • Final token is always <NON>
  • Samples provide a state string instead of a response snippet

StateMachineInstruction Parameters​

class StateMachineInstruction:
def __init__(self, input: StateMachineInput, states: List[str]):
  • input: A StateMachineInput instance defining the input TokenSets
  • states: A list of allowed state names for the instruction output

Creating a StateMachineInstruction​

question_tokenset = mtp.TokenSet(tokens=(question, context))

state_machine_input = mtp.StateMachineInput(
tokensets=[question_tokenset]
)

state_machine_instruction = mtp.StateMachineInstruction(
input=state_machine_input,
states=["WHERE"]
)

state_machine_instruction.add_sample(
input_snippets=["Where are you from?"],
state="WHERE"
)

The list of possible states is derived from these samples and stored as the single-state output metadata when state_machine=True. For the multi-state form, see MultiClassifierInstruction. For shared input structure, see StateMachineInput.