# Slot Relation Extraction

# What

# What is slot relation extraction?

Slot Relation Extraction is the process of training a model that uses semantic meaning to extract relationships between two slot labels.

# How

How to create a relationship

How to add an annotation

How to transfer utterances among datasets

How to query for slot relation extraction

# How to create relationships

  1. Users can add relationships through the competency edit dialog. There must be at least one slot to create a relationship.

add slot relationship

  1. Once a relationship exists, it appears on the competency sidebar below the competency's slots.

competency sidebar

# How to add annotations

  1. Clicking on a relationship takes the user to the slot relation data page. SVP and SRE utterances have a chip to indicate which dataset(s) they belong to. An utterance can belong to the SVP dataset, the SRE dataset, or both.

utterance chip

  1. Clicking the ... button for an SRE utterance gives users the option to Add Slot Annotations. There must be at least two slot labels on the utterance before adding relationship annotations.

ann annotations

  1. Clicking the Add Slot Annotations button shows a dialog that allows users to add annotations. The Relationship dropdown has a list of all relationships under a competency. The Source and Destination dropdowns have a list of all the labels for an utterance. The following restrictions apply for adding annotations:

    • A user cannot add duplicate source and destination labels. Duplicate means the exact same label including its location in the utterance. For example, if an utterance has two instances of the word large labeled, a user can add the first instance of large as Source and the second instance of large as Destination. However, a user cannot add the first instance of large as Source and the first instance of large also as Destination.
    • A user cannot add the same relationship/source/destination pair multiple times edit annotations
  2. Utterances in the SRE dataset that have annotations have a link icon next to the utterance. annotation link

# How to transfer utterances

Users can transfer utterances among CLF, SVP, and SRE datasets.

  1. To transfer CLF utterances, a user can go to the CLF page and select the utterances they want to transfer. If the competency has relationships, the user sees the options to transfer to SRE or both SVP and SRE datasets. If the competency only has slots, the user only has the option to transfer to SVP data.

transfer clf

  1. A user can transfer SVP utterances to either the CLF dataset or the SRE dataset. A user can also transfer SRE utterances to either the CLF dataset or the SVP dataset.

transfer svp

# How to query slot relation extraction

  1. After adding labels and annotations to utterances, a user can see that the slot relationship was picked up by inspecting the full query response. In the response, there is a slot_relations section that lists the relationship that was picked up on query.

query sre

# How to configure BLS for SRE

Once the relationships are created on an AI version, each query request will make a BLS call that includes slot_relations in the request. The slot_relations field contains the following sub-fields: relation name of the relation name as defined in the AI:

source["slot"] : the source slot name
source["index"] : index of token associated with source slot
source["value"] : value of the source slot
destination["slot"] : the destination slot name
destination["index"] : index of token associated with destination slot
destination["value"] : value of the destination slot

Let us illustrate with the use case of a funds transfer competency, where the customer wants to transfer some money from their ‘checking’ account ending in 4074 to their ‘trading’ account ending in 1362. With the following query to that effect, the AI will pick the slots as illustrated.

Query: Transfer $10,000 from my checking 4074 account to my trading 1362 account today

Slots Extracted as follows (color coded):
MONEY SOURCE_ACCOUNT ACCT_NUM DESTINATION_ACCOUNTACCT_NUM

Additionally, as the AI has been trained to recognize the relationship pairs, it will record the two relationships:

  • (source) SOURCE_ACCOUNT & (destination) ACCT_NUM in slot_relations[0] ; and
  • (source) DESTINATION_ACCOUNT & (destination) ACCT_NUM in slot_relations[1]
"slot_relations": [
    {
      "relation": "account_group",
      "source": {
        "slot": "_SOURCE_ACCOUNT_",
        "index": 0,
        "value": "checking"
      },
      "destination": {
        "slot": "_ACCT_NUM_",
        "index": 1,
        "value": "4074"
      }
    },
    {
      "relation": "account_group",
      "source": {
        "slot": "_DESTINATION_ACCOUNT_",
        "index": 2,
        "value": "trading"
      },
      "destination": {
        "slot": "_ACCT_NUM_",
        "index": 3,
        "value": "1362"
      }
    }
  ]

BLS is expected to extract the relevant details from slot_relations and perform necessary operations with the information. The following sample script does the following:

  • Stores the request payload in temp variable called response
  • Searches for the slot_relations field and if found extracts the source and destination account numbers, adding them as new slots in the response to the platform
    • The account category slot and values are present in value["source"]["slot"] and value["source"]["value"]
    • The account number slot and values are present in value["destination"]["value"] and value["destination"]["value"]
  • Returns the response
@app.route('/slot_relation_demo', methods = ['POST'])
def sre_demo_webhook():

    if request.json:
        #Store request payload
        response = json.loads(str(request.data, encoding = 'utf-8'))

        #Search for the 'slot_relations' field and process if found
        if response.get("slot_relations"):

            #Store the slot_relation value
            sr = request.json["slot_relations"]
            
            for value in sr:
                #Process the source account
                if value["source"]["slot"] == "_SOURCE_ACCOUNT_":
                    account_num = {
                            "type": "string",
                            "values": [
                            {
                                #source acc number
                                "value": value["destination"]["value"],
                                "status": "CONFIRMED"
                            }
                            ]
                        }
                    #create new slot for source acc number
                    response['slots']['_SOURCE_ACCOUNT_NUM_'] = account_num

                #Process the destination account
                if value["source"]["slot"] == "_DESTINATION_ACCOUNT_":
                    account_num = {
                            "type": "string",
                            "values": [
                            {   #destination acc number
                                "value": value["destination"]["value"],
                                "status": "CONFIRMED"
                            }
                            ]
                        }
                    #create new slot for destination acc number
                    response['slots']['_DESTINATION_ACCOUNT_NUM_'] = account_num

    return jsonify(response)