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 GenerationEvalCallback

From Leeroopedia
Knowledge Sources
Domains Deep_Learning, Evaluation
Last Updated 2026-10-18 00:00 GMT

Overview

Custom training callback for the Forecaster that evaluates text generation quality (ROUGE, binary accuracy) during training by generating predictions on an eval subset.

Description

The GenerationEvalCallback is a `TrainerCallback` subclass used in the Forecaster training pipeline. During evaluation steps, it generates model predictions on a 50-sample eval subset, extracts answers using regex (stripping content before `[/INST]`), and computes metrics via `calc_metrics` (binary accuracy, MSE, ROUGE scores for positive developments, potential concerns, and analysis sections). Results are logged to wandb.

The callback has an `ignore_until_epoch` parameter to skip early evaluations during the initial training phase (default: first 30% of epochs).

Usage

Import this class when you need custom generation-based evaluation during training:

  • Forecaster training: Evaluating generated analysis quality during training.
  • Text generation monitoring: Tracking ROUGE and prediction accuracy over training steps.

Code Reference

Source Location

  • Repository: FinGPT
  • File: fingpt/FinGPT_Forecaster/train_lora.py
  • Lines: L34-79

Signature

class GenerationEvalCallback(TrainerCallback):
    def __init__(
        self,
        eval_dataset: Dataset,
        ignore_until_epoch: int = 0,
    )

    def on_evaluate(
        self,
        args,
        state: TrainerState,
        control: TrainerControl,
        **kwargs,
    ) -> None

Import

from train_lora import GenerationEvalCallback

I/O Contract

Inputs

Name Type Required Description
eval_dataset Dataset Yes 50-sample eval subset with 'prompt' and 'answer' fields
ignore_until_epoch int No Skip evaluation before this epoch (default 0)

Outputs

Name Type Description
wandb logs dict Metrics logged to wandb: bin_acc, mse, rouge scores

Usage Examples

Use in Trainer

from train_lora import GenerationEvalCallback

eval_dataset = original_dataset['test'].shuffle(seed=42).select(range(50))

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=dataset['train'],
    eval_dataset=dataset['test'],
    tokenizer=tokenizer,
    data_collator=DataCollatorForSeq2Seq(tokenizer, padding=True),
    callbacks=[
        GenerationEvalCallback(
            eval_dataset=eval_dataset,
            ignore_until_epoch=round(0.3 * args.num_epochs),
        )
    ],
)

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

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