我们提供苏小锦人工智能助手招投标所需全套资料,包括苏小锦人工智能助手介绍PPT、苏小锦人工智能助手产品解决方案、
苏小锦人工智能助手产品技术参数,以及对应的标书参考文件,详请联系客服。
import spacy
nlp = spacy.load("zh_core_web_sm") # 加载中文模型
text = "明天的数学课在301教室"
doc = nlp(text)
print("实体提取结果:")
for ent in doc.ents:
print(ent.text, ent.label_)
print("\n意图识别:")
# 这里可以加入更复杂的逻辑来判断意图
if "数学" in text and "教室" in text:
print("意图:查询课程安排")
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import Pipeline
# 示例数据
X_train = [
"明天的数学课在哪个教室?",
"帮我查一下图书馆开放时间。",

"请问下个月的考试安排是什么时候?"
]
y_train = ["课程安排", "图书馆信息", "考试时间"]
# 构建管道
model = Pipeline([
('vectorizer', CountVectorizer()),
('classifier', MultinomialNB())
])
# 训练模型
model.fit(X_train, y_train)
# 预测新句子
new_text = "下周的英语考试在哪里举行?"
prediction = model.predict([new_text])
print(f"预测意图:{prediction[0]}")
# domain.yml
intents:
- 咨询课程安排
- 查询图书馆信息
- 查询考试时间
entities:
- 课程名称
- 时间
- 地点
responses:
utter_greet:
- text: "你好!有什么可以帮助你的吗?"
actions:
- action_default_fallback
# stories.md
## 咨询课程安排
* 咨询课程安排
- action_greet
* 咨询课程安排{"课程名称": "数学", "时间": "明天"}
- utter_course_info
* 咨询课程安排{"课程名称": "英语", "时间": "下周"}
- utter_course_info
# actions.py
from rasa_sdk import Action
from rasa_sdk.events import SlotSet
class ActionCourseInfo(Action):
def name(self):
return "action_course_info"
async def run(self, dispatcher, tracker, domain):
course_name = tracker.get_slot("课程名称")
time = tracker.get_slot("时间")

response = f"关于{course_name}课程,在{time}的时间安排是..."
dispatcher.utter_message(response)
return []