Sentiment Analysis Module¶
pipelines.pipelines.nodes.sentiment_analysis.senta_preprocessor ¶
SentaProcessor ¶
Read and preprocess texts that you wanna perform sentiment analysis.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_preprocessor.py
__init__ ¶
Init Senta Preprocessor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_examples |
int
|
Maximum amount of examples to process. if you set to be -1, it will keep all examples to analyze. |
-1
|
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_preprocessor.py
pipelines.pipelines.nodes.sentiment_analysis.senta_visualization ¶
SentaVisualization ¶
Generate Images with the Result of Sentiment Analysis.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
__init__ ¶
Init Senta Visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
font_name |
str
|
The font name used to generate images. |
'SimHei'
|
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
run ¶
:Param sr_save_path: The file path of sentiment analysis fesults.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
SentimentResult ¶
load and analyze result of sentiment analysis.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
VisualSentiment ¶
A tool class for visualing sentiment analysis results.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
plot_aspect_with_frequency ¶
plot_aspect_with_frequency(aspect_freq, save_path, image_type='wordcloud', with_line_chart='true', top_n=15)
generate image for aspect, two types of images are supported: wordcloud and histogram. this method can help analyze which aspects of the product/service are more important to customers. Args: aspect_freq (dict): an aspect dict with frequency, the key is aspect and its value is frequency. save_path (str): path that the image is saved to. image_type (str): Only wordcloud and histogram are supported, that is, you should set be in [wordcloud, histogram]. with_line_chart (bool): Whether to plot line chart, Only work when image_type is set be histogram. top_n (int): show top_n of frequency of apsects, Only work when image_type is set be histogram.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
plot_aspect_with_opinion ¶
plot_aspect_with_opinion(aspect_opinion, save_path, sentiment='all', image_type='wordcloud', with_line_chart='true', top_n=15)
generate image with aspect and opinion, that is, combining apsect with opinion to display the more specifical opinions of aspect. this method can help you at two aspects: 1. mining custom's overall impression of products/services; 2. analyzing the quality of some aspect and improve it further. Args: aspect_opinion (dict[dict] or dict): when sentiment set be "all", a expected dict containing aspect, opinion and its frequency, the key is aspect and its value is a dict containing the aspect's opinion and frequency. when sentiment set be "positive" or "netative", a expected dict containing aspect with opinion and frequency, the key is aspect with opinion and its value is frequency. aspect_sentiment (dict[dict]): a dict containing aspect, sentiment and its frequency, the key is aspect and its value is a dict containing the aspect's sentiment and frequency. save_path (str): path that the image is saved to. sentiment (str): analyzing aspect with sentiment, Only "all", "positive" and "negative" are received. "positive" only analyzes positive aspects with opinions, "negative" only analyzes negative aspects with opinions, and "all" analyzes all apsects. image_type (str): Only wordcloud and histogram are supported, that is, you should set be in [wordcloud, histogram]. with_line_chart (bool): Whether to plot line chart, Only work when image_type is set be histogram. top_n (int): show top_n of frequency of opinions, Only work when image_type is set be histogram.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
plot_aspect_with_sentiment ¶
plot_aspect_with_sentiment(aspect_sentiment, save_path, image_type='wordcloud', top_n=0, descend_aspects=None)
generate image with aspect and sentiment, that is, combining apsect and sentiment to display the sentiment of aspect. This method can help you more intuitively analyze customers' direct impressions of aspects of products/services. Args: aspect_sentiment (dict[dict]): a dict containing aspect, sentiment and its frequency, the key is aspect and its value is a dict containing the aspect's sentiment and frequency. descend_aspects (dict): an aspect list, sorted by frequency in reverse order. save_path (str): path that the image is saved to. image_type (str): Only wordcloud and histogram are supported, that is, you should set be in [wordcloud, histogram]. top_n (int): show top_n of frequency of opinions, Only work when image_type is set be histogram. if top_n set be 0, it will plot all aspects in histogram.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
plot_opinion_with_aspect ¶
plot_opinion_with_aspect(aspect, aspect_opinion, save_path, image_type='wordcloud', with_line_chart=True, top_n=15)
generate opinion image for given aspect. This method can help you analyzing opinions for given aspects. Args: aspect (str): The set of aspect to analyze. aspect_opinion (dict[dict] or dict): when sentiment set be "all", a expected dict containing aspect, opinion and its frequency, the key is aspect and its value is a dict containing the aspect's opinion and frequency. when sentiment set be "positive" or "netative", a expected dict containing aspect with opinion and frequency, the key is aspect with opinion and its value is frequency. save_path (str): path that the image is saved to. image_type (str): Only wordcloud and histogram are supported, that is, you should set be in [wordcloud, histogram]. with_line_chart (bool): Whether to plot line chart, Only work when image_type is set be histogram. top_n (int): show top_n of frequency of opinions, Only work when image_type is set be histogram.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
plot_opinion_with_frequency ¶
plot_opinion_with_frequency(opinion_freq, save_path, image_type='wordcloud', with_line_chart='true', top_n=15)
generate image for opinion, two types of images are supported: wordcloud and histogram. this method can help analyze the whole impression of the product/service. Args: opinion_freq (dict): an opinion dict with frequency, the key is opinion and its value is frequency. save_path (str): path that the image is saved to. image_type (str): Only wordcloud and histogram are supported, that is, you should set be in [wordcloud, histogram]. with_line_chart (bool): Whether to plot line chart, Only work when image_type is set be histogram. top_n (int): show top_n of frequency of opinions, Only work when image_type is set be histogram.
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta_visualization.py
pipelines.pipelines.nodes.sentiment_analysis.senta ¶
UIESenta ¶
Senta: sentiment analysis for user's comments based on Taskflow
Source code in pipelines/pipelines/nodes/sentiment_analysis/senta.py
__init__ ¶
__init__(model, schema, task='sentiment_analysis', aspects=None, max_seq_len=512, batch_size=1, split_sentence=False, position_prob=0.5, lazy_load=False, num_workers=0, use_fast=False, **kwargs)
Init UIESenta for Sentiment Analysis. :num_workers: the number of subprocess to load data for dataloader, 0 for no subprocess used and loading data in main process. Default 0. :use_fast: whether to fast tokenizer for UIE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
the model name that you wanna use, you can choose it in [use-base, uie-medium, uie-micro, uie-mini, uie-nano]. |
required | |
schema |
the schema for extracting sentiment information with UIE. |
required | |
task |
the task name, you should set to be |
'sentiment_analysis'
|
|
aspects |
optional, a list of pre-given aspects, that is to say, Taskflow only perform sentiment analysis on these pre-given aspects if you input it. |
None
|
|
max_seq_len |
The maximum total input sequence length after tokenization. Sequences longer than this will be truncated, sequences shorter will be padded. |
512
|
|
batch_size |
Number of samples the model receives in one batch for inference. |
1
|
|
split_sentence |
If True, sentence-level split will be performed on the inputing examples. |
False
|
|
position_prob |
Probability threshold for start/end index probabiliry. |
0.5
|
|
lazy_load |
whether to using |
False
|