How to make a Snips skill – Part 2 – Intents

25. December 2018 20:23
4 min reading
This post thumbnail

Today I will try to make a new skill for the Snips Platform. The skill should be able to answer questions about the timetable of trains, buses and trams within the Swiss Public Transport system. This blog post is written while I’m about to develop the skill. What you are reading right now is part 2, looking at how to setup the intents in Snips and where to get the data from to train the slots.

Table of Content

  1. Overview
  2. Intents – how to get data for slots and intents
  3. All about API – get the needed public transport data
  4. Data to spoken text – what about Multilanguage
  5. Develop the actions – tell Snips what to do
  6. Put everything together – publish and debug the App and Actions

Intents

For the intents we have to think about the different possibilities a user may use to ask the question. In Part one we decided to use 3 intents as a starting point:

IntentSlot-1Slot-2Slot-3
train_schedule_totransport_typeto_station-
station_timetabletransport_type--
train_schedule_from_totransport_typefrom_stationto_station

Before we can generate intents in Snips we need to think about the slots we want to fill. Snips provides a set of built-in Slot Types (snips/datetime, snips/duration, …). However we are dealing her with a special subset of words we want to use for the Slots. Therefore we look into the generation of Custom Slot Types a bit more detailed.

Slots

swiss_publictransport_stations

To be able to ask Snips about train connections we need to provide the origin and destination stations. I decided to a create a Custom Slot Type. There are more than 20’000 railway, bus and tram stations within the Swiss Public Transport System. Lucky as we are, this data is provided in the so called Didok Record.

We download the csv-file and edit it in Excel:

  • we filter the data to just show Swiss stations (row ‘land’ = Switzerland)
  • further we just want the real stations (row ‘Haltestelle’ = *)
  • What we are looking for is the first column ‘Name’.

Let’s take the first column and copy it into the text editor of our choice (Visual Studio Code in my case). After investigating the names, I found some names with brackets and also commas. The Snips “Slot Type Importer” treats commas as a separator for synonyms. So we do some more data mingling:

  • remove all ‘)’ and ‘(‘ from the name
  • replace all ‘,’ with a dash (no idea how snips will handle this)
  • leave all ‘/’ in place
  • replace all ‘str.’ with ‘strasse’
  • replace all ‘Kath.’ with ‘Katholische’

This leaves us with 24756 station names. Let’s try if we can import this amount of data into Snips.

Import Slot Type Variables

publictransport_type

We also want to ask Snips for a specific mode of Transportation. Therefore we create another Slot Type for the possible transports. We have 4 different transports:

  • Railway
  • Bus
  • Tram
  • Ship

In the picture you see the slots I made for the German assistant with according synonyms:

Slot Type Transport Type

Intents – continued

Now we have the Slot Types in place we can continue to generate training samples for our first intent.

train_schedule_to

Let’s look at the possible questions one might ask:

  • when is the next transportation_type to destination
  • at what time is the next transportation_type connection to destination
  • can you tell me the next available connection to destination

and so on…

Thankfully we have a little helper to automatically generate some variations in the questions we want to ask. Greg(oziee) made a nice tool which is helpful in debugging stuff around Snips Snips WebAdmin. There is also a video with an overview of all the functions.

Greg has built in a function called Generator which lets you enter some variables and spits out a list of questions to import into the training example section of the Snips Intent.

I configured the following Slots:

to_station  -> with 2 samples (Zürich, Bern)
transport_type -> wit 4 samples (Zug, Bus, Tram, Schiff)

and Phrases:

zeit=wann, um wieviel uhr, zu welcher Zeit
was=fährt, rollt, geht
derdiedas=der, die, das

and Sentences:

#zeit #was #derdiedas nächste $transport_type nach $to_station
#zeit #was #derdiedas nächste $transport_type auf $to_station zu
#zeit #was #derdiedas nächste $transport_type Richtung $to_station

Slots Dialog Box

This generates 162 items we can use and import into the Snips intent:

Train Schedule TO Intent samples

station_timetable

The next intent is easier to do. Since we will set our ‘home’ station in our skill configuration, we only have one slot: the transport type. Questions might be as follows:

  • when is the next transportation_type?
  • what time the next transportation_type is leaving?
  • tell me the next transportation_type connection?

Again we will use Gregs Generator from Snips WebAdmin with the following input parameters

Slots:

transport_type -> with 4 samples (Zug, Bus, Tram, Schiff)

Phrases:

zeit=wann, um wieviel uhr, zu welcher Zeit
was=fährt, rollt, geht
derdiedas=der, die, das

Sentences:

#zeit #was #derdiedas nächste $transport_type
#zeit ist die nächste $transport_type Verbindung
was ist die nächste $transport_type Verbindung

With these input parameters we get 62 training items we can feed to Snips.

Station Timetable Intent samples

train_schedule_from_to

This leaves us with the last intent we want to provide. The question for a connection from a specific origin to a destinations. Questions might be:

  • when is the next transportation_type from from_station to to_station?
  • what time does the next transportation_type from from_station leave towards to_station?
  • tell me the next transportation_type connection from from_station to to_station!

A third time we use Snips WebAdmin Generator to generate some useful trainings samples for the questions:

Slots:

transport_type -> wit 4 samples (Zug, Bus, Tram, Schiff)
to_station -> with 2 samples (Zürich, Bern)
from_station -> with 2 samples (Zürich, Bern)

Phrases:

zeit=wann, um wieviel uhr, zu welcher Zeit
was=fährt, rollt, geht
derdiedas=der, die, das
von=von, aus
nach=nach, in Richtung

Sentences:

#zeit #was #derdiedas nächste $transport_type #von $from_station #nach $to_station
#zeit #was #derdiedas nächste $transport_type #nach $to_station #von $from_station

These couple of lines will leave us with 432 training sentences we can feed into the Snips Console. Train Schedule FROM-TO Intent samples

This leaves us with a fully trained set of Intents we can use in our actions. Trained set if intends

Talking about actions, this will be in the next two parts of this series. I have to wrap up here and start preparing Christmas Dinner with my lovely – how do you call them in Home Assistant terms – SO (Significant other).

Blog Gallery Picture
Blog Gallery Picture
Blog Gallery Picture
Blog Gallery Picture
Blog Gallery Picture