Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
PaulaMcC
Frequent Visitor

Error in Azure Sentiment Analysis

I'm currently using Azure Cognitive Services for the first. I've managed to get the Text Analysis to work but am struggling to get the sentiment analysis to work as it's just returning errors for all rows. 

I'm following the instructions from the MS Tutorial - https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/tutorials/tutorial-power-bi... plus some additional research & watching video's but I can't work out where I've gone wrong!

 

This is the code I'm using:

let
apikey = "MY.API.KEY",
endpoint = "https://MYSUBDOMAIN.cognitiveservices.azure.com" & "/text/analytics/v3.0/sentiment",
jsontext = Text.FromBinary(Json.FromValue(Text.Start(Text.Trim(text), 5000))),
jsonbody = "{ documents: [ { language: ""en"", id: ""0"", text: " & jsontext & " } ] }",
bytesbody = Text.ToBinary(jsonbody),
headers = [#"Ocp-Apim-Subscription-Key" = apikey],
bytesresp = Web.Contents(endpoint, [Headers=headers, Content=bytesbody]),
jsonresp = Json.Document(bytesresp),
sentiment = jsonresp[documents]{0}[detectedLanguage][confidenceScore] in sentiment

 

I then go to my query with the data to analyse, Invoke Custom Function - choose the above function but the returns the results as an error:

PaulaMcC_1-1616991206393.png

 

Really hoping someone's got some advice because this is breaking my brain!!

 

 

 

 

1 ACCEPTED SOLUTION
PaulaMcC
Frequent Visitor

@amitchandak just wanted to give you an update, I've finally managed to get the sentiment analysis to work!!

I created parameters for the code so it ended up looking like this:

 

(text) => let
apikey = APIKey,
endpoint = Endpoint& "/text/analytics/v3.0/"&Service,
jsontext = Text.FromBinary(Json.FromValue(Text.Start(Text.Trim(text), 5000))),
jsonbody = "{ documents: [ { language: ""en"", id: ""0"", text: " & jsontext & " } ] }",
bytesbody = Text.ToBinary(jsonbody),
headers = [#"Ocp-Apim-Subscription-Key" = apikey],
bytesresp = Web.Contents(endpoint, [Headers=headers, Content=bytesbody]),
jsonresp = Json.Document(bytesresp)
in jsonresp

 

I also had a parameter for language replacing the ""en"" but this didn't work so reverted but to the orginal

I'm so happy it worked in the end!!

View solution in original post

6 REPLIES 6
PaulaMcC
Frequent Visitor

@amitchandak just wanted to give you an update, I've finally managed to get the sentiment analysis to work!!

I created parameters for the code so it ended up looking like this:

 

(text) => let
apikey = APIKey,
endpoint = Endpoint& "/text/analytics/v3.0/"&Service,
jsontext = Text.FromBinary(Json.FromValue(Text.Start(Text.Trim(text), 5000))),
jsonbody = "{ documents: [ { language: ""en"", id: ""0"", text: " & jsontext & " } ] }",
bytesbody = Text.ToBinary(jsonbody),
headers = [#"Ocp-Apim-Subscription-Key" = apikey],
bytesresp = Web.Contents(endpoint, [Headers=headers, Content=bytesbody]),
jsonresp = Json.Document(bytesresp)
in jsonresp

 

I also had a parameter for language replacing the ""en"" but this didn't work so reverted but to the orginal

I'm so happy it worked in the end!!

PaulaMcC
Frequent Visitor

@amitchandak So I've tried stripping back the query so there are less steps involved but it's still returning an error.

PaulaMcC
Frequent Visitor

@amitchandak this is the erro:

An error occurred in the ‘’ query. Expression.Error: The field 'detectedLanguage' of the record wasn't found.
Details:
id=0
sentiment=positive
confidenceScores=
positive=1
neutral=0
negative=0
sentences=[List]
warnings=[List]

@PaulaMcC , Is showing an error on detectedLanguage, Have you removed any columns ??

What are the steps you have performed

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak I have removed columns prior to Invoked Custom Function. I've also got the text analysis custom function in the same query, I'll try it in a fresh query no & see if it makes a difference

amitchandak
Super User
Super User

@PaulaMcC , Click on the error, You will get some text. Share that here. See if that can give you some hint where is the error.

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.