dialog_sentiment_intensity_mapper¶
Mapper to predict user’s sentiment intensity in a dialog, ranging from -5 to 5.
This operator analyzes the sentiment of user queries in a dialog and outputs a list of sentiment intensities and corresponding analyses. The sentiment intensity ranges from -5 (extremely negative) to 5 (extremely positive), with 0 indicating a neutral sentiment. The analysis is based on the provided history, query, and response keys. The default system prompt and templates guide the sentiment analysis process. The results are stored in the meta field under ‘dialog_sentiment_intensity’ for intensities and ‘dialog_sentiment_intensity_analysis’ for analyses. The operator uses an API model to generate the sentiment analysis, with configurable retry attempts and sampling parameters.
预测用户在对话中的情感强度,范围从-5到5。
该算子分析对话中用户查询的情感,并输出一个情感强度列表及其对应的分析。情感强度范围从-5(极其负面)到5(极其正面),0表示中性情感。分析基于提供的历史记录、查询和响应键。默认系统提示和模板指导情感分析过程。结果存储在元数据字段下的’dialog_sentiment_intensity’键(强度)和’dialog_sentiment_intensity_analysis’键(分析)。该算子使用API模型生成情感分析,可配置重试尝试和采样参数。
Type 算子类型: mapper
Tags 标签: cpu, api
🔧 Parameter Configuration 参数配置¶
name 参数名 |
type 类型 |
default 默认值 |
desc 说明 |
---|---|---|---|
|
<class ‘str’> |
|
API model name. |
|
typing.Annotated[int, Ge(ge=0)] |
|
The max num of round in the dialog to build the prompt. |
|
<class ‘str’> |
|
The key name in the meta field to store the output sentiment intensities. It is ‘dialog_sentiment_intensity’ in default. |
|
<class ‘str’> |
|
The key name in the meta field to store the corresponding analysis. It is ‘dialog_sentiment_intensity_analysis’ in default. |
|
typing.Optional[str] |
|
URL endpoint for the API. |
|
typing.Optional[str] |
|
Path to extract content from the API response. Defaults to ‘choices.0.message.content’. |
|
typing.Optional[str] |
|
System prompt for the task. |
|
typing.Optional[str] |
|
Template for query part to build the input prompt. |
|
typing.Optional[str] |
|
Template for response part to build the input prompt. |
|
typing.Optional[str] |
|
Template for analysis part to build the input prompt. |
|
typing.Optional[str] |
|
Template for intensity part to build the input prompt. |
|
typing.Optional[str] |
|
Pattern to parse the return sentiment analysis. |
|
typing.Optional[str] |
|
Pattern to parse the return sentiment intensity. |
|
typing.Annotated[int, Gt(gt=0)] |
|
The number of retry attempts when there is an API call error or output parsing error. |
|
typing.Dict |
|
Parameters for initializing the API model. |
|
typing.Dict |
|
Extra parameters passed to the API call. e.g {‘temperature’: 0.9, ‘top_p’: 0.95} |
|
|
Extra keyword arguments. |
📊 Effect demonstration 效果演示¶
test_default¶
DialogSentimentIntensityMapper(api_model='qwen2.5-72b-instruct')
📥 input data 输入数据¶
📤 output data 输出数据¶
✨ explanation 解释¶
This example shows the default behavior of the operator, which analyzes the sentiment intensity and provides an analysis for each dialog round. The sentiment intensity ranges from -5 (extremely negative) to 5 (extremely positive). In this case, the operator processes four rounds of dialog and outputs the corresponding sentiment intensities and analyses. 这个例子展示了算子的默认行为,它分析每个对话轮次的情绪强度并提供分析。情绪强度范围从-5(极度负面)到5(极度正面)。在这个例子中,算子处理了四轮对话,并输出相应的情绪强度和分析。
test_max_round_zero¶
DialogSentimentIntensityMapper(api_model='qwen2.5-72b-instruct', max_round=0)
📥 input data 输入数据¶
📤 output data 输出数据¶
✨ explanation 解释¶
This example demonstrates an edge case where the max_round
parameter is set to 0. This means that the operator will not consider any historical context and will only analyze the current round of the dialog. The output shows the sentiment intensities and analyses for each round, but without considering the previous context, the results may differ from the default case.
这个例子展示了一个边缘情况,其中max_round
参数设置为0。这意味着算子不会考虑任何历史上下文,只会分析当前轮次的对话。输出显示了每一轮的情绪强度和分析,但由于没有考虑之前的上下文,结果可能与默认情况不同。