# darthreca/losses-cook architecture

> Architecture diagram of the GitHub repository darthreca/losses-cook, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/darthreca/losses-cook
- Repository: https://github.com/darthreca/losses-cook

## Overview

This repository is a research fine-tuning pipeline for structured recipe generation, centered on comparing token-level and ingredient-structure losses. The workflow configures datasets and a language model, loads training and validation data, fine-tunes with a custom weighted-loss Trainer, and saves the resulting model and tokenizer. The README also describes recipe-quality evaluation and human preference results; sampled code shows validation wiring but not the metric or study implementations. The data-file wiring is not fully clear from the sampled entry point, so uncertain links are omitted.

Main entry points: [`improved_loss.py`](https://github.com/darthreca/losses-cook/blob/main/improved_loss.py) (Training entrypoint), [`model/loss_model.py`](https://github.com/darthreca/losses-cook/blob/main/model/loss_model.py) (Weighted loss), [`loss/topological_loss.py`](https://github.com/darthreca/losses-cook/blob/main/loss/topological_loss.py) (Topological loss), [`data`](https://github.com/darthreca/losses-cook/tree/main/data) (Recipe source files)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Recipe data"]
  node_dataset_configs["Dataset configs"]
  node_recipe_files["Recipe source files"]
  node_prepared_data[("Prepared datasets")]
  node_collator["Custom collator<br/>[improved_loss.py]"]
end

subgraph group_training["Fine-tuning"]
  node_entry["Training entrypoint<br/>[improved_loss.py]"]
  node_model_configs["Model configs"]
  node_trainer_config["Trainer config"]
  node_tokenizer["Tokenizer<br/>[improved_loss.py]"]
  node_base_model["Causal LM<br/>[improved_loss.py]"]
  node_lora["LoRA adaptation<br/>[improved_loss.py]"]
  node_trainer["Custom Trainer<br/>[loss_model.py]"]
end

subgraph group_objectives["Loss objectives"]
  node_loss_config["Loss config"]
  node_loss_mix["Weighted loss<br/>[loss_model.py]"]
  node_ce["Cross entropy<br/>[loss_model.py]"]
  node_dice["Generalized Dice<br/>[dice_loss.py]"]
  node_focal["Focal loss<br/>[focal_loss.py]"]
  node_topological["Topological loss"]
  node_sinkhorn["Sinkhorn divergence"]
end

subgraph group_results["Tracking and outputs"]
  node_comet["Comet tracking<br/>[improved_loss.py]"]
  node_saved_model["Fine-tuned model"]
end

node_researcher(("Researcher"))

node_researcher -->|"runs"| node_entry
node_entry -->|"loads config"| node_dataset_configs
node_entry -->|"loads config"| node_model_configs
node_entry -->|"loads config"| node_trainer_config
node_entry -->|"loads config"| node_loss_config
node_recipe_files -.-> node_prepared_data
node_entry -->|"loads datasets"| node_prepared_data
node_entry -->|"loads"| node_tokenizer
node_entry -->|"loads"| node_base_model
node_entry -->|"adapts model"| node_lora
node_entry -->|"configures"| node_collator
node_entry -->|"constructs"| node_trainer
node_entry -.->|"optionally initializes"| node_comet
node_trainer -->|"runs forward"| node_base_model
node_trainer -->|"uses batches"| node_collator
node_trainer -->|"computes"| node_loss_mix
node_loss_mix -->|"optionally applies"| node_ce
node_loss_mix -->|"optionally applies"| node_dice
node_loss_mix -->|"optionally applies"| node_focal
node_loss_mix -->|"optionally applies"| node_topological
node_topological -->|"computes divergence"| node_sinkhorn
node_entry -->|"saves model"| node_saved_model
node_entry -->|"saves tokenizer"| node_tokenizer

click node_entry "https://github.com/darthreca/losses-cook/blob/main/improved_loss.py"
click node_dataset_configs "https://github.com/darthreca/losses-cook/tree/main/configs/dataset"
click node_model_configs "https://github.com/darthreca/losses-cook/tree/main/configs/model"
click node_trainer_config "https://github.com/darthreca/losses-cook/tree/main/configs/trainer"
click node_loss_config "https://github.com/darthreca/losses-cook/blob/main/configs/loss_topological-recipenlg_Qwen3-4B.yaml"
click node_recipe_files "https://github.com/darthreca/losses-cook/tree/main/data"
click node_tokenizer "https://github.com/darthreca/losses-cook/blob/main/improved_loss.py"
click node_base_model "https://github.com/darthreca/losses-cook/blob/main/improved_loss.py"
click node_lora "https://github.com/darthreca/losses-cook/blob/main/improved_loss.py"
click node_collator "https://github.com/darthreca/losses-cook/blob/main/improved_loss.py"
click node_trainer "https://github.com/darthreca/losses-cook/blob/main/model/loss_model.py"
click node_loss_mix "https://github.com/darthreca/losses-cook/blob/main/model/loss_model.py"
click node_ce "https://github.com/darthreca/losses-cook/blob/main/model/loss_model.py"
click node_dice "https://github.com/darthreca/losses-cook/blob/main/loss/dice_loss.py"
click node_focal "https://github.com/darthreca/losses-cook/blob/main/loss/focal_loss.py"
click node_topological "https://github.com/darthreca/losses-cook/blob/main/loss/topological_loss.py"
click node_sinkhorn "https://github.com/darthreca/losses-cook/blob/main/loss/topological_loss.py"
click node_comet "https://github.com/darthreca/losses-cook/blob/main/improved_loss.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dataset_configs,node_recipe_files,node_prepared_data,node_collator toneBlue
class node_entry,node_model_configs,node_trainer_config,node_tokenizer,node_base_model,node_lora,node_trainer toneAmber
class node_loss_config,node_loss_mix,node_ce,node_dice,node_focal,node_topological,node_sinkhorn toneMint
class node_comet,node_saved_model toneRose
class node_researcher toneIndigo
```

## Components

### Recipe data

- [Dataset configs](https://github.com/darthreca/losses-cook/tree/main/configs/dataset): `configs/dataset`
- [Recipe source files](https://github.com/darthreca/losses-cook/tree/main/data): `data`
- **Prepared datasets**
- [Custom collator](https://github.com/darthreca/losses-cook/blob/main/improved_loss.py): `improved_loss.py`

### Fine-tuning

- [Training entrypoint](https://github.com/darthreca/losses-cook/blob/main/improved_loss.py): `improved_loss.py`
- [Model configs](https://github.com/darthreca/losses-cook/tree/main/configs/model): `configs/model`
- [Trainer config](https://github.com/darthreca/losses-cook/tree/main/configs/trainer): `configs/trainer`
- [Tokenizer](https://github.com/darthreca/losses-cook/blob/main/improved_loss.py): `improved_loss.py`
- [Causal LM](https://github.com/darthreca/losses-cook/blob/main/improved_loss.py): `improved_loss.py`
- [LoRA adaptation](https://github.com/darthreca/losses-cook/blob/main/improved_loss.py): `improved_loss.py`
- [Custom Trainer](https://github.com/darthreca/losses-cook/blob/main/model/loss_model.py): `model/loss_model.py`

### Loss objectives

- [Loss config](https://github.com/darthreca/losses-cook/blob/main/configs/loss_topological-recipenlg_Qwen3-4B.yaml): `configs/loss_topological-recipenlg_Qwen3-4B.yaml`
- [Weighted loss](https://github.com/darthreca/losses-cook/blob/main/model/loss_model.py): `model/loss_model.py`
- [Cross entropy](https://github.com/darthreca/losses-cook/blob/main/model/loss_model.py): `model/loss_model.py`
- [Generalized Dice](https://github.com/darthreca/losses-cook/blob/main/loss/dice_loss.py): `loss/dice_loss.py`
- [Focal loss](https://github.com/darthreca/losses-cook/blob/main/loss/focal_loss.py): `loss/focal_loss.py`
- [Topological loss](https://github.com/darthreca/losses-cook/blob/main/loss/topological_loss.py): `loss/topological_loss.py`
- [Sinkhorn divergence](https://github.com/darthreca/losses-cook/blob/main/loss/topological_loss.py): `loss/topological_loss.py`

### Tracking and outputs

- [Comet tracking](https://github.com/darthreca/losses-cook/blob/main/improved_loss.py): `improved_loss.py`
- **Fine-tuned model**

### Other components

- **Researcher**

## Connections

- Researcher → Training entrypoint: runs
- Training entrypoint → Dataset configs: loads config
- Training entrypoint → Model configs: loads config
- Training entrypoint → Trainer config: loads config
- Training entrypoint → Loss config: loads config
- Recipe source files → Prepared datasets
- Training entrypoint → Prepared datasets: loads datasets
- Training entrypoint → Tokenizer: loads
- Training entrypoint → Causal LM: loads
- Training entrypoint → LoRA adaptation: adapts model
- Training entrypoint → Custom collator: configures
- Training entrypoint → Custom Trainer: constructs
- Training entrypoint → Comet tracking: optionally initializes
- Custom Trainer → Causal LM: runs forward
- Custom Trainer → Custom collator: uses batches
- Custom Trainer → Weighted loss: computes
- Weighted loss → Cross entropy: optionally applies
- Weighted loss → Generalized Dice: optionally applies
- Weighted loss → Focal loss: optionally applies
- Weighted loss → Topological loss: optionally applies
- Topological loss → Sinkhorn divergence: computes divergence
- Training entrypoint → Fine-tuned model: saves model
- Training entrypoint → Tokenizer: saves tokenizer
