dialog_sentiment_detection_mapper¶
Generates sentiment labels and analysis for user queries in a dialog.
This operator processes a dialog to detect and label the sentiments expressed by the user. It uses the provided history, query, and response keys to construct prompts for an API call. The API returns sentiment analysis and labels, which are then parsed and stored in the sample's metadata under the 'dialog_sentiment_labels' and 'dialog_sentiment_labels_analysis' keys. The operator supports custom templates and patterns for prompt construction and output parsing. If no sentiment candidates are provided, it uses open-domain sentiment labels. The operator retries the API call up to a specified number of times in case of errors.
为用户查询在对话中生成情感标签和分析。
该算子处理对话以检测并标记用户表达的情感。它使用提供的历史记录、查询和响应键来构建API调用的提示。API返回情感分析和标签,然后解析并将结果存储在样本的元数据中的'dialog_sentiment_labels'和'dialog_sentiment_labels_analysis'键下。该算子支持自定义模板和模式用于提示构建和输出解析。如果没有提供情感候选,则使用开放领域情感标签。该算子在出现错误时最多重试指定次数的API调用。
Type 算子类型: mapper
Tags 标签: cpu, api
🔧 Parameter Configuration 参数配置¶
name 参数名 |
type 类型 |
default 默认值 |
desc 说明 |
---|---|---|---|
|
<class 'str'> |
|
API model name. |
|
typing.Optional[typing.List[str]] |
|
The output sentiment candidates. Use open-domain sentiment labels if it is None. |
|
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 labels. It is 'dialog_sentiment_labels' in default. |
|
<class 'str'> |
|
The key name in the meta field to store the corresponding analysis. It is 'dialog_sentiment_labels_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 sentiment candidates to build the input prompt. |
|
typing.Optional[str] |
|
Template for analysis part to build the input prompt. |
|
typing.Optional[str] |
|
Template for labels 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 labels. |
|
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¶
DialogSentimentDetectionMapper(api_model='qwen2.5-72b-instruct')
📥 input data 输入数据¶
📤 output data 输出数据¶
✨ explanation 解释¶
This example demonstrates the default behavior of the operator, which analyzes the sentiment of each dialog in the provided history. The operator uses an API to detect and label the sentiments expressed by the user. The output includes both the sentiment labels (e.g., '赞赏、肯定', '讽刺、不满') and a detailed analysis of each sentiment (e.g., '用户提到“李莲花有口皆碑”,这表明用户对李莲花的评价很高,认为她受到了广泛的赞誉和认可,语气中带有赞赏和肯定。'). 此示例展示了算子的默认行为,它分析所提供历史记录中每个对话的情绪。算子使用API来检测并标记用户表达的情绪。输出包括情绪标签(例如,“赞赏、肯定”,“讽刺、不满”)以及对每种情绪的详细分析(例如,“用户提到‘李莲花有口皆碑’,这表明用户对李莲花的评价很高,认为她受到了广泛的赞誉和认可,语气中带有赞赏和肯定。”)。