Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI4Finance Foundation FinGPT test ner

From Leeroopedia
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

Uses Heuristic

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment