How noahho/caafe works
1. What this repository is
CAAFE is a Python package for semi-automated feature engineering on tabular datasets. The core architecture is a loop that takes a dataset plus a natural-language description, asks an LLM to propose feature code, executes the code under restrictions, and keeps only features that improve downstream model performance.
2. Main public entry point
The main user-facing object is CAAFEClassifier in caafe/caafe.py, exposed through the package root. It behaves like a classifier wrapper: users provide a base sklearn-compatible model, an LLM choice, and iteration count; CAAFE then manages feature generation and model fitting around that estimator.
3. Feature-engineering pipeline
The central data flow is:
raw pandas data → preprocessing/encoding → prompt construction from dataset description → LLM-generated feature code → code execution → candidate feature matrix → cross-validated evaluation → accepted features appended to the training set.
This loop is iterative, so the system can refine feature proposals using feedback from prior verification results.
4. LLM code generation boundary
caafe/run_llm_code.py is the execution boundary for model-generated code. The README makes clear that CAAFE does not trust arbitrary code: generated Python is syntactically checked and constrained by a whitelist of allowed operations. This is the main safety boundary between untrusted LLM output and the Python runtime.
5. Classifier abstraction boundary
caafe/sklearn_wrapper.py adapts downstream estimators to the CAAFE workflow. The downstream model must be fast and sklearn-like because it is repeatedly trained during feature verification. The repo explicitly supports models such as TabPFNClassifier and RandomForestClassifier, but the architectural requirement is “fit/predict like sklearn.”
6. Data preprocessing and feature handling
caafe/preprocessing.py and caafe/data.py handle dataset preparation and likely dataset-specific utilities needed before prompting or model training. These modules form the boundary between raw tabular inputs and the feature-engineering loop, ensuring the data can be presented consistently to the LLM and the verifier.
7. Evaluation subsystem
caafe/evaluate.py, caafe/caafe_evaluate.py, caafe/metrics.py, and caafe/plotting.py support benchmarking and reporting. This part of the repository is separate from the interactive classifier workflow and is used to compare generated features, run experiments across datasets, compute metrics, and visualize results.
8. Baselines and comparison methods
caafe/feature_extension_baselines.py indicates a comparison layer for non-LLM feature engineering baselines. Architecturally, this keeps the repo from being only an LLM demo; it also supports method comparison for experiments and paper reproduction.
9. Repository data assets
The data/ directory contains the experimental corpus: human-written dataset descriptions, many prompt/code pairs under generated_code/, and evaluations.zip. These assets are not runtime dependencies for the core API, but they are important for reproducing experiments, inspecting generated feature proposals, and evaluating results across multiple datasets.
10. Experiment scripts
scripts/generate_features_script.py and scripts/run_classifiers_script.py suggest a batch-oriented workflow for reproducing the paper’s experiments. One script likely generates feature code over datasets; the other runs downstream classifiers on the resulting engineered data.
11. Testing and package boundary
The repo has a small test surface in tests/test_sklearn_wrapper.py, which points to sklearn_wrapper.py as a critical integration boundary. setup.py and the package layout indicate this is a distributable Python library rather than a standalone application.
12. External services and runtime dependencies
The main external runtime dependency is an LLM endpoint, such as OpenAI GPT-4/GPT-3.5, used for feature-code generation. The architecture also relies on the Python scientific stack and sklearn-compatible estimators for repeated verification, making the whole system centered on pandas/tabular ML rather than web or service infrastructure.
Main entry points: caafe.py Feature loop · caafe_evaluate.py CAAFE eval · run_llm_code.py LLM code run · sklearn_wrapper.py Model wrapper
Components 18
Core package
Public API and the feature-engineering loop
- Package API · Exports the library entry point
caafe/__init__.py - CAAFEClassifier · User-facing estimator that orchestrates feature generation and fitting
caafe/caafe.py - Feature loop · Iterative generate-evaluate-accept cycle
caafe/caafe.py - Preprocessing · Cleans and encodes raw data for prompting and training
caafe/preprocessing.py - Data utils · Dataset-specific utilities and metadata handling
caafe/data.py - Prompting · Constructs prompts from dataset descriptions and prior feedback
caafe/caafe.py - LLM code run · Validates and executes model-generated Python under restrictions
caafe/run_llm_code.py - Model wrapper · Adapts downstream estimators to repeated fit/predict verification
caafe/sklearn_wrapper.py
Evaluation
Benchmarking, metrics, and plots
- Eval entry · Runs experiments over datasets and models
caafe/evaluate.py - CAAFE eval · Evaluation workflow specific to CAAFE comparisons
caafe/caafe_evaluate.py - Metrics · Computes performance and comparison metrics
caafe/metrics.py - Plots · Visualizes evaluation results and comparisons
caafe/plotting.py - Baselines · Non-LLM feature engineering baselines for experiments
caafe/feature_extension_baselines.py
Data assets
Stored prompts, generated code, and dataset descriptions
- Descriptions · Human-written dataset summaries used in prompts
data/dataset_descriptions - Generated code · Stored prompt/code pairs from feature generation runs
data/generated_code - Eval archive · Packaged experimental outputs and results
data/evaluations.zip
Scripts
Batch workflows for reproducing experiments
- Generate features · Reproduces feature-generation runs across datasets
scripts/generate_features_script.py - Run classifiers · Runs downstream classifiers on engineered features
scripts/run_classifiers_script.py
Connections 18
- Package API → CAAFEClassifier: exports · Package root exposes the main classifier wrapper
- CAAFEClassifier → Feature loop: drives · Wrapper coordinates the iterative feature-engineering loop
- Feature loop → Preprocessing: prep · Raw tabular data is normalized before prompting and training
- Feature loop → Data utils: reads · Dataset metadata and helpers feed the loop
- Feature loop → Prompting: builds · Creates prompts from data description and feedback
- Prompting → Descriptions: uses · Dataset descriptions ground the prompt context
- Prompting → LLM code run: requests code · Prompted model output becomes candidate feature code
- LLM code run → Generated code: stores · Prompt/code artifacts are preserved for inspection and reuse
- LLM code run → Model wrapper: executes on · Generated features are verified with sklearn-like estimators
- Model wrapper → Feature loop: scores · Downstream performance determines whether features are accepted
- Feature loop → Preprocessing: appends features · Accepted features are merged into the training matrix
- Feature loop → Eval entry: benchmarks · Feature sets can be evaluated in experiment mode
- Eval entry → CAAFE eval: coordinates · Evaluation entry point delegates to CAAFE-specific harnesses
- CAAFE eval → Metrics: computes · Experimental runs produce metrics
- CAAFE eval → Plots: visualizes · Results are summarized in plots
- CAAFE eval → Baselines: compares · LLM-generated features are measured against baselines
- Generate features → Generated code: produces · Batch generation writes prompt/code pairs
- Run classifiers → Eval archive: reads results · Classifier batch runs consume stored evaluation outputs