Skip to content

About

Fine-tuning scripts that create jsonls from Excel datasets for OpenAIs text-models (babbage/davinci) and chat-models (GPT-3.5-turbo/GPT-4).

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

🎯 Finetune-GPT

Turn Excel tax-jurisdiction datasets into OpenAI fine-tuning JSONL — for classic completion models and chat models.

Python OpenAI License: GPL v3


Overview

Finetune-GPT is a pair of data-prep scripts that convert structured spreadsheet rows into the training formats OpenAI expects:

Script Target models Output shape
create_jsonl_for_llm_finetuning.py Legacy text models (e.g. Babbage / Davinci-style) prompt + completion pairs
create_jsonl_for_chat_finetuning.py Chat models (GPT-3.5-turbo / GPT-4 family) messages: system / user / assistant

Both scripts were built around a real use case: teaching a model US tax jurisdiction / geolocation facts (Tax Area ID, ZIP, city, county, state, country) from an Excel workbook.


Features

  • Excel-native ingestion via pandas + openpyxl (CSV is an easy edit)
  • Multi-template expansion — each data row becomes several training examples with different question framings
  • Zero-padding helpers for ZIP codes (5 digits) and Tax Area IDs (9 digits)
  • String dtypes for IDs so leading zeros are preserved
  • Two export formats aligned with OpenAI’s completion vs chat fine-tuning APIs

How it works

Location_Training.xlsx  (sheet: "Geolocation Data")
            │
            ▼
     pandas DataFrame
     (ZIP / Tax Area ID as strings)
            │
            ├──────────────────────┐
            ▼                      ▼
  prompt/completion templates   chat message templates
            │                      │
            ▼                      ▼
 prompt_completion_pairs.json   chat_format_pairs.json

Example domain templates

For each row, templates ask things like:

  • “Summarize tax jurisdiction data for Tax Area ID {Tax Area ID}”
  • “Summarize tax jurisdiction data for ZIP {Zip Code}”
  • “Summarize for Tax Area ID + ZIP together”
  • “Summarize for City {City} in State {State}”

Assistant (or completion) text is filled from the same row fields: country, state, county, city, ZIP, Tax Area ID.

That multi-angle expansion helps the fine-tuned model answer the same facts no matter how the user phrases the question.


Project layout

Finetune-GPT/
├── create_jsonl_for_chat_finetuning.py   # Chat-format training data
├── create_jsonl_for_llm_finetuning.py    # Prompt/completion training data
├── LICENSE
└── README.md

Place your workbook (default name: Location_Training.xlsx) next to the scripts. The training sheet is expected to be named Geolocation Data.


Expected Excel columns

Column Notes
Tax Area ID Stored as string; zero-padded to 9 digits
Zip Code Stored as string; zero-padded to 5 digits
Country e.g. United States
State State / region name or code
County County name
City City name

Column names must match the template placeholders exactly (including spaces).


Setup

python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install pandas openpyxl

Usage

1. Chat-model fine-tuning data

python create_jsonl_for_chat_finetuning.py

Writes chat_format_pairs.json with objects shaped like:

{
  "messages": [
    {"role": "system", "content": "You are acting as a tax jurisdiction/geolocation expert..."},
    {"role": "user", "content": "Provide a summary of tax jurisdiction data for Zip Code 10001:"},
    {"role": "assistant", "content": "The tax jurisdiction with Zip Code 10001 has Tax Area ID ..."}
  ]
}

2. Legacy completion-model data

python create_jsonl_for_llm_finetuning.py

Writes prompt_completion_pairs.json with:

{
  "prompt": "Provide a summary of tax jurisdiction data for Tax Area ID 123456789:",
  "completion": "The tax jurisdiction with Tax Area ID 123456789 is located in ..."
}

3. Upload & fine-tune (OpenAI)

Convert/validate to the exact JSONL layout your OpenAI account expects, then use the fine-tuning API or dashboard. Always review a sample of generated rows before spending training budget.


Customizing for your domain

  1. Change excel_file / sheet name at the top of either script
  2. Edit the templates list — add or remove question/answer patterns
  3. Adjust dtype and zero-padding for your ID fields
  4. Re-run and spot-check the JSON output

The scripts are intentionally small and readable so you can adapt them from tax geo data to any structured Q&A dataset.


Dependencies

Package Role
pandas Read Excel / tabular data
openpyxl Excel engine for .xlsx
json (stdlib) Serialize training objects

License

Distributed under the terms of the GNU General Public License v3.0. See LICENSE for details.


Spreadsheet in → fine-tuning examples out. Built for teaching models precise jurisdiction facts.

About

Fine-tuning scripts that create jsonls from Excel datasets for OpenAIs text-models (babbage/davinci) and chat-models (GPT-3.5-turbo/GPT-4).

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages