Implementation:AI4Finance Foundation FinGPT create dataset
| Knowledge Sources | |
|---|---|
| Domains | NLP, Data_Preparation, Finance |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete tool for assembling per-symbol GPT-4 labeled data into a train/test DatasetDict provided by the FinGPT Forecaster pipeline.
Description
The create_dataset function transforms per-symbol GPT-4 labeled CSVs into a HuggingFace `DatasetDict` with `train` and `test` splits. For each symbol, it calls `gpt4_to_llama` which reformats prompts into Llama-2 chat template (`[INST]<<SYS>>...<</SYS>>...[/INST]`) and extracts the prediction label. The resulting datasets are concatenated across all symbols and split by `train_ratio`.
Usage
Import this function when you need to build the final training dataset from GPT-4 labeled data:
- Dataset construction: Assembling the train/test split for LoRA fine-tuning.
- Multi-symbol datasets: Combining multiple tickers into a single DatasetDict.
Code Reference
Source Location
- Repository: FinGPT
- File: fingpt/FinGPT_Forecaster/data.py
- Lines: L317-361 (create_dataset), L257-314 (gpt4_to_llama helper)
Signature
def create_dataset(
symbol_list: list,
data_dir: str,
start_date: str,
end_date: str,
train_ratio: float = 0.8,
with_basics: bool = True,
with_market_sentiment: bool = False,
) -> datasets.DatasetDict
Import
from data import create_dataset
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| symbol_list | list | Yes | List of ticker symbols |
| data_dir | str | Yes | Directory with GPT-4 labeled CSVs |
| start_date | str | Yes | Start date YYYY-MM-DD |
| end_date | str | Yes | End date YYYY-MM-DD |
| train_ratio | float | No | Fraction for train split (default 0.8) |
| with_basics | bool | No | Must match prior steps (default True) |
| with_market_sentiment | bool | No | Must match prior steps (default False) |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | datasets.DatasetDict | Dict with 'train' and 'test' splits; each example has prompt, answer, period, label, symbol fields |
Usage Examples
Build Training Dataset
from data import create_dataset
from indices import DOW_30
dataset = create_dataset(
symbol_list=["AAPL", "MSFT"],
data_dir="./data",
start_date="2023-01-01",
end_date="2023-12-31",
train_ratio=0.8,
with_basics=True,
)
print(dataset)
# DatasetDict({
# train: Dataset({features: ['prompt', 'answer', 'period', 'label', 'symbol'], num_rows: ...}),
# test: Dataset({features: ['prompt', 'answer', 'period', 'label', 'symbol'], num_rows: ...})
# })