Skip to content

Instantly share code, notes, and snippets.

@Decad
Last active September 20, 2020 19:49
Show Gist options
  • Save Decad/e7de645e89e2a66395d7ca560d6be0e0 to your computer and use it in GitHub Desktop.
Save Decad/e7de645e89e2a66395d7ca560d6be0e0 to your computer and use it in GitHub Desktop.
Wildcards with snips-nlu
from __future__ import unicode_literals, print_function
import io
import json
from snips_nlu import SnipsNLUEngine
from snips_nlu.default_configs import CONFIG_EN
from snips_nlu.dataset import Dataset
with io.open("dataset/remind.yaml") as f:
dataset = Dataset.from_yaml_files("en", [f])
nlu_engine = SnipsNLUEngine(config=CONFIG_EN)
nlu_engine = nlu_engine.fit(dataset.json)
text = "Remind me tomorrow find a flight to london"
parsing = nlu_engine.parse(text)
print(json.dumps(parsing, indent= 4, sort_keys=True))
---
type: intent
name: Reminder
utterances:
- Remind me [snips/datetime](tomorrow) to [action](go to the gym)
- remind me to [action](take an umbrella) [snips/datetime](in 5 days)
- remind me to [action](walk the dog tonight)
- could you remind me to [action](call my mom)
- please remind me to [action](go to my appointment)
# Required to make this work
# - Remind me [snips/datetime](tomorrow) to [action](find a flight to london)
---
type: entity
name: action
automatically_extensible: yes
# searchFlight Intent
---
type: intent
name: searchFlight
slots:
- name: origin
entity: city
- name: destination
entity: city
- name: date
entity: snips/datetime
utterances:
- find me a flight from [origin](Paris) to [destination](New York)
- I need a flight leaving [date](this weekend) to [destination](Berlin)
- show me flights to go to [destination](new york) leaving [date](this evening)
# City Entity
---
type: entity
name: city
values:
- london
- [new york, big apple]
- [paris, city of lights]
{
"input": "Remind me tomorrow to find a flight to london",
"intent": {
"intentName": "searchFlight",
"probability": 0.6030061357370643
},
"slots": [
{
"entity": "city",
"range": {
"end": 45,
"start": 39
},
"rawValue": "london",
"slotName": "destination",
"value": {
"kind": "Custom",
"value": "london"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment