Heuristic:AI4Finance Foundation FinGPT Output Normalization
| Knowledge Sources | |
|---|---|
| Domains | NLP, Evaluation, Sentiment_Analysis |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Normalize free-form LLM sentiment outputs to canonical labels (positive/negative/neutral) using substring matching before computing metrics.
Description
LLMs generate sentiment predictions in free-form text that may include capitalization variations, extra context, or non-standard phrasing. The `change_target` function normalizes any output containing "positive" or "negative" (case-insensitive) to the canonical label, defaulting to "neutral" otherwise. This normalization is applied to both predictions and ground truth before computing accuracy and F1 scores. For multi-template voting, each template's output is individually normalized before majority voting.
Usage
Use this heuristic for Benchmark Evaluation of sentiment tasks (FPB, FiQA, TFNS, NWGI, Headline). Apply `change_target` to all model outputs before metric computation.
The Insight (Rule of Thumb)
- Action: Apply `change_target` to normalize outputs containing "positive"/"negative" (case-insensitive) to canonical labels; default to "neutral".
- Value: Map: contains "positive" → "positive", contains "negative" → "negative", else → "neutral".
- Trade-off: May misclassify ambiguous outputs as neutral, but ensures metric compatibility.
- Compatibility: Used by all sentiment benchmarks (FPB, FiQA, TFNS, NWGI, Headline) and the template voting ensemble.
Reasoning
Instruction-tuned LLMs don't always output exactly one of {positive, negative, neutral}. They may write "The sentiment is positive." or "This is Negative." Raw string comparison would fail. Substring matching is a simple, robust normalization that handles capitalization and surrounding text. The "neutral" default catches cases where the model doesn't produce a clear sentiment, preventing metric computation errors.
Code Evidence
`change_target` normalization from `fingpt/FinGPT_Benchmark/benchmarks/fpb.py:32-38`:
def change_target(x):
if 'positive' in x or 'Positive' in x:
return 'positive'
elif 'negative' in x or 'Negative' in x:
return 'negative'
else:
return 'neutral'
Applied to both predictions and ground truth from `fingpt/FinGPT_Benchmark/benchmarks/fpb.py:94-95`:
instructions["new_target"] = instructions["target"].apply(change_target)
instructions["new_out"] = instructions["out_text"].apply(change_target)
Used in template voting from `fingpt/FinGPT_Benchmark/benchmarks/fpb.py:41-51`:
def vote_output(x):
output_dict = {'positive': 0, 'negative': 0, 'neutral': 0}
for i in range(len(templates)):
pred = change_target(x[f'out_text_{i}'].lower())
output_dict[pred] += 1
if output_dict['positive'] > output_dict['negative']:
return 'positive'
elif output_dict['negative'] > output_dict['positive']:
return 'negative'
else:
return 'neutral'