Language

Windows ML タスクを使用して意思決定を行う

Important

Decision Task は実験的な機能であり、運用環境での使用はサポートされていません。また、Windows ML 2.9 Experimental 以降が必要です。

決定タスクは、メッセージ、サポート チケット、シリアル化されたドキュメントなどの状態を、型指定された質問に対して評価します。 各質問について、すべてのオプションの確率、選択したオプション、信頼度、行動またはエスカレートの推奨事項が返されます。 決定は質問ごとに 1 つの評価であるため、タスクはテキストを生成しません。

デシジョン タスクは、公開されたデシジョン モデル フォルダーをモデルとして受け取り、Windows ML は CGC バックエンドを使用して GPU のモデルをコンパイルします。 当面は、推奨モデルに含まれる検証済みの意思決定モデル Laya をご利用ください。 GPU 実行ターゲットが必要であり、CPU ターゲットでは HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) が返されます。 タスクによるモデルの実行方法については、タスクによるモデルの実行方法の選択を参照してください。

質問の種類

サブタイプ オプション
選択肢 少なくとも 1 つ。 それぞれに一意のラベルとオプションの説明があります。
Score 少なくとも 1 つ。 オプション i はレベル iであり、その説明ではそのレベルの条件が示されます。
はい/いいえ 「なし」: モデルのデフォルトの記述を両方の回答に適用する場合、または正確に 2 つ (false、次に true) の場合。

質問では、act しきい値を 0 から 1 に設定できます。 この回答は、信頼度がしきい値に達したときに ACT を推奨し、それ以外の場合は ESCALATE を推奨します。 しきい値がない場合、モデルの動作確率が 0.5 以上であれば、推奨される回答は ACT です。

決定

LoadModelFromPathを使用してモデル フォルダーを読み込み、CreateDecisionTaskFromModelでタスクを作成し、セッションを作成して、状態とその質問を含むDecideを呼び出します。 トークナイザーは省略可能です。nullptr を使用すると、Task はモデル フォルダーからモデル独自のトークナイザーを作成します。

// 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);

回答を読む

フィールド Meaning
selectedOption 最も可能性の高いオプション。 はい/いいえの質問の場合、1 は true を意味します。
confidence 選択したオプションの確率。
distributionConfidence 1 から分布の正規化エントロピを引いた値: すべての確率が 1 つのオプションの場合は 1、均一の場合は 0。 これは、較正された確率ではありません。
expectedScore スコアに関する質問で、期待されるレベル。
actProbability 回答に基づいて行動できるというモデルの見積もり。
recommendation ACT または ESCALATE。

モデルのシーケンス内で質問が残す余地よりも長い状態は、末尾で切り捨てられます。 シリアル化されたテキスト 形式で構造化状態を渡します。

コンパイル済みプログラムを保持する

CGC バックエンドを使用する他のタスクと同様に、最初のセッションでは GPU のプログラムがコンパイルされます。 モデル オプションで compiledProgramDirectory を設定して、後のプロセスで再利用します。 コンパイル済みプログラムをキャッシュするを参照してください。

次のステップ