Reward functions overview
Reward Functions Overview
This guide provides an overview of reward functions in RewardKit and how to use them effectively.
What are Reward Functions?
Reward functions are the core building blocks of RewardKit. They evaluate model responses and provide numerical feedback that can be used for training, evaluation, and analysis.
Basic Structure
Every reward function follows this pattern:
Built-in Reward Functions
RewardKit provides several built-in reward functions:
Accuracy-based
accuracy
: Exact string matchingfuzzy_accuracy
: Fuzzy string matching with configurable threshold
Length-based
length
: Evaluates response lengthlength_penalty
: Penalizes responses that are too long or short
Format-based
json_schema
: Validates JSON responses against a schemaformat_compliance
: Checks if responses follow expected formats
Code-specific
code_execution
: Evaluates code by executing itsyntax_validation
: Checks code syntax
Custom Reward Functions
You can create custom reward functions for domain-specific evaluation:
Best Practices
- Clear Naming: Use descriptive names for your reward functions
- Type Hints: Include type hints for better IDE support
- Documentation: Add docstrings explaining what your function evaluates
- Normalization: Normalize scores to a consistent range (typically 0.0 to 1.0)
- Testing: Test your reward functions with edge cases
Combining Rewards
You can combine multiple reward functions: