0 / 0
Go back to the English version of the documentation
观点分类
Last updated: 2024年7月29日
观点分类

Watson 自然语言处理观点分类模型对输入文本的观点进行分类。

受支持的语言

观点分类可用于以下语言。 有关语言代码和相应语言的列表,请参阅 语言代码

ar , cs , da , de , en , es , fi , fr , he , hi , it , ja , ko , nb , nl , nn , pl , pt , ro , ru , sk , sv , tr , zh-cn

情绪

文本的观点可以是正面的,负面的或中立的。

观点模型计算输入文档中每个句子的观点。 还会使用观点转换工作流程来计算整个文档的聚集观点。

返回的分类包含概率。 情感得分从 -1 到 1 不等。 大于 0 的分数表示正面观点,小于 0 的分数表示负面观点,而大于 0 的分数表示中立观点。

语句观点工作流程

工作流程名称

  • sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled
  • sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled-cpu

可以在 CPU 和 GPU 上使用 sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled 工作流程。

针对基于 CPU 的运行时优化了 sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled-cpu 工作流程。

使用 sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled 工作流程的代码样本

# Load the Sentiment workflow
sentiment_model = watson_nlp.load('sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled-cpu')

# Run the sentiment model on the result of the syntax results
sentiment_result = sentiment_model.run('The rooms are nice. But the beds are not very comfortable.')

# Print the sentence sentiment results
print(sentiment_result)

代码样本的输出:

{
  "document_sentiment": {
    "score": -0.339735,
    "label": "SENT_NEGATIVE",
    "mixed": true,
    "sentiment_mentions": [
      {
        "span": {
          "begin": 0,
          "end": 19,
          "text": "The rooms are nice."
        },
        "sentimentprob": {
          "positive": 0.9720447063446045,
          "neutral": 0.011838269419968128,
          "negative": 0.016117043793201447
        }
      },
      {
        "span": {
          "begin": 20,
          "end": 58,
          "text": "But the beds are not very comfortable."
        },
        "sentimentprob": {
          "positive": 0.0011594508541747928,
          "neutral": 0.006315878126770258,
          "negative": 0.9925248026847839
        }
      }
    ]
  },
  "targeted_sentiments": {
    "targeted_sentiments": {},
    "producer_id": {
      "name": "Aggregated Sentiment Workflow",
      "version": "0.0.1"
    }
  },
  "producer_id": {
    "name": "Aggregated Sentiment Workflow",
    "version": "0.0.1"
  }
}

目标观点提取

目标观点提取提取文本中表达的观点,并确定这些观点的目标。

它可以在一个语句中处理具有不同情绪的多个目标,而不是上面描述的情绪块。

例如,给定输入句子 所提供的食品是美味的,但服务是缓慢的。 "目标" 情绪块标识目标 "食品" 中表达了积极情绪, "服务" 中表达了消极情绪。

该模型仅针对英语数据进行了微调。 虽然您可以在 "支持的语言" 下列出的其他语言上使用模型,但结果可能有所不同。

目标观点工作流程

工作流程名称

  • targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled
  • targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled-cpu

可以在 CPU 和 GPU 上使用 targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled 工作流程。

针对基于 CPU 的运行时优化了 targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled-cpu 工作流程。

targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled 工作流程的代码样本

import watson_nlp
# Load Targets Sentiment model for English
targets_sentiment_model = watson_nlp.load('targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled')
# Run the targets sentiment model on the input text
targets_sentiments = targets_sentiment_model.run('The rooms are nice, but the bed was not very comfortable.')
# Print the targets with the associated sentiment
print(targets_sentiments)

代码样本的输出:

{
  "targeted_sentiments": {
    "rooms": {
      "score": 0.990798830986023,
      "label": "SENT_POSITIVE",
      "mixed": false,
      "sentiment_mentions": [
        {
          "span": {
            "begin": 4,
            "end": 9,
            "text": "rooms"
          },
          "sentimentprob": {
            "positive": 0.990798830986023,
            "neutral": 0.0,
            "negative": 0.00920116901397705
          }
        }
      ]
    },
    "bed": {
      "score": -0.9920912981033325,
      "label": "SENT_NEGATIVE",
      "mixed": false,
      "sentiment_mentions": [
        {
          "span": {
            "begin": 28,
            "end": 31,
            "text": "bed"
          },
          "sentimentprob": {
            "positive": 0.00790870189666748,
            "neutral": 0.0,
            "negative": 0.9920912981033325
          }
        }
      ]
    }
  },
  "producer_id": {
    "name": "Transformer-based Targets Sentiment Extraction Workflow",
    "version": "0.0.1"
  }
}

父主题: Watson Natural Language Processing 任务目录

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more