Turn Excel tax-jurisdiction datasets into OpenAI fine-tuning JSONL — for classic completion models and chat models.
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.
- 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
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
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.
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 namedGeolocation Data.
| 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).
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install pandas openpyxlpython create_jsonl_for_chat_finetuning.pyWrites 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 ..."}
]
}python create_jsonl_for_llm_finetuning.pyWrites 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 ..."
}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.
- Change
excel_file/ sheet name at the top of either script - Edit the
templateslist — add or remove question/answer patterns - Adjust
dtypeand zero-padding for your ID fields - 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.
| Package | Role |
|---|---|
pandas |
Read Excel / tabular data |
openpyxl |
Excel engine for .xlsx |
json (stdlib) |
Serialize training objects |
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.