Reasoning#
The reasoning interceptor processes chain-of-thought reasoning from model responses by removing reasoning tokens from content and tracking reasoning statistics.
Overview#
The ResponseReasoningInterceptor
handles models that generate explicit reasoning steps, typically enclosed in special tokens. It removes reasoning content from the final response and tracks reasoning metrics for analysis.
Configuration#
Python Configuration#
from nemo_evaluator.adapters.adapter_config import AdapterConfig, InterceptorConfig
adapter_config = AdapterConfig(
interceptors=[
InterceptorConfig(
name="reasoning",
config={
"start_reasoning_token": "<think>",
"end_reasoning_token": "</think>",
"add_reasoning": True,
"enable_reasoning_tracking": True
}
)
]
)
CLI Configuration#
--overrides 'target.api_endpoint.adapter_config.interceptors=[{"name":"reasoning","config":{"start_reasoning_token":"<think>","end_reasoning_token":"</think>"}}]'
YAML Configuration#
target:
api_endpoint:
adapter_config:
interceptors:
- name: reasoning
config:
start_reasoning_token: "<think>"
end_reasoning_token: "</think>"
add_reasoning: true
enable_reasoning_tracking: true
Configuration Options#
Parameter |
Description |
Default |
Type |
---|---|---|---|
|
Token that marks the start of reasoning section |
|
str | None |
|
Token that marks the end of reasoning section |
|
str |
|
Whether to add reasoning information |
|
bool |
|
Migrate reasoning_content to content field with tokens |
|
bool |
|
Enable reasoning tracking and logging |
|
bool |
|
Include reasoning content if reasoning is not finished (end token not found) |
|
bool |
|
How often (every N responses) to save stats to file |
|
int | None |
|
Whether to enable caching of reasoning statistics |
|
bool |
|
Custom cache directory for reasoning stats |
|
str |
|
How often (every N responses) to log aggregated reasoning statistics |
|
int |
Processing Examples#
Basic Reasoning Stripping#
# Original response from model
original_content = "<think>Let me solve this step by step. 2+2 is basic addition. 2 plus 2 equals 4.</think>The answer is 4."
# After reasoning interceptor processing
# The content field has reasoning removed
processed_content = "The answer is 4."
Multi-Step Reasoning#
# Original response with multi-line reasoning
original_content = """<think>
This is a word problem. Let me break it down:
1. John has 5 apples
2. He gives away 2 apples
3. So he has 5 - 2 = 3 apples left
</think>John has 3 apples remaining."""
# After processing: reasoning tokens and content are removed
processed_content = "John has 3 apples remaining."
Tracked Metrics#
The interceptor automatically tracks the following statistics:
Metric |
Description |
---|---|
|
Total number of responses processed |
|
Number of responses containing reasoning content |
|
Number of responses where reasoning completed (end token found) |
|
Number of responses where reasoning started |
|
Average word count in reasoning content |
|
Average token count in reasoning content |
|
Average word count in original content (before processing) |
|
Average word count in updated content (after processing) |
|
Average token count in updated content |
|
Maximum word count in reasoning content |
|
Maximum token count in reasoning content |
|
Maximum token count in updated content |
|
Total word count across all reasoning content |
|
Total token count across all reasoning content |
These statistics are saved to eval_factory_metrics.json
under the reasoning
key after evaluation completes.
Example: Custom Reasoning Tokens#
from nemo_evaluator.adapters.adapter_config import AdapterConfig, InterceptorConfig
# For models using different reasoning tokens
adapter_config = AdapterConfig(
interceptors=[
InterceptorConfig(
name="reasoning",
config={
"start_reasoning_token": "[REASONING]",
"end_reasoning_token": "[/REASONING]"
}
)
]
)
Example: Combined with Other Interceptors#
from nemo_evaluator.adapters.adapter_config import AdapterConfig, InterceptorConfig
adapter_config = AdapterConfig(
interceptors=[
InterceptorConfig(name="request_logging", config={"max_requests": 50}),
InterceptorConfig(name="response_logging", config={"max_responses": 50}),
InterceptorConfig(
name="reasoning",
config={
"start_reasoning_token": "<think>",
"end_reasoning_token": "</think>",
"enable_reasoning_tracking": True
}
)
]
)