Create an Azure Language Understanding app

Provision Azure resources for Language Understanding

To use the Language Understanding service to develop a natural language understanding solution, you require two kinds of resource in your Azure subscription:

  • An Authoring resource (which must be a Language Understanding - Authoring resource) that you can use to train your language understanding model.
  • Prediction resource (which can be a Language Understanding - Prediction or Cognitive Services resource) to host your trained model and process requests from client applications.

Define intents and utterances

Utterances are the phrases that a user might enter when interacting with an application that uses your Language Understanding model. An intent represents a task or action the user wants to perform, or more simply the meaning of an utterance. You create a model by defining intents and associating them with one or more utterances.

For example, consider the following list of intents and associated utterances:

  • GetTime:
    • "What time is it?"
    • "What is the time?"
    • "Tell me the time"
  • GetWeather:
    • "What is the weather forecast?"
    • "Do I need an umbrella?"
    • "Will it snow?"
  • TurnOnDevice
    • "Turn the light on."
    • "Switch on the light."
    • "Turn on the fan"
  • None:
    • "Hello"
    • "Goodbye"

Define entities

Entities are used to add specific context to intents. For example, you might define a TurnOnDevice intent that can be applied to multiple devices, and use entities to define the different devices.

Consider the following utterances, intents, and entities:

DEFINE ENTITIES
UtteranceIntentEntities
What is the time?GetTime
What time is it in London?GetTimeLocation (London)
What's the weather forecast for Paris?GetWeatherLocation (Paris)
Will I need an umbrella tonight?GetWeatherTime (tonight)
What's the forecast for Seattle tomorrow?GetWeatherLocation (Seattle), Time (tomorrow)
Turn the light on.TurnOnDeviceDevice (light)
Switch on the fan.TurnOnDeviceDevice (fan)

Entity types

You can define entities in a number of ways:

  • Machine learned entities are the most flexible kind of entity, and should be used in most cases. You define a machine learned entity with a suitable name, and then associate words or phrases with it in training utterances. When you train your model, it learns to match the appropriate elements in the utterances with the entity.
  • List entities are useful when you need an entity with a specific set of possible values - for example, days of the week. You can include synonyms in a list entity definition, so you could define a DayOfWeek entity that includes the values "Sunday", "Monday", "Tuesday", and so on; each with synonyms like "Sun", "Mon", "Tue", and so on.
  • Regular Expression or RegEx entities are useful when an entity can be identified by matching a particular format of string. For example, a date in the format MM/DD/YYYY, or a flight number in the format AB-1234.
  • Pattern.any() entities are used with patterns, which are discussed in the next topic.

Use patterns to differentiate similar utterances

In some cases, a model might contain multiple intents for which utterances are likely to be similar. You can use patterns to disambiguate the intents while minimizing the number of sample utterances.

For example, consider the following utterances:

  • "Turn the kitchen light on."
  • "Is the kitchen light on?"
  • "Turn the kitchen light off."

These utterances are syntactically similar, with only a few differences in words or punctuation. However, they represent three different intents (which could be named TurnOnDeviceGetDeviceStatus, and TurnOffDevice). Additionally, the intents could apply to a wide range of entity values. In addition to "kitchen light", the intent could apply to "living room light", "bedside lamp", "fan", television", or any other device that the model might need to support.

You could associate utterances for every possible entity with all three intents. However, a more efficient way to train the model is to define patterns that include utterance templates, like this:

  • TurnOnDevice:
    • "Turn the {DeviceName} on."
    • "Switch the {DeviceName} on."
    • "Turn on the {DeviceName}."
  • GetDeviceStatus:
    • "Is the {DeviceName} on[?]"
  • TurnOffDevice:
    • "Turn the {DeviceName} off."
    • "Switch the {DeviceName} off."
    • "Turn off the {DeviceName}."

These utterances include a placeholder for a Pattern.any() entity named DeviceName. reducing the number of utterances required to train the model. Patterns can make use of optional elements, such as punctuation to provide additional cues that help identify the appropriate intent.

The patterns defined in the utterance templates, including the position of the Pattern.any() entity and any optional words or punctuation, help the model identify the intents and entity values from fewer samples:

表 1
UtteranceIntentEntity
Turn the kitchen light on.TurnOnDeviceDeviceName (kitchen light)
Is the bedroom lamp on?GetDeviceStatusDeviceName (bedroom lamp)
Switch the TV off.TurnOffDeviceDeviceName (TV)

Use pre-built models

You can create your own language models by defining all the intents and utterances it requires, but often you can use prebuilt model elements that encapsulate common intents and entities.

The Language Understanding service provides prebuilt model elements at three different levels of granularity:

  • Prebuilt Domains define complete language understanding models that include predefined intents, utterances, and entities. Prebuilt domains include CalendarEmailWeatherRestaurantReservationHomeAutomation, and others.
  • Prebuilt Intents include predefined intents and utterances, such as CreateCalendarEntrySendEmailTurnOnAddToDo, and others.
  • Prebuilt Entities define commonly used entities, such as AgeEmailPersonNameNumberGeographyDateTime, and others.

Using prebuilt model elements can significantly reduce the time it takes to develop a language understanding solution.

Train test publish and review a Language Understanding app

Completed100 XP

  • 3 minutes

Creating a language understanding model is an iterative process with the following activities:

The train, test, publish, review cycle

  1. Train a model to learn intents and entities from sample utterances.
  2. Test the model interactively, or by submitting a batch of utterances with known intent labels and comparing the predicted intents to the known label.
  3. Publish a trained model to a prediction resource and use it from client applications.
  4. Review the predictions made by the model based on user input and apply active learning to correct misidentified intents or entities and improve the model.

Exercise - Create a Language Understanding app

https://docs.microsoft.com/zh-cn/learn/modules/create-language-understanding-app/8-exercise

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值