在我的Dialogflow项目中,我正在使用Python客户端library批量上传训练短语,具体如下:
training_phrases = []
for training_phrases_part in training_phrases_parts:
part = dialogflow.types.Intent.TrainingPhrase.Part(
text=training_phrases_part)
# Here we create a new training phrase for each provided part.
training_phrase = dialogflow.types.Intent.TrainingPhrase(parts=[part])
training_phrases.append(training_phrase)
但是,除了训练短语本身之外,我想知道是否还可以上传标记在短语中的实体。例如,假设我有一个训练短语“我喜欢苹果”,其中“苹果”被标记为实体。如何将这些信息与短语一起传递给Dialogflow?我知道我总是可以在用户界面中手动突出显示实体,但是我很好奇是否有使用客户端库进行编程的方式。
谢谢!
答案 0 :(得分:0)
使用API时,您必须通过将实体和短语的其余部分分成不同的部分来手动注释训练短语,大致如下:
from dialogflow_v2.types import Intent
parts = [
Intent.TrainingPhrase.Part(text='I like '), # Note the space at the end, you have to add them manually
Intent.TrainingPhrase.Part(text='apples', entity_type='@fruit:fruit')
]
training_phrase = Intent.TrainingPhrase(parts=parts)
答案 1 :(得分:0)
如何使用对话框流python客户端API将所有训练短语中的特定单词作为一个实体检测为一个实体,同时将其添加为一堆。我正在共享我的代码,以更好地理解。在这段代码中,我想检测“ John
”单词作为通过对话流客户端添加的训练短语中的名称实体。现在,通过此代码,它可以将训练短语的整个句子检测为一个实体。就像有Hi john
一样,它应该只检测john作为名称实体,但会检测整个短语。
intents_client = dialogflow.IntentsClient()
parent = intents_client.project_agent_path(DIALOGFLOW_PROJECT_ID)
training_phrases_parts = ["JOhn", " Hey John", " Hi john "]
training_phrases = []
for training_phrases_part in training_phrases_parts:
part = (
# Intent.TrainingPhrase.Part(text=training_phrases_part ),
Intent.TrainingPhrase.Part(text=training_phrases_part, entity_type='@sys.given-name', alias='name'))
# Here we create a new training phrase for each provided part.
training_phrase = Intent.TrainingPhrase(parts=[part])
training_phrases.append(training_phrase)
text = dialogflow.types.Intent.Message.Text(text=["its working", "hey its great" ,"testing"])
message = dialogflow.types.Intent.Message(text=text)
intent = dialogflow.types.Intent(
display_name='name',
training_phrases=training_phrases,
messages=[message])
# response = intents_client.create_intent(parent, intent)
try:
response = intents_client.create_intent(parent, intent)
except InvalidArgument:
raise