pair_preference_mapper#
Mapper to construct paired preference samples by generating a rejected response and its reason.
This operator uses an API model to generate a new response that is opposite in style, factuality, or stance to the original response. The generated response and the reason for its generation are stored in the sample. The default system prompt and input template are provided, but can be customized. The output is parsed using a regular expression to extract the new response and the reason. If parsing fails, the operator retries up to a specified number of times. The generated response and reason are stored in the sample under the keys 'rejected_response' and 'reason', respectively.
构造配对偏好样本的映射器,通过生成一个被拒绝的回答及其原因。
该算子使用API模型生成与原始回答在风格、事实性或立场上相反的新回答。生成的回答及其生成原因会被存储在样本中。提供了默认的系统提示和输入模板,但可以自定义。输出使用正则表达式解析以提取新回答和原因。如果解析失败,算子将重试指定次数。生成的回答和原因分别存储在样本的'rejected_response'和'reason'键下。
Type 算子类型: mapper
Tags 标签: cpu, api, text
🔧 Parameter Configuration 参数配置#
name 参数名 |
type 类型 |
default 默认值 |
desc 说明 |
|---|---|---|---|
|
<class 'str'> |
|
API model name. |
|
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 guiding the generation task. |
|
typing.Optional[str] |
|
Template for building the model input. It must contain placeholders '{query}' and '{response}', and can optionally include '{reference}'. |
|
typing.Optional[str] |
|
Regular expression for parsing model output. |
|
<class 'str'> |
|
The field name in the sample to store the generated rejected response. Defaults to 'rejected_response'. |
|
<class 'str'> |
|
The field name in the sample to store the reason for generating the response. Defaults to 'reason'. |
|
typing.Annotated[int, Gt(gt=0)] |
|
The number of retries for the API call in case of response parsing failure. Defaults to 3. |
|
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#
PairPreferenceMapper(api_model='qwen2.5-72b-instruct')
📥 input data 输入数据#
王八十娘:小远城王八十的娘亲,李莲花刚到小远城时被方多病偷掉钱袋找小乞丐问路时,刚好发现王八十娘被另一个小乞丐撞到便将她扶起,结识了王八十。 朴二黄:灵山派管家,方多病小厮旺福的父亲。真实身份是金鸳盟的奔雷手辛雷,离开金鸳盟后,用假名朴二黄在灵山派当管家。因害怕王青山看穿他的身份,设计杀死了灵山派的王青山。被捕后识破了李莲花的真实身份,最后在攻击李莲花的时候被方多病情急之下杀死。
📤 output data 输出数据#
王八十娘:小远城王八十的娘亲,李莲花刚到小远城时被方多病偷掉钱袋找小乞丐问路时,刚好发现王八十娘被另一个小乞丐撞到便将她扶起,结识了王八十。 朴二黄:灵山派管家,方多病小厮旺福的父亲。真实身份是金鸳盟的奔雷手辛雷,离开金鸳盟后,用假名朴二黄在灵山派当管家。因害怕王青山看穿他的身份,设计杀死了灵山派的王青山。被捕后识破了李莲花的真实身份,最后在攻击李莲花的时候被方多病情急之下杀死。
test_no_reference#
PairPreferenceMapper(api_model='qwen2.5-72b-instruct', system_prompt='修改问答对中的回答,在语言风格、事实性、人物身份、立场等任一方面与原回答相反。必须按照以下标记格式输出,不要输出其他多余内容。\n【回答】\n生成的新回答\n【原因】\n生成该回答的原因', input_template='以下是原始问答对:\n【问题】\n{query}\n【回答】\n{response}')