我使用的是windows10机器上的snips-nlu库。
我能够使用pip install snips-nlu成功安装它,然后使用snips-nlu download en安装该语言。我的example.py文件如下所示:
engine = SnipsNLUEngine(resources=load_resources('snips_nlu_en')) # this works for me
# engine = SnipsNLUEngine(resources=load_resources('en')) # this throws errors about en not being installed even after installing them
with io.open("dataset.json") as f:
dataset = json.load(f)
engine.fit(dataset)
parsing = engine.parse("Are there holidays next week in botswana?")
print(json.dumps(parsing, indent=2))执行时,我得到以下输出:
{
"input": "Are there holidays next week in botswana?",
"intent": {
"intentName": null,
"probability": 0.4607009138432084
},
"slots": []
}我的yaml文件如下所示:
# ask for country holidays
---
type: intent
name: holidayQuestion
slots:
- name: country
entity: snips/country
- name: date
entity: snips/datetime
utterances:
- What holidays is it [date] in [country]?
- Is it a holiday in [country]?
- Is it a holiday [date] in [country]?
- Is it a [country] holiday [date]?
- Holiday [date] in [country]?
- Holiday [date] [country]?
- Holiday [country]?我用snips-nlu generate-dataset en dataset.yaml > dataset.json把它转换成json文件。
当我执行我的python文件时,它会报错:
FileNotFoundError: No data found for the 'snips/country' builtin entity in language 'en'. You must download the corresponding resources by running 'python -m snips_nlu download-entity snips/country en' before you can use this builtin entity.我在windows cmd上使用管理员权限执行它,但它仍然返回空插槽和没有intentName。有人能帮我解释一下发生了什么事吗?我已经尝试卸载pip、python和所有包,重新启动计算机并清除与python/pip相关的环境变量。但没有骰子。
发布于 2019-11-27 19:17:08
首先,为了避免使用管理员权限运行命令,您应该在virtual environment中运行所有内容。
在virtualenv中运行后,在您的用例中使用snips-nlu之前,您必须安装英文资源和snips/country内置实体:
python -m snips_nlu download en
python -m snips_nlu download-entity snips/country en这通常会下载并链接相应的资源,以便snips-nlu库可以在默认位置访问它们。如果您由于权限错误而未在virtualenv中运行,则这两个命令可能会失败。
在此之后,您可以尝试使用CLI处理数据集:
> python -m snips_nlu train dataset.json nlu_engine
Create and train the engine...
Persisting the engine...
Saved the trained engine to nlu_engine然后:
> python -m snips_nlu parse nlu_engine
Enter a query (type 'q' to quit): Are there holidays next week in botswana?
{
"input": "Are there holidays next week in botswana?",
"intent": {
"intentName": "holidayQuestion",
"probability": 0.7427372869733698
},
"slots": [
{
"entity": "snips/datetime",
"range": {
"end": 28,
"start": 19
},
"rawValue": "next week",
"slotName": "date",
"value": {
"grain": "Week",
"kind": "InstantTime",
"precision": "Exact",
"value": "2019-12-02 00:00:00 +01:00"
}
},
{
"entity": "snips/country",
"range": {
"end": 40,
"start": 32
},
"rawValue": "botswana",
"slotName": "country",
"value": {
"kind": "Country",
"value": "Botswana"
}
}
]
}你能分享你正在使用的snips-nlu版本吗?如果可能,您应该更新到最新的可用版本。
https://stackoverflow.com/questions/58974181
复制相似问题