Implementation:AI4Finance Foundation FinGPT test ner
| Knowledge Sources | |
|---|---|
| Domains | NLP, Evaluation, Named_Entity_Recognition |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete tool for evaluating financial LLMs on the Financial Named Entity Recognition (NER) benchmark provided by the FinGPT Benchmark harness.
Description
The test_ner function evaluates a fine-tuned model on the financial NER dataset. It loads the dataset, constructs NER instruction prompts, generates model predictions in batches, and computes entity-level F1 using `seqeval.metrics.classification_report`. Unlike sentiment tasks, NER requires token-level evaluation where predictions are compared against gold entity tags.
Similar structure applies to test_re (FinRed relation extraction) and test_convfinqa (numerical QA), which use the same dispatch pattern but different metrics.
Usage
Import this function when you need to evaluate model performance on financial NER:
- Benchmark evaluation: Standard NER entity-level F1 via seqeval.
- Token-level evaluation: Different from sentiment tasks which use classification metrics.
Code Reference
Source Location
- Repository: FinGPT
- File: fingpt/FinGPT_Benchmark/benchmarks/ner.py
- Lines: L54-94
Signature
def test_ner(
args: Namespace,
model: PeftModel,
tokenizer: AutoTokenizer,
) -> pd.DataFrame
Import
from ner import test_ner
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 |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | pd.DataFrame | DataFrame with predictions |
| metrics | printed | Entity-level precision, recall, F1 via seqeval |
Usage Examples
NER Evaluation
from ner import test_ner
results = test_ner(args, model, tokenizer)
# Prints entity-level precision, recall, F1
Related Pages
Implements Principle
- Principle:AI4Finance_Foundation_FinGPT_Benchmark_Evaluation
- Principle:AI4Finance_Foundation_FinGPT_Metric_Computation
Uses Heuristic
- Heuristic:AI4Finance_Foundation_FinGPT_CUDA_Cache_Management
- Heuristic:AI4Finance_Foundation_FinGPT_Quantization_Fallback_Chain