Skip to content

Commit d1d76eb

Browse files
authored
Merge pull request #107129 from thediris/master
[Cog Svcs] Update Text Analytics Python Quickstarts with preview.3
2 parents b818464 + fe969b8 commit d1d76eb

File tree

1 file changed

+44
-46
lines changed
  • articles/cognitive-services/text-analytics/includes/quickstarts

1 file changed

+44
-46
lines changed

articles/cognitive-services/text-analytics/includes/quickstarts/python-sdk.md

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,18 @@ def sentiment_analysis_example(client):
128128
document = ["I had the best day of my life. I wish you were there with me."]
129129
response = client.analyze_sentiment(inputs=document)[0]
130130
print("Document Sentiment: {}".format(response.sentiment))
131-
print("Overall scores: positive={0:.3f}; neutral={1:.3f}; negative={2:.3f} \n".format(
132-
response.sentiment_scores.positive,
133-
response.sentiment_scores.neutral,
134-
response.sentiment_scores.negative,
131+
print("Overall scores: positive={0:.2f}; neutral={1:.2f}; negative={2:.2f} \n".format(
132+
response.confidence_scores.positive,
133+
response.confidence_scores.neutral,
134+
response.confidence_scores.negative,
135135
))
136136
for idx, sentence in enumerate(response.sentences):
137-
print("[Offset: {}, Length: {}]".format(sentence.offset, sentence.length))
137+
print("[Length: {}]".format(sentence.grapheme_length))
138138
print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
139-
print("Sentence score:\nPositive={0:.3f}\nNeutral={1:.3f}\nNegative={2:.3f}\n".format(
140-
sentence.sentiment_scores.positive,
141-
sentence.sentiment_scores.neutral,
142-
sentence.sentiment_scores.negative,
139+
print("Sentence score:\nPositive={0:.2f}\nNeutral={1:.2f}\nNegative={2:.2f}\n".format(
140+
sentence.confidence_scores.positive,
141+
sentence.confidence_scores.neutral,
142+
sentence.confidence_scores.negative,
143143
))
144144

145145

@@ -150,21 +150,21 @@ sentiment_analysis_example(client)
150150

151151
```console
152152
Document Sentiment: positive
153-
Overall scores: positive=1.000; neutral=0.000; negative=0.000
153+
Overall scores: positive=1.00; neutral=0.00; negative=0.00
154154

155-
[Offset: 0, Length: 30]
155+
[Length: 30]
156156
Sentence 1 sentiment: positive
157157
Sentence score:
158-
Positive=1.000
159-
Neutral=0.000
160-
Negative=0.000
158+
Positive=1.00
159+
Neutral=0.00
160+
Negative=0.00
161161

162-
[Offset: 31, Length: 30]
162+
[Length: 30]
163163
Sentence 2 sentiment: neutral
164164
Sentence score:
165-
Positive=0.210
166-
Neutral=0.770
167-
Negative=0.020
165+
Positive=0.21
166+
Neutral=0.77
167+
Negative=0.02
168168
```
169169

170170
#### [Version 2.1](#tab/version-2)
@@ -249,9 +249,8 @@ def entity_recognition_example(client):
249249

250250
print("Named Entities:\n")
251251
for entity in result.entities:
252-
print("\tText: \t", entity.text, "\tCategory: \t", entity.category, "\tSubCategory: \t", entity.subcategory,
253-
"\n\tOffset: \t", entity.offset, "\tLength: \t", entity.offset,
254-
"\tConfidence Score: \t", round(entity.score, 3), "\n")
252+
print("\tText: \t", entity.text, "\tCategory: \t", entity.category, "\tSubCategory: \t", entity.subcategory,
253+
"\n\tLength: \t", entity.grapheme_length, "\tConfidence Score: \t", round(entity.score, 2), "\n")
255254

256255
except Exception as err:
257256
print("Encountered exception. {}".format(err))
@@ -263,11 +262,11 @@ entity_recognition_example(client)
263262
```console
264263
Named Entities:
265264

266-
Text: Seattle Category: Location SubCategory: GPE
267-
Offset: 26 Length: 26 Confidence Score: 0.92
265+
Text: Seattle Category: Location SubCategory: GPE
266+
Length: 7 Confidence Score: 0.92
268267

269-
Text: last week Category: DateTime SubCategory: DateRange
270-
Offset: 34 Length: 34 Confidence Score: 0.8
268+
Text: last week Category: DateTime SubCategory: DateRange
269+
Length: 9 Confidence Score: 0.8
271270
```
272271

273272
## Using NER to detect personal information
@@ -285,17 +284,17 @@ def entity_pii_example(client):
285284
print("Personally Identifiable Information Entities: ")
286285
for entity in result.entities:
287286
print("\tText: ",entity.text,"\tCategory: ", entity.category,"\tSubCategory: ", entity.subcategory)
288-
print("\t\tOffset: ", entity.offset, "\tLength: ", entity.length, "\tScore: {0:.3f}".format(entity.score), "\n")
287+
print("\t\tLength: ", entity.grapheme_length, "\tScore: {0:.2f}".format(entity.score), "\n")
289288

290289
entity_pii_example(client)
291290
```
292291

293292
### Output
294293

295294
```console
296-
Personally Identifiable Information Entities:
297-
Text: 123-12-1234 Category: U.S. Social Security Number (SSN) SubCategory: None
298-
Offset: 33 Length: 11 Score: 0.850
295+
Personally Identifiable Information Entities:
296+
Text: 123-12-1234 Category: U.S. Social Security Number (SSN) SubCategory: None
297+
Length: 11 Score: 0.85
299298
```
300299

301300

@@ -316,13 +315,12 @@ def entity_linking_example(client):
316315

317316
print("Linked Entities:\n")
318317
for entity in result.entities:
319-
print("\tName: ", entity.name, "\tId: ", entity.id, "\tUrl: ", entity.url,
318+
print("\tName: ", entity.name, "\tId: ", entity.data_source_entity_id, "\tUrl: ", entity.url,
320319
"\n\tData Source: ", entity.data_source)
321320
print("\tMatches:")
322321
for match in entity.matches:
323322
print("\t\tText:", match.text)
324-
print("\t\tScore: {0:.3f}".format(match.score), "\tOffset: ", match.offset,
325-
"\tLength: {}\n".format(match.length))
323+
print("\t\tScore: {0:.2f}".format(match.score), "\tLength: {}\n".format(match.grapheme_length))
326324

327325
except Exception as err:
328326
print("Encountered exception. {}".format(err))
@@ -334,47 +332,47 @@ entity_linking_example(client)
334332
```console
335333
Linked Entities:
336334

337-
Name: Altair 8800 Id: Altair 8800 Url: https://en.wikipedia.org/wiki/Altair_8800
335+
Name: Altair 8800 Id: Altair 8800 Url: https://en.wikipedia.org/wiki/Altair_8800
338336
Data Source: Wikipedia
339337
Matches:
340338
Text: Altair 8800
341-
Score: 0.777 Offset: 125 Length: 11
339+
Score: 0.78 Length: 11
342340

343-
Name: Bill Gates Id: Bill Gates Url: https://en.wikipedia.org/wiki/Bill_Gates
341+
Name: Bill Gates Id: Bill Gates Url: https://en.wikipedia.org/wiki/Bill_Gates
344342
Data Source: Wikipedia
345343
Matches:
346344
Text: Bill Gates
347-
Score: 0.555 Offset: 25 Length: 10
345+
Score: 0.55 Length: 10
348346

349347
Text: Gates
350-
Score: 0.555 Offset: 179 Length: 5
348+
Score: 0.55 Length: 5
351349

352-
Name: Paul Allen Id: Paul Allen Url: https://en.wikipedia.org/wiki/Paul_Allen
350+
Name: Paul Allen Id: Paul Allen Url: https://en.wikipedia.org/wiki/Paul_Allen
353351
Data Source: Wikipedia
354352
Matches:
355353
Text: Paul Allen
356-
Score: 0.533 Offset: 40 Length: 10
354+
Score: 0.53 Length: 10
357355

358-
Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
356+
Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
359357
Data Source: Wikipedia
360358
Matches:
361359
Text: Microsoft
362-
Score: 0.469 Offset: 0 Length: 9
360+
Score: 0.47 Length: 9
363361

364362
Text: Microsoft
365-
Score: 0.469 Offset: 168 Length: 9
363+
Score: 0.47 Length: 9
366364

367-
Name: April 4 Id: April 4 Url: https://en.wikipedia.org/wiki/April_4
365+
Name: April 4 Id: April 4 Url: https://en.wikipedia.org/wiki/April_4
368366
Data Source: Wikipedia
369367
Matches:
370368
Text: April 4
371-
Score: 0.248 Offset: 54 Length: 7
369+
Score: 0.25 Length: 7
372370

373-
Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
371+
Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
374372
Data Source: Wikipedia
375373
Matches:
376374
Text: BASIC
377-
Score: 0.281 Offset: 98 Length: 5
375+
Score: 0.28 Length: 5
378376

379377
```
380378

0 commit comments

Comments
 (0)