question

VedantModi-4587 avatar image
0 Votes"
VedantModi-4587 asked romungi-MSFT commented

How to connect to Text Analysis (Named Entity Recognition) with Python

I need to run Named Entity Recognition of Text Analysis using Python.

Here's my code which I've sourced from here.


 from azure.ai.textanalytics import TextAnalyticsClient
 from azure.core.credentials import AzureKeyCredential
    
 key = "snip"
 endpoint = "https://centralindia.cognitiveservices.azure.com/text/analytics/v3.1/entities/recognition/general"
    
 def authenticate_client():
     ta_credential = AzureKeyCredential(key)
     text_analytics_client = TextAnalyticsClient(
             endpoint=endpoint,
             credential=ta_credential)
     return text_analytics_client
 client = authenticate_client()
    
 def entity_recognition_example(client):
     try:
         documents = ["I had a wonderful trip to Seattle last week."]
         result = client.recognize_entities(documents = documents)[0]
    
         print("Named Entities:\n")
         for entity in result.entities:
             print("\tText: \t", entity.text, "\tCategory: \t", entity.category, "\tSubCategory: \t", entity.subcategory,
                     "\n\tConfidence Score: \t", round(entity.confidence_score, 2), "\tLength: \t", entity.length, "\tOffset: \t", entity.offset, "\n")
    
     except Exception as err:
         print("Encountered exception. {}".format(err))
 entity_recognition_example(client)

This gives me the error: Encountered exception. <urllib3.connection.HTTPSConnection object at 0x000001D0BD6A26A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

I'm not sure how to write the endpoint, this page says I have to follow this format: https://<your-custom-subdomain>.cognitiveservices.azure.com/text/analytics/v3.1/entities/recognition/general. Not sure what to put in place of "<your-custom-subdomain>"


azure-text-analytics
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@VedantModi-4587 Did you get a chance to check if the below suggestion worked?

0 Votes 0 ·
romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered

@VedantModi-4587 The custom subdomain is basically the name of your resource you created from Azure portal. You can find your key and endpoint in the resource's key and endpoint page, under resource management. Since you have already copied the key you can directly copy the endpoint and add the required API name to the call or you can just replace your resource name in the above code and try again.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

liroyben avatar image
0 Votes"
liroyben answered liroyben edited

Hello,

Look this code about the certification AI-900 https://github.com/MicrosoftLearning/mslearn-ai900/blob/main/07%20-%20Text%20Analytics.ipynb
you can use it with azure marchine learning

Have a great day !
Please don't forget to Accept as answer and upvote :)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.