日本語でのRasaを使用したチャットボットの作成
このガイドでは、Rasa を使用して日本語対応のチャットボットを作成し、「ビッグカメラ」などの IT ガジェットショップでの販売をサポートする方法について説明します。
ステップ 1: Rasa のインストール
Python がインストールされていることを確認し、pip を使用して Rasa をインストールします。
pip install rasa
ステップ 2: 新しい Rasa プロジェクトを初期化
新しい Rasa プロジェクトを作成します:
rasa init --no-prompt
このコマンドで、デフォルトのプロジェクト構造が生成されます。
ステップ 3: 日本語サポートの追加
config.yml
ファイルを編集して、日本語をサポートするようにします。日本語を効果的に処理できるトークナイザーとパイプラインを使用します。
language: ja
pipeline:
- name: "JiebaTokenizer"
- name: "RegexFeaturizer"
- name: "LexicalSyntacticFeaturizer"
- name: "CountVectorsFeaturizer"
analyzer: "word"
- name: "CountVectorsFeaturizer"
analyzer: "char_wb"
min_ngram: 1
max_ngram: 4
- name: "DIETClassifier"
epochs: 100
- name: "EntitySynonymMapper"
- name: "ResponseSelector"
epochs: 100
- name: "FallbackClassifier"
threshold: 0.3
ステップ 4: インテントとレスポンスの定義
domain.yml
ファイルに、チャットボットで使用するインテントとレスポンスを定義します。
intents:
- greet
- ask_discount
- ask_camera_features
- check_stock
- thank_you
responses:
utter_greet:
- text: こんにちは!ビッグカメラ IT ガジェットショップへようこそ!
utter_ask_discount:
- text: このカメラは今だけ特別価格で提供されています!どのモデルに興味がありますか?
utter_ask_camera_features:
- text: ご希望のカメラの特徴を教えてください。高画質ですか?ズームレンズですか?
utter_check_stock:
- text: ご希望のモデル名を教えてください。在庫状況を確認します。
utter_thank_you:
- text: ありがとうございます!他に質問があればお気軽にお問い合わせください。
ステップ 5: トレーニングデータの作成
data/nlu.yml
ファイルに日本語でトレーニングデータを追加します。
version: "3.0"
nlu:
- intent: greet
examples: |
- こんにちは
- ハロー
- intent: ask_discount
examples: |
- 特別価格の商品はありますか?
- 値引きはありますか?
- intent: ask_camera_features
examples: |
- このカメラにはどんな特徴がありますか?
- 高画質のカメラはどれですか?
- intent: check_stock
examples: |
- このモデルは在庫がありますか?
- 在庫状況を教えてください。
- intent: thank_you
examples: |
- ありがとう
- 感謝します
ステップ 6: カスタムアクションの作成
在庫を確認するカスタムアクションを actions/actions.py
ファイルに定義します。
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
class ActionCheckStock(Action):
def name(self) -> Text:
return "action_check_stock"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
# 在庫情報の例
stock_data = {
"camera_x": "在庫あり",
"camera_y": "在庫なし",
}
model = tracker.get_slot("camera_model")
if model in stock_data:
stock_status = stock_data[model]
response = f"モデル {model} の在庫状況: {stock_status}"
else:
response = "指定されたモデルは見つかりませんでした。"
dispatcher.utter_message(text=response)
return []
domain.yml
ファイルを更新して、カスタムアクションとスロットを追加します。
actions:
- action_check_stock
slots:
camera_model:
type: text
ステップ 7: ストーリーの作成
在庫確認のストーリーを data/stories.yml
に追加します。
version: "3.0"
stories:
- story: Check Stock
steps:
- intent: check_stock
- action: utter_check_stock
- slot_was_set:
- camera_model: "camera_x"
- action: action_check_stock
ステップ 8: チャットボットのテスト
以下のコマンドを使用してチャットボットを実行します。
rasa train
rasa shell
日本語でテストメッセージを入力して動作を確認します。
ステップ 9: チャットボットのデプロイ
Rasa X を使用するか、ウェブインターフェースと統合してチャットボットをデプロイします。
ステップ 10: 継続的な改善
チャットボットのパフォーマンスを分析し、トレーニングデータを最適化して、さまざまなユーザーの問い合わせに対応できるようモデルを改善します。
Rasa のワークフロー
以下は、Rasa のワークフローを MermaidJS で視覚化したものです。
graph TD
User[ユーザー入力] -->|メッセージ送信| NLU[NLU パイプライン]
NLU -->|インテントとエンティティを分類| Core[Rasa Core]
Core -->|ポリシーに従う| Action[アクションサーバー]
Action -->|カスタムアクションまたはレスポンスを実行| Bot[ボットレスポンス]
Bot -->|ユーザーに返信| User
subgraph Rasa システム
NLU
Core
Action
end
このガイドを参考に、日本語対応の Rasa チャットボットを作成して、「ビッグカメラ」や他の IT ガジェットショップの販売を支援してください。
Get in Touch with us
Related Posts
- How to Build an AI-Resistant Project: Ideas That Thrive on Human Interaction
- Build Your Own Cybersecurity Lab with GNS3 + Wazuh + Docker: Train, Detect, and Defend in One Platform
- How to Simulate and Train with Network Devices Using GNS3
- What Is an LMS? And Why You Should Pay Attention to Frappe LMS
- Agentic AI in Factories: Smarter, Faster, and More Autonomous Operations
- Smarter, Safer EV Fleets: Geo-Fencing and Real-Time Tracking for Electric Motorcycles
- How to Implement Google Single Sign-On (SSO) in FastAPI
- Build Your Own Taxi Booking App with Simplico: Scalable, Secure & Ready to Launch
- Building a Scalable EV Charging Backend — For Operators, Developers, and Innovators
- How to Handle Complex Pricing for Made-to-Order Products in Odoo
- How to Build a Made-to-Order Product System That Boosts Sales & Customer Satisfaction
- Transform Your Operations with Autonomous Agentic AI
- Streamline Fiber Tester Management with a Lightweight EXFO Admin Panel
- Enhancing Naval Mission Readiness with EMI Simulation: Cost-Effective Risk Reduction Using MEEP and Python
- Strengthen Your Cybersecurity Posture with Wazuh: A Scalable, Cost-Effective SIEM Solution
- OCPP Central System + Mobile App — Customer Proposal
- How TAK Systems Are Transforming Border Security
- ChatGPT-4o vs GPT-4.1 vs GPT-4.5: Which Model Is Best for You?
- Can Clients Decrypt Server Data Without the Private Key? (Spoiler: No—and Here’s Why)
- Managing JWT Authentication Across Multiple Frameworks