Επεξεργασία

Κοινή χρήση μέσω


How to use Named Entity Recognition (NER)

The NER feature can evaluate unstructured text, and extract named entities from text in several predefined categories, for example: person, location, event, product, and organization.

Development options

To use named entity recognition, you submit raw unstructured text for analysis and handle the API output in your application. Analysis is performed as-is, with no additional customization to the model used on your data. There are two ways to use named entity recognition:

Development option Description
Language studio Language Studio is a web-based platform that lets you try entity linking with text examples without an Azure account, and your own data when you sign up. For more information, see the Language Studio website or language studio quickstart.
REST API or Client library (Azure SDK) Integrate named entity recognition into your applications using the REST API, or the client library available in a variety of languages. For more information, see the named entity recognition quickstart.

Determine how to process the data (optional)

Input languages

When you submit documents to be processed, you can specify which of the supported languages they're written in. if you don't specify a language, key phrase extraction defaults to English. The API may return offsets in the response to support different multilingual and emoji encodings.

Submitting data

Analysis is performed upon receipt of the request. Using the NER feature synchronously is stateless. No data is stored in your account, and results are returned immediately in the response.

When using this feature asynchronously, the API results are available for 24 hours from the time the request was ingested, and is indicated in the response. After this time period, the results are purged and are no longer available for retrieval.

The API attempts to detect the defined entity categories for a given document language.

Getting NER results

When you get results from NER, you can stream the results to an application or save the output to a file on the local system. The API response will include recognized entities, including their categories and subcategories, and confidence scores.

Select which entities to be returned (Preview API only)

Starting with API version 2023-04-15-preview, the API attempts to detect the defined entity types and tags for a given document language. The entity types and tags replace the categories and subcategories structure the older models use to define entities for more flexibility. You can also specify which entities are detected and returned, use the optional includeList and excludeList parameters with the appropriate entity types. The following example would detect only Location. You can specify one or more entity types to be returned. Given the types and tags hierarchy introduced for this version, you have the flexibility to filter on different granularity levels as so:

Input:

Note

In this example, it returns only the Location entity type.

{
    "kind": "EntityRecognition",
    "parameters": 
    {
        "includeList" :
        [
            "Location"
        ]
    },
    "analysisInput":
    {
        "documents":
        [
            {
                "id":"1",
                "language": "en",
                "text": "We went to Contoso foodplace located at downtown Seattle last week for a dinner party, and we adore the spot! They provide marvelous food and they have a great menu. The chief cook happens to be the owner (I think his name is John Doe) and he is super nice, coming out of the kitchen and greeted us all. We enjoyed very much dining in the place! The pasta I ordered was tender and juicy, and the place was impeccably clean. You can even pre-order from their online menu at www.contosofoodplace.com, call 112-555-0176 or send email to order@contosofoodplace.com! The only complaint I have is the food didn't come fast enough. Overall I highly recommend it!"
            }
        ]
    }
}

The above examples would return entities falling under the Location entity type such as the GPE, Structural, and Geological tagged entities as outlined by entity types and tags. We could also further filter the returned entities by filtering using one of the entity tags for the Location entity type such as filtering over GPE tag only as outlined:


    "parameters": 
    {
        "includeList" :
        [
            "GPE"
        ]
    }
    

This method returns all Location entities only falling under the GPE tag and ignore any other entity falling under the Location type that is tagged with any other entity tag such as Structural or Geological tagged Location entities. We could also further drill down on our results by using the excludeList parameter. GPE tagged entities could be tagged with the following tags: City, State, CountryRegion, Continent. We could, for example, exclude Continent and CountryRegion tags for our example:


    "parameters": 
    {
        "includeList" :
        [
            "GPE"
        ],
        "excludeList": :
        [
            "Continent",
            "CountryRegion"
        ]
    }
    

Using these parameters we can successfully filter on only Location entity types, since the GPE entity tag included in the includeList parameter, falls under the Location type. We then filter on only Geopolitical entities and exclude any entities tagged with Continent or CountryRegion tags.

Specify the NER model

By default, this feature uses the latest available AI model on your text. You can also configure your API requests to use a specific model version.

Service and data limits

For information on the size and number of requests you can send per minute and second, see the service limits article.

Next steps

Named Entity Recognition overview