Language
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
The Decision Task is experimental, not supported for use in production environments, and requires Windows ML 2.9 experimental or later.
The Decision Task evaluates a state, such as a message, a support ticket, or a serialized document, against typed questions. For each question it returns a probability for every option, the selected option, a confidence, and a recommendation to act or to escalate. A decision is a single evaluation per question, so the Task generates no text.
The Decision Task takes a published decision model folder as its model, and Windows ML compiles the model for the GPU with the CGC backend. For now, use Laya, the validated decision model in the recommended models. It requires a GPU execution target, and a CPU target returns HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED). For how Tasks run models, see Choose how a Task runs your model.
Question kinds
| Kind | Options |
|---|---|
| Choice | At least one. Each has a unique label and an optional description. |
| Score | At least one. Option i is level i, and its description states the criterion for that level. |
| Yes/no | None, which uses the model's default description of both answers, or exactly two (false, then true). |
A question can set an act threshold from 0 to 1. The answer recommends ACT when its confidence reaches the threshold and ESCALATE otherwise. Without a threshold, the recommendation is ACT when the model's act probability is at least 0.5.
Decide
Load the model folder with LoadModelFromPath, create the Task with CreateDecisionTaskFromModel, create a session, and call Decide with a state and its questions. The tokenizer is optional: with nullptr, the Task creates the model's own tokenizer from the model folder.
// Temporary: WinMLRuntime and the other wrapper types in the WinMLSamples.Runtime
// namespaces aren't in the Windows ML package yet. Copy the wrapper files from
// https://github.com/microsoft/WindowsML/tree/main/Samples/Runtime/shared/csharp
// into your project. A future update will include the C# APIs natively.
using WinMLSamples.Runtime;
using WinMLSamples.Runtime.Tasks;
// Load the decision model and create the task on a GPU target.
using WinMLRuntime runtime = WinMLRuntime.Create();
using ExecutionTarget target = runtime.CreateExecutionTarget(
ExecutionTargetKind.Gpu, ExecutionTargetPreference.Performance);
using Model model = runtime.LoadModelFromPath(modelFolder);
using WinMLTasks tasks = WinMLTasks.Create(runtime);
using DecisionTask task = tasks.Decision.CreateDecisionTaskFromModel(target, model);
// Describe a choice question and evaluate a state against it.
DecisionOption[] options =
[
new("billing", "A question about an invoice or payment"),
new("technical", "A problem using the product"),
];
DecisionQuestion question = new()
{
Kind = DecisionQuestionKind.Choice,
Instructions = "Which team should handle this support ticket?",
Options = options,
};
DecisionRequest request = new()
{
State = "I was charged twice for my subscription.",
Questions = [question],
};
// A Decider keeps the session on a thread of its own.
await using Decider decider = await Decider.CreateAsync(tasks, task);
using DecisionResult result = await decider.DecideAsync(request, CancellationToken.None);
// Closing the session reports a failure that disposing it would not.
await decider.CloseAsync();
DecisionAnswer answer = result.GetAnswer(0);
float[] probabilities = new float[options.Length];
result.GetProbabilities(0, probabilities);
Read the answer
| Field | Meaning |
|---|---|
selectedOption |
The most probable option. For yes/no questions, 1 means true. |
confidence |
The probability of the selected option. |
distributionConfidence |
One minus the normalized entropy of the distribution: 1 when all probability is on one option, 0 when uniform. It isn't a calibrated probability. |
expectedScore |
For score questions, the expected level. |
actProbability |
The model's estimate that the answer can be acted on. |
recommendation |
ACT or ESCALATE. |
A state that's longer than the room a question leaves in the model's sequence is truncated at its end. Pass a structured state in its serialized text form.
Keep compiled programs
As with the other Tasks that use the CGC backend, the first session compiles programs for the GPU. Set compiledProgramDirectory in the model options to reuse them in later processes. See Cache compiled programs.