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

Principle:AI4Finance Foundation FinGPT Instruction Tuning

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

Overview

A supervised fine-tuning paradigm where a language model is trained on instruction-response pairs to follow task-specific instructions across diverse financial datasets.

Description

Instruction tuning (or supervised fine-tuning, SFT) trains a language model to map instructions to desired outputs. Unlike pre-training (which learns general language patterns), instruction tuning teaches the model to follow instructions in a specific format. The standard FinGPT instruction template is:

Instruction: {instruction}
Input: {input}
Answer: {output}

This format is applied across all benchmark datasets (FPB, FiQA, TFNS, NWGI, Headline, NER, FinRed, FinEval, ConvFinQA) and 10 base models (Llama2, ChatGLM2, Falcon, MPT, Bloom, Qwen, InternLM, Baichuan). The model learns to generalize across financial tasks while following a consistent response format.

Usage

Use this principle when:

  • Adapting a pre-trained model to financial tasks: The model must follow specific instruction formats for sentiment analysis, NER, classification, etc.
  • Multi-task training: Training on multiple benchmark datasets with a shared instruction format.
  • Zero-shot evaluation: Instruction-tuned models can generalize to unseen financial tasks.

Instruction tuning is the core training paradigm for the FinGPT Benchmark and the RAG sentiment analysis pipeline.

Theoretical Basis

Instruction tuning reframes diverse tasks into a unified instruction-response format, enabling cross-task generalization. Given an instruction I, input X, and target Y:

ℒSFT=−log⁡pθ(Y|I,X)

The prompt portion is masked in the loss (set to `pad_token_id` in labels), so the model only learns to generate the response, not the instruction. This ensures the model learns to respond to instructions rather than memorize them.

Key design decisions:

# Abstract: instruction tuning loss masking
prompt_ids = tokenize(instruction + input)
target_ids = tokenize(output)
input_ids = prompt_ids + target_ids
# Mask prompt in labels
labels = [pad_token_id] * len(prompt_ids) + target_ids
loss = cross_entropy(model(input_ids), labels)

Practical Guide

  • Use the `default` template: `Instruction: {instruction}\nInput: {input}\nAnswer: `.
  • Set `label_pad_token_id = -100` in the data collator to ignore prompt tokens in loss.
  • Filter examples exceeding `max_length` (default 512) to prevent truncation issues.
  • Use `gradient_accumulation_steps=8` to simulate larger batch sizes with limited GPU memory.

Related Pages

Implemented By

Uses Heuristic

Page Connections

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