やりたいこと
最近話題のSystem One ModelsをCudaなし,Windowsのローカル環境で動かしてみます。
Jevが話題ですがローカルモデルではないのでローカルモデルのLayaを試します。
環境構築
Python
Pythonを以下のページからダウンロードしてインストールします。

3.10以上が必要です。環境のPythonが3.10未満の場合はアップデートしてください。
venv環境への移動(任意)
必要であればコマンドプロンプトを開き、以下のコマンドを作業フォルダで実行して、Venvの環境を作成してアクティブにします。
python -mvenv venv
venv\scripts\activate.bat
Laya
以下のコマンドを作業フォルダで実行し、Layaをインストールします。
python -m pip install laya
Script
作業フォルダにrun.pyを作成して以下のスクリプトを貼り付け保存します。
(公式のコードです。)
from laya import Router
router = Router() # downloads a checkpoint on first use; Router(preload=True) loads all three up front
state = "Hi, we were billed twice for March. Please refund the duplicate today or we will cancel our plan."
questions = {
"department": {"type": "choice", "instructions": "Which department should handle this?",
"criteria": {"billing": "invoices, payments, refunds",
"technical": "bugs, outages, system errors",
"other": "everything else"}},
"urgency": {"type": "score", "instructions": "How urgent is this?",
"criteria": ["not urgent", "soon", "blocking"]},
"churn_risk": {"type": "noul", "instructions": "Does the user threaten to cancel or leave?"},
}
result = router.predict(state, questions)
print(result["answers"]["department"]["choice"]) # billing
print(result["answers"]["churn_risk"]["noul"]) # probability the answer is yes
print(result["routing"]["model"]) # english
実行
以下のコマンドを作業フォルダで実行し、Layaを実行します。
python run.py
初回はモデルのダウンロードが行われるため数分かかります。
以下のように(値は異なる可能性があります)表示されれば成功です。
billing
0.879
english
特にCUDAなど気にせずに動作しました。(おそらくCPUで動作していますが、早いので気になりません)
好きなことを聞いてみる
上の例では公式の例で試したので今度は日本語で聞きたいことを聞いてみます。
state には前提条件を書きます。
questions = {“Dish”:のDish部分は質問のラベルです。”instructions”の右側に質問内容を記載します。”criteria”に選択肢を列挙します。左側が選択肢のラベル、右側が選択肢の内容です。
下の例だと “今日の献立はなにがいい?”の回答が”カレー”だったら”Curry”が返ってくるという感じです。
from laya import Router
router = Router() # downloads a checkpoint on first use; Router(preload=True) loads all three up front
state = "今日は魚を食べたいです。"
questions = {
"Dish": {"type": "choice", "instructions": "今日の献立はなにがいい?",
"criteria": {"Curry": "カレー",
"Sushi": "寿司",
"Steak": "ステーキ",
"other": "その他"}},
}
result = router.predict(state, questions)
print(result["answers"]["Dish"]["choice"])
実行結果
実行した結果、魚が食べたいことをくみ取って寿司と返してくれました。
Sushi
日本語などの言語を使用すると追加のモデルが必要になります。
初回はモデルのダウンロードが行われるため数分かかります。
参考にさせていただいたサイト


コメント