Entities for the Yandex.Dialogues platform

An online hackathon to develop Alice's skills took place last Saturday. It is a pity that no one wrote about the results here, it is curious to read the stories of the winners. But since there were no volunteers, I will share my story.



I am making a voice interface for managing a brokerage account, I already wrote about it on Habré - Alice, buy Yandex . At some point, I needed to extract the price in different currencies from the request. I'm sure I'm not the first one who faced such a task, so I tried to find ready-made intents or named entities on GitHub, but I couldn't find anything. There was a hackathon on the nose, many developers in one place, I thought, if everyone shares their best practices, then there will be a whole library of entities. This is how the idea for the entity library repository was born.



Custom entities in Dialogs



When I say to the smart column “buy one Yandex share,” the speech goes through the inner magic of the Yandex.Dialogi platform, then goes to the web hook that I specified as the skill handler. This is what comes into the handler:



  "request": {
    "command": "   ",
    "original_utterance": "   ",
    "nlu": {
      "tokens": [
        "",
        "1",
        "",
        ""
      ],
      ...
      "intents": {
        "market.order": {
          "slots": {
            "amount": {
              "type": "YANDEX.NUMBER",
              "tokens": {
                "start": 1,
                "end": 2
              },
              "value": 1
            },
            "unit": {
              "type": "OperationUnit",
              "tokens": {
                "start": 2,
                "end": 3
              },
              "value": "share"
            },
            "figi": {
              "type": "EFigi",
              "tokens": {
                "start": 3,
                "end": 4
              },
              "value": "BBG006L8G4H1"
            },
            "operation": {
              "type": "OperationType",
              "tokens": {
                "start": 0,
                "end": 1
              },
              "value": "buy"
            }
          }
        }
      }
    },
    ...
  },


Pay attention to the slot figithat contains the Yandex stock identifier, the so-called FIGI (Financial Instrument Global Identifier), which is required to interact with the API of the Tinkoff Investments trading platform. The EFigi data type is a custom entity that I described in the Entities section when creating a skill in the Yandex.Dialogi platform. Here's a snippet of the description:



entity EFigi:
    values:
        BBG005DXJS36:
            %exact
            TCS
            %lemma
            ()?
            ()?
            ()?
               ()?
        BBG006L8G4H1:
            %exact
            YNDX
            %lemma
            
            
        BBG004730JJ5:
            %exact
            MOEX
            %lemma
             
            
        BBG002B2J5X0:
            %exact
            KRKNP
            %lemma
            [   ]
            [    ]
...


Thanks to the entity mechanism, in the handler code, I do not need to do additional manipulations on the input data to get FIGI. The Dialogue Platform converts the name of the security to FIGI for me.



I am using EFigi as a nonterminal grammar and slot type in intents. Intents are regular expressions on steroids in Dialogues. Intents help Dialogues understand what data needs to be retrieved from the user request and passed to the handler. Here is an example of an intent for the command to buy / sell securities on the exchange at a market price:



slots:
    operation:
        source: $Operation
        type: OperationType
    figi:
        source: $Stock
        type: Efigi
    amount:
        source: $Amount
        type: YANDEX.NUMBER
    unit:
        source: $Unit
        type: OperationUnit
root:
    $Operation [$Amount $Unit $Stock]
$Operation:
    $OperationType
$Amount:
    $YANDEX.NUMBER
$Unit:
    $OperationUnit
$Stock:
    $EFigi


This is similar to regular expressions.



Entity Library for Dialogues



During the hackathon to develop skills for Alice, I created the alice-entities-library repository , pushed the EFigi entity there and went to GitHub to look for repositories that have a description of custom entities. I expected to find hundreds of repositories, contact the developers and offer to send pull requests to the entity library.



I searched for repositories by tags: yandex-dialogs, alice-skills, yandex-alice and alice-sdk. It turned out that very few people use tags on GitHub, I was able to find only one repository containing a file describing the ELang entity. By coincidence, the author of the repository turned out to be David, one of the organizers of the hackathon. I suggested to David to add the ELang entity to the library and received a pull request from him a few minutes later.



Other members of the online hackathon ignored my chat messages with a proposal to replenish the entity library. Perhaps, in the midst of the struggle, there was no time for this. To be honest, I got a little frustrated, but at the end I added a link to the repository at sameoldmadness / awesome-alice .



Instead of a conclusion



Dear Alice Skill Developers, please upload the source code to GitHub whenever possible so others can learn.



Please add the yandex-dialogs, alice-skills and yandex-alice tags to the repos so others can find your skills on GitHub.



Create a directory in your repository entitiesand put the entity description files that you wrote for the skill there so that others can reuse your work.



Before describing a new entity, take a look at the entity library , it may already have what you need there. And if not, then please add your entities to the library.



All Articles