Skip to content

Instantly share code, notes, and snippets.

@dipanjannag
Created December 4, 2018 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dipanjannag/7fe43fac046018ec6a1c84785acca1e9 to your computer and use it in GitHub Desktop.
Save dipanjannag/7fe43fac046018ec6a1c84785acca1e9 to your computer and use it in GitHub Desktop.
from __future__ import unicode_literals, print_function
import json
from pathlib import Path
from snips_nlu import SnipsNLUEngine, load_resources
from snips_nlu.default_configs import CONFIG_EN
SAMPLE_DATASET_PATH = Path(__file__).parent / "sample_dataset.json"
with SAMPLE_DATASET_PATH.open(encoding="utf8") as f:
sample_dataset = json.load(f)
load_resources("snips_nlu_en")
nlu_engine = SnipsNLUEngine(config=CONFIG_EN)
nlu_engine.fit(sample_dataset)
# nlu_engine = SnipsNLUEngine(config=CONFIG_EN)
# nlu_engine.from_path('./model')
# # nlu_engine.persist('./model')
text = "What will be the weather in San Francisco next week?"
parsing = nlu_engine.parse(text)
print(json.dumps(parsing, indent=2))
{
"intents": {
"sampleGetWeather": {
"utterances": [
{
"data": [
{
"text": "give me the weather forecast for "
},
{
"text": "los angeles",
"entity": "location",
"slot_name": "weatherLocation"
},
{
"text": " "
},
{
"text": "this weekend",
"entity": "snips/datetime",
"slot_name": "weatherDate"
}
]
},
{
"data": [
{
"text": "What kind of weather should I expect "
},
{
"text": "today",
"entity": "snips/datetime",
"slot_name": "weatherDate"
},
{
"text": " in "
},
{
"text": "rio de janeiro",
"entity": "location",
"slot_name": "weatherLocation"
},
{
"text": " ? "
}
]
},
{
"data": [
{
"text": "Will it be sunny in "
},
{
"text": "Tokyo",
"entity": "location",
"slot_name": "weatherLocation"
},
{
"text": " "
},
{
"text": "at the end of the day",
"entity": "snips/datetime",
"slot_name": "weatherDate"
},
{
"text": " ?"
}
]
},
{
"data": [
{
"text": "What will be the weather in "
},
{
"text": "London",
"entity": "location",
"slot_name": "weatherLocation"
},
{
"text": ", "
},
{
"text": "tomorrow morning",
"entity": "snips/datetime",
"slot_name": "weatherDate"
},
{
"text": "?"
}
]
},
{
"data": [
{
"text": "Tell me if it is going to rain "
},
{
"text": "this afternoon",
"entity": "snips/datetime",
"slot_name": "weatherDate"
},
{
"text": " in "
},
{
"text": "tel aviv",
"entity": "location",
"slot_name": "weatherLocation"
},
{
"text": ", please"
}
]
},
{
"data": [
{
"text": "What is the weather in "
},
{
"text": "Paris",
"entity": "location",
"slot_name": "weatherLocation"
},
{
"text": "?"
}
]
}
]
},
"sampleTurnOnLight": {
"utterances": [
{
"data": [
{
"text": "The "
},
{
"text": "bedroom",
"entity": "room",
"slot_name": "room"
},
{
"text": " is dark, please turn on the light !"
}
]
},
{
"data": [
{
"text": "Can you enlight the "
},
{
"text": "living room",
"entity": "room",
"slot_name": "room"
},
{
"text": " ?"
}
]
},
{
"data": [
{
"text": "I need some light in the "
},
{
"text": "basement",
"entity": "room",
"slot_name": "room"
},
{
"text": " please"
}
]
},
{
"data": [
{
"text": "Please put some lights in the "
},
{
"text": "bathroom",
"entity": "room",
"slot_name": "room"
}
]
},
{
"data": [
{
"text": "Turn on the lights in the "
},
{
"text": "kitchen",
"entity": "room",
"slot_name": "room"
}
]
}
]
}
},
"entities": {
"location": {
"data": [],
"use_synonyms": true,
"automatically_extensible": true,
"parser_threshold": 1.0
},
"snips/datetime": {},
"room": {
"data": [
{
"value": "basement",
"synonyms": [
"cellar"
]
},
{
"value": "living room",
"synonyms": [
"lounge",
"family room"
]
}
],
"use_synonyms": true,
"automatically_extensible": false,
"parser_threshold": 1.0
}
},
"language": "en"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment