Implementation:AI4Finance Foundation FinGPT test fpb
| Knowledge Sources | |
|---|---|
| Domains | NLP, Evaluation, Sentiment_Analysis |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete tool for evaluating financial LLMs on the Financial PhraseBank (FPB) sentiment classification benchmark provided by the FinGPT Benchmark harness.
Description
The test_fpb function evaluates a fine-tuned model on the FPB dataset, which contains financial news sentences labeled as negative (0), neutral (1), or positive (2). It loads the dataset from disk, constructs instruction prompts ("What is the sentiment of this news?"), generates model predictions in batches, normalizes outputs via `change_target`, and computes accuracy and F1 (macro, micro, weighted).
The multi-template variant test_fpb_mlt evaluates the model across multiple sentiment prompt templates (from `sentiment_templates.txt`) and ensembles predictions via majority voting (`vote_output`).
Usage
Import this function when you need to evaluate model performance on the FPB benchmark:
- Benchmark evaluation: Standard FPB sentiment accuracy and F1.
- Multi-template evaluation: Template ensemble via `test_fpb_mlt` for robust sentiment classification.
Code Reference
Source Location
- Repository: FinGPT
- File: fingpt/FinGPT_Benchmark/benchmarks/fpb.py
- Lines: L53-104 (test_fpb), L107-168 (test_fpb_mlt)
Signature
def test_fpb(
args: Namespace,
model: PeftModel,
tokenizer: AutoTokenizer,
prompt_fun: Optional[Callable] = None,
) -> pd.DataFrame
def test_fpb_mlt(
args: Namespace,
model: PeftModel,
tokenizer: AutoTokenizer,
) -> pd.DataFrame
Import
from fpb import test_fpb, test_fpb_mlt
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| args | Namespace | Yes | Contains batch_size, max_length, instruct_template |
| model | PeftModel | Yes | Fine-tuned model in eval mode |
| tokenizer | AutoTokenizer | Yes | Model tokenizer |
| prompt_fun | Callable | No | Custom instruction formatter (default uses standard sentiment prompt) |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | pd.DataFrame | DataFrame with out_text, new_target, new_out columns |
| metrics | printed | Accuracy, F1 macro, F1 micro, F1 weighted |
Usage Examples
Standard FPB Evaluation
from fpb import test_fpb
results = test_fpb(args, model, tokenizer)
# Prints: Acc: 0.85. F1 macro: 0.83. F1 micro: 0.85. F1 weighted: 0.84.
Multi-Template Evaluation
from fpb import test_fpb_mlt
results = test_fpb_mlt(args, model, tokenizer)
# Evaluates across all templates in sentiment_templates.txt
# Ensembles via vote_output (majority voting)
Related Pages
Implements Principle
- Principle:AI4Finance_Foundation_FinGPT_Benchmark_Evaluation
- Principle:AI4Finance_Foundation_FinGPT_Sentiment_Classification
- Principle:AI4Finance_Foundation_FinGPT_Metric_Computation
Uses Heuristic
- Heuristic:AI4Finance_Foundation_FinGPT_Output_Normalization
- Heuristic:AI4Finance_Foundation_FinGPT_Template_Ensemble_Voting
- Heuristic:AI4Finance_Foundation_FinGPT_CUDA_Cache_Management
- Heuristic:AI4Finance_Foundation_FinGPT_Quantization_Fallback_Chain