@@ -128,18 +128,18 @@ def sentiment_analysis_example(client):
128
128
document = [" I had the best day of my life. I wish you were there with me." ]
129
129
response = client.analyze_sentiment(inputs = document)[0 ]
130
130
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,
135
135
))
136
136
for idx, sentence in enumerate (response.sentences):
137
- print (" [Offset: {} , Length: {} ]" .format(sentence.offset , sentence.length ))
137
+ print (" [Offset: {} , Length: {} ]" .format(sentence.grapheme_offset , sentence.grapheme_length ))
138
138
print (" Sentence {} sentiment: {} " .format(idx+ 1 , sentence.sentiment))
139
- print (" Sentence score:\n Positive={0:.3f } \n Neutral={1:.3f } \n Negative={2:.3f } \n " .format(
140
- sentence.sentiment_scores .positive,
141
- sentence.sentiment_scores .neutral,
142
- sentence.sentiment_scores .negative,
139
+ print (" Sentence score:\n Positive={0:.2f } \n Neutral={1:.2f } \n Negative={2:.2f } \n " .format(
140
+ sentence.confidence_scores .positive,
141
+ sentence.confidence_scores .neutral,
142
+ sentence.confidence_scores .negative,
143
143
))
144
144
145
145
@@ -150,21 +150,21 @@ sentiment_analysis_example(client)
150
150
151
151
``` console
152
152
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
154
154
155
155
[Offset: 0, Length: 30]
156
156
Sentence 1 sentiment: positive
157
157
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
161
161
162
162
[Offset: 31, Length: 30]
163
163
Sentence 2 sentiment: neutral
164
164
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
168
168
```
169
169
170
170
#### [ Version 2.1] ( #tab/version-2 )
@@ -250,8 +250,8 @@ def entity_recognition_example(client):
250
250
print (" Named Entities:\n " )
251
251
for entity in result.entities:
252
252
print (" \t Text: \t " , entity.text, " \t Category: \t " , entity.category, " \t SubCategory: \t " , entity.subcategory,
253
- " \n\t Offset: \t " , entity.offset , " \t Length: \t " , entity.offset ,
254
- " \t Confidence Score: \t " , round (entity.score, 3 ), " \n " )
253
+ " \n\t Offset: \t " , entity.grapheme_offset , " \t Length: \t " , entity.grapheme_offset ,
254
+ " \t Confidence Score: \t " , round (entity.score, 2 ), " \n " )
255
255
256
256
except Exception as err:
257
257
print (" Encountered exception. {} " .format(err))
@@ -285,7 +285,7 @@ def entity_pii_example(client):
285
285
print (" Personally Identifiable Information Entities: " )
286
286
for entity in result.entities:
287
287
print (" \t Text: " ,entity.text," \t Category: " , entity.category," \t SubCategory: " , entity.subcategory)
288
- print (" \t\t Offset: " , entity.offset , " \t Length: " , entity.length , " \t Score: {0:.3f } " .format(entity.score), " \n " )
288
+ print (" \t\t Offset: " , entity.grapheme_offset , " \t Length: " , entity.grapheme_length , " \t Score: {0:.2f } " .format(entity.score), " \n " )
289
289
290
290
entity_pii_example(client)
291
291
```
@@ -295,7 +295,7 @@ entity_pii_example(client)
295
295
``` console
296
296
Personally Identifiable Information Entities:
297
297
Text: 123-12-1234 Category: U.S. Social Security Number (SSN) SubCategory: None
298
- Offset: 33 Length: 11 Score: 0.850
298
+ Offset: 33 Length: 11 Score: 0.85
299
299
```
300
300
301
301
@@ -316,13 +316,13 @@ def entity_linking_example(client):
316
316
317
317
print (" Linked Entities:\n " )
318
318
for entity in result.entities:
319
- print (" \t Name: " , entity.name, " \t Id: " , entity.id , " \t Url: " , entity.url,
319
+ print (" \t Name: " , entity.name, " \t Id: " , entity.data_source_entity_id , " \t Url: " , entity.url,
320
320
" \n\t Data Source: " , entity.data_source)
321
321
print (" \t Matches:" )
322
322
for match in entity.matches:
323
323
print (" \t\t Text:" , match.text)
324
- print (" \t\t Score: {0:.3f } " .format(match.score), " \t Offset: " , match.offset ,
325
- " \t Length: {} \n " .format(match.length ))
324
+ print (" \t\t Score: {0:.2f } " .format(match.score), " \t Offset: " , match.grapheme_offset ,
325
+ " \t Length: {} \n " .format(match.grapheme_length ))
326
326
327
327
except Exception as err:
328
328
print (" Encountered exception. {} " .format(err))
@@ -338,43 +338,43 @@ Linked Entities:
338
338
Data Source: Wikipedia
339
339
Matches:
340
340
Text: Altair 8800
341
- Score: 0.777 Offset: 125 Length: 11
341
+ Score: 0.78 Offset: 125 Length: 11
342
342
343
343
Name: Bill Gates Id: Bill Gates Url: https://en.wikipedia.org/wiki/Bill_Gates
344
344
Data Source: Wikipedia
345
345
Matches:
346
346
Text: Bill Gates
347
- Score: 0.555 Offset: 25 Length: 10
347
+ Score: 0.55 Offset: 25 Length: 10
348
348
349
349
Text: Gates
350
- Score: 0.555 Offset: 179 Length: 5
350
+ Score: 0.55 Offset: 179 Length: 5
351
351
352
352
Name: Paul Allen Id: Paul Allen Url: https://en.wikipedia.org/wiki/Paul_Allen
353
353
Data Source: Wikipedia
354
354
Matches:
355
355
Text: Paul Allen
356
- Score: 0.533 Offset: 40 Length: 10
356
+ Score: 0.53 Offset: 40 Length: 10
357
357
358
358
Name: Microsoft Id: Microsoft Url: https://en.wikipedia.org/wiki/Microsoft
359
359
Data Source: Wikipedia
360
360
Matches:
361
361
Text: Microsoft
362
- Score: 0.469 Offset: 0 Length: 9
362
+ Score: 0.47 Offset: 0 Length: 9
363
363
364
364
Text: Microsoft
365
- Score: 0.469 Offset: 168 Length: 9
365
+ Score: 0.47 Offset: 168 Length: 9
366
366
367
367
Name: April 4 Id: April 4 Url: https://en.wikipedia.org/wiki/April_4
368
368
Data Source: Wikipedia
369
369
Matches:
370
370
Text: April 4
371
- Score: 0.248 Offset: 54 Length: 7
371
+ Score: 0.25 Offset: 54 Length: 7
372
372
373
373
Name: BASIC Id: BASIC Url: https://en.wikipedia.org/wiki/BASIC
374
374
Data Source: Wikipedia
375
375
Matches:
376
376
Text: BASIC
377
- Score: 0.281 Offset: 98 Length: 5
377
+ Score: 0.28 Offset: 98 Length: 5
378
378
379
379
```
380
380
0 commit comments