【发布时间】:2019-08-03 02:47:34
【问题描述】:
我已成功让我的代码检测到正确的意图,但即使我在训练数据中提供了一些实体,也没有出现实体。
数据.json:
{ “common_examples”: [
{ “text”:“Hello”,
“intent”:“greeting”,
“entities”:[] },
{ “text”:“Hi”,
“intent”:“greeting”,
“entities”:[] },
{ “text”:“I want a recipe for my lunch”,
“intent”:“get_recipe”,
“entities”:[
{ “start”:22,
“end”: 28,
“value”: “lunch”,
“entity”: “mealtime” }
]
},
{ “text”:“Can you give me a recipe for dinner tonight?”,
“intent”:“get_recipe”,
“entities”:[
{ “start”:29,
“end”:35,
“value”: “dinner”,
“entity”: “mealtime” }
]
},
{ “text”:“I don’t know what to have for lunch”,
“intent”:“get_recipe”,
“entities”:[
{ “start”:31,
“end”: 35,
“value”: “lunch”,
“entity”: “mealtime” }
]
}
},
}
],
"regex_features": [],
"entity_synonyms":[]
}
}
这只是一个sn-p。我总共为 get_recipe 意图创建了 15 个示例。我只需要它从发送给机器人的消息中挑选出“用餐时间”的实体。
我的config.yml如下:
language: “en”
pipeline:
-name: “nlp_spacy”
-name: “tokenizer_spacy”
-name: “intent_entity_featurizer_regex”
-name: “intent_featurizer_spacy”
-name: “ner_crf”
-name: “ner_synonyms”
-name: “intent_featurizer_count_vectors”
-name: “intent_classifier_tensorflow_embedding”
这是我用来训练机器人的代码:
from rasa_nlu.training_data import load_data
from rasa_nlu.model import Trainer
from rasa_nlu import config
from rasa_nlu.model import Interpreter
def train_bot(data_json,config_file,model_dir):
training_data = load_data(data_json)
trainer = Trainer(config.load(config_file))
trainer.train(training_data)
model_directory=trainer.persist(model_dir,fixed_model_name=‘vegabot’)
运行良好。
我运行来预测意图的代码:
def predict_intent(text):
interpreter = Interpreter.load(‘models/nlu/default/vegabot’)
print(interpreter.parse(text))
产生结果:
{‘intent’: {‘name’: ‘get_recipe’, ‘confidence’: 0.9701309204101562}, ‘entities’: [], ‘intent_ranking’: [{‘name’: ‘get_recipe’, ‘confidence’: 0.9701309204101562}, {‘name’: ‘greeting’, ‘confidence’: 0.03588612377643585}], ‘text’: ‘can you find me a recipe for dinner’}
如您所见,意图是正确的,但实体为空白 [],我不知道为什么。我似乎没有收到任何错误。除了这个,一切都运行良好!
我还进行了评估并得到:
- intent examples: 12 (2 distinct intents)
- Found intents: ‘greeting’, ‘get_recipe’
- entity examples: 10 (1 distinct entities)
- found entities: ‘mealtime’ which all looks fine.
很明显它知道要注意用餐时间实体,但为什么不从我的测试消息中提取它?
例如我需要一份午餐食谱,你能给我一份晚餐时间的食谱吗?等等
我使用的是 RASA NLU 0.14 版。
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
ner_crf根据位置线索提取实体。您可以尝试添加更多类似类型的示例。例如> I don’t know what to have for lunch. > I do not know what to have for lunch. > I don't really know what to have for lunch告诉我进展如何。 -
@msv 我添加了更多类似的示例,它似乎有效,谢谢!
-
很高兴它成功了!请确保在stackoverflow上推广正确的答案:)
标签: tensorflow chatbot rasa-nlu named-entity-recognition crf