TRL
🏡 查看所有文档 AWS Trainium & Inferentia Accelerate Argilla AutoTrain Bitsandbytes 聊天用户界面 数据集查看器 数据集 在 AWS 上部署 Diffusers Distilabel Evaluate Gradio Hub Hub Python 库 Huggingface.js 推理端点(专用) 推理服务提供商 LeRobot 排行榜 Lighteval Microsoft Azure Optimum PEFT Safetensors Sentence Transformers TRL 任务 文本嵌入推理 文本生成推理 Tokenizers Transformers Transformers.js smolagents timm
搜索文档
main v0.21.0 v0.20.0 v0.19.1 v0.18.1 v0.17.0 v0.16.1 v0.15.2 v0.14.0 v0.13.0 v0.12.2 v0.11.4 v0.10.1 v0.9.6 v0.8.6 v0.7.11 v0.6.0 v0.5.0 v0.4.7 v0.3.1 v0.2.1 v0.1.1
英
加入 Hugging Face 社区
并获得增强的文档体验
奖励函数 此模块包含一些有用的奖励函数,主要用于 GRPOTrainer 。
格式化奖励 think_format_reward trl.rewards.think_format_reward < 源 > ( completions: list **kwargs ) → list[float]
参数
completions (list[list[dict[str, str]]]
) — 待评估的补全列表。每个补全必须是包含一条消息的列表,即一个包含键 "content"
且其值为补全文本的字典。 **kwargs — 额外的关键字参数。此函数不使用它们,但在函数签名中需要它们以确保与像 GRPOTrainer 这样的训练器兼容。
一个奖励列表,其中每个奖励如果补全符合预期格式则为 1.0,否则为 0.0。
该奖励函数检查推理过程是否被包裹在 "<think>"
和 "</think>"
标签内。如果格式正确,函数返回 1.0 的奖励,否则返回 0.0。
示例
>>> from trl.rewards import think_format_reward
>>> completions = [
... [{"content" : "<think>\nThis is my reasoning.\n</think>\nThis is my answer." }],
... [{"content" : "<think>\nThis is my reasoning.\nThis is my answer." }],
... ]
>>> think_format_reward(completions)
[1.0 , 0.0 ] < > 在 GitHub 上更新
© . This site is unofficial and not affiliated with Hugging Face, Inc.