Guide to Analyzing Data-Driven Optimize Output
1. Prerequisites: GCS Authentication
Before using the Python tools described in this guide, you must authenticate
your local environment with Google Cloud. The tools need to access the output
files stored in a GCS bucket, which requires proper permissions.
2. Introduction
After a Data-Driven Optimize (Prompt Optimizer) job completes, it writes a
number of files to the specified output path. This can be a Google Cloud
Storage (GCS) bucket or a local directory. This document explains what these
files are and how to use the provided tools to analyze them.
3. Data-Driven Optimize Output Files
The output directory contains several JSON files that capture the results of
the optimization.
optimized_results.json: Contains the single best prompt template found.
The entries in the following pairs of files have corresponding orders, and
their contents can be zipped together for detailed analysis:
- Training Results During Optimization Process:
templates.json: Contains all templates evaluated during the
optimization process, along with their summary metrics.
eval_results.json: Contains detailed, per-row training results on
minibatches during the optimization process. This file is for manual,
in-depth analysis and is not read by the analysis tools.
- Initial and Best Templates on Full Test Set:
test_templates.json: Contains your original prompt and the best
prompt, along with their summary metrics on the full test dataset. The
best prompt is selected based on the metric from training only.
test_eval_results.json: Contains the detailed, per-row evaluation
scores for the original and best prompts on the full test dataset.
This file is for manual, in-depth analysis and is not read by the
analysis tools.
- Eval of All Candidates on Full Test Set:
all_candidates_full_test_templates.json: A list of all prompt
candidates, along with their summary metrics on the full test set.
all_candidates_full_test_eval_results.json: Contains detailed,
per-row evaluation results for each candidate prompt on the full test
set. This file is for manual, in-depth analysis and is not read by the
analysis tools.
- Eval of All Candidates on Full Training Set:
all_candidates_full_train_templates.json: A list of all prompt
candidates, along with their summary metrics on the full training set.
all_candidates_full_train_eval_results.json: Contains detailed,
per-row evaluation results for each candidate prompt on the full
training set. This file is for manual, in-depth analysis and is not
read by the analysis tools.
Controlling Output File Generation
Not all output files are generated by default. Their creation depends on your
job's configuration. This is important because the analysis tools are designed
to handle missing files gracefully, but you may want to enable certain outputs
for a more complete analysis.
Here are the key flags that control which files are generated:
Providing Test Data (test_input_data_path): This parameter is
optional but highly recommended. When you provide a test dataset, the
test_templates.json and test_eval_results.json files are generated,
which provide a final comparison between your original prompt and the
best-optimized prompt. Without a test set, you cannot accurately measure
the generalization performance of your prompts.
eval_all_candidates_on_full_test: This is an optional boolean
flag. When set to True (and a test set is provided), the job will generate
all_candidates_full_test_templates.json and
all_candidates_full_test_eval_results.json. These files allow for a
deep-dive analysis into the performance of every candidate on the test
set. Warning: Enabling this flag can be computationally expensive and
significantly increase the job's runtime.
eval_all_candidates_on_full_train: This is an optional boolean
flag. When set to True, the job will generate
all_candidates_full_train_templates.json and
all_candidates_full_train_eval_results.json. These enable a detailed
comparison of performance on the full training set versus the test set, and
against batch training results, which is crucial for identifying
overfitting. Warning: Enabling this flag can be computationally
expensive and significantly increase the job's runtime.
4. Data File Structure Details
Key Fields:
In _templates.json files (e.g., all_candidates_full_train_templates.json,
test_templates.json):
step: The optimization step where this candidate was generated or
selected.
metrics: This object contains aggregated evaluation results
(e.g., ROUGE_L/mean or exact_match/mean). The specific metric name
will vary depending on the eval_metric configured. It also contains
the "uid" which is an unique identifier consistent across all result
files.
prompt: The prompt string itself.
In _eval_results.json files (e.g., all_candidates_full_train_eval_results.json,
test_eval_results.json):
summary_results: This object contains the aggregated metrics for
the entire evaluation.
metrics_table: This object contains the per-row evaluation
results, useful for detailed debugging.
5. Generating an Analysis Report
The recommended way to analyze your results is to use a multi-step process
involving the tools provided and your reasoning capabilities:
- Analyze Results: First, call
analyze_data_driven_optimize_results(output_path, analysis_data_path="path/to/analysis_data.json")
to process the raw output files. Providing analysis_data_path is highly
recommended as it saves the results into three separate files to avoid
system size limits:
analysis_data.json: Core metadata (config, comparison, best prompt).
analysis_data_metrics.json: Detailed metrics for all candidates
(no prompt text).
analysis_data_prompts.json: Mapping of top candidates' keys to full
prompt texts.
This tool returns a minimal summary object with the paths to the saved
files and the best prompt score.
- Formulate Suggestions: You should then analyze the
analysis_data
summary. Based on the guidelines in the Data-Driven Optimize Tuning Guide,
formulate suggestions for the next run. This should result in a
suggested_config_data dictionary, containing:
"suggested_config": A dictionary of configuration modifications.
"rationale": A string explaining the reasoning behind the
suggestions.
- Generate HTML Report: Finally, call
generate_html_report() passing
either the analysis_data object or the analysis_data_path obtained in
Step 1, along with the suggested_config_data. Passing analysis_data_path
is the most efficient way to handle large analysis results as it
automatically re-joins the metadata, metrics, and prompts from the three
split files.
You can then open the generated HTML file in any web browser to view the full
analysis. For a deeper understanding of how to interpret these results and
iterate, please refer to the Data-Driven Optimize Tuning Guide.
1---2name: 2600-data-driven-optimize-output-analysis-e58bea193description: Guide to Analyzing Data-Driven Optimize Output4---5# Guide to Analyzing Data-Driven Optimize Output67## 1. Prerequisites: GCS Authentication89Before using the Python tools described in this guide, you must authenticate10your local environment with Google Cloud. The tools need to access the output11files stored in a GCS bucket, which requires proper permissions.1213## 2. Introduction1415After a Data-Driven Optimize (Prompt Optimizer) job completes, it writes a16number of files to the specified output path. This can be a Google Cloud17Storage (GCS) bucket or a local directory. This document explains what these18files are and how to use the provided tools to analyze them.1920## 3. Data-Driven Optimize Output Files2122The output directory contains several JSON files that capture the results of23the optimization.2425- **`optimized_results.json`**: Contains the single best prompt template found.2627The entries in the following pairs of files have corresponding orders, and28their contents can be zipped together for detailed analysis:2930- **Training Results During Optimization Process**:31 - **`templates.json`**: Contains all templates evaluated during the32 optimization process, along with their summary metrics.33 - **`eval_results.json`**: Contains detailed, per-row training results on34 minibatches during the optimization process. This file is for manual,35 in-depth analysis and is not read by the analysis tools.36- **Initial and Best Templates on Full Test Set**:37 - **`test_templates.json`**: Contains your original prompt and the best38 prompt, along with their summary metrics on the full test dataset. The39 best prompt is selected based on the metric from training only.40 - **`test_eval_results.json`**: Contains the detailed, per-row evaluation41 scores for the original and best prompts on the full test dataset.42 This file is for manual, in-depth analysis and is not read by the43 analysis tools.44- **Eval of All Candidates on Full Test Set**:45 - **`all_candidates_full_test_templates.json`**: A list of *all* prompt46 candidates, along with their summary metrics on the full test set.47 - **`all_candidates_full_test_eval_results.json`**: Contains detailed,48 per-row evaluation results for each candidate prompt on the full test49 set. This file is for manual, in-depth analysis and is not read by the50 analysis tools.51- **Eval of All Candidates on Full Training Set**:52 - **`all_candidates_full_train_templates.json`**: A list of *all* prompt53 candidates, along with their summary metrics on the full training set.54 - **`all_candidates_full_train_eval_results.json`**: Contains detailed,55 per-row evaluation results for each candidate prompt on the full56 training set. This file is for manual, in-depth analysis and is not57 read by the analysis tools.5859### Controlling Output File Generation6061Not all output files are generated by default. Their creation depends on your62job's configuration. This is important because the analysis tools are designed63to handle missing files gracefully, but you may want to enable certain outputs64for a more complete analysis.6566Here are the key flags that control which files are generated:6768- **Providing Test Data (`test_input_data_path`)**: This parameter is69 **optional but highly recommended**. When you provide a test dataset, the70 `test_templates.json` and `test_eval_results.json` files are generated,71 which provide a final comparison between your original prompt and the72 best-optimized prompt. Without a test set, you cannot accurately measure73 the generalization performance of your prompts.7475- **`eval_all_candidates_on_full_test`**: This is an **optional** boolean76 flag. When set to `True` (and a test set is provided), the job will generate77 `all_candidates_full_test_templates.json` and78 `all_candidates_full_test_eval_results.json`. These files allow for a79 deep-dive analysis into the performance of *every* candidate on the test80 set. **Warning:** Enabling this flag can be computationally expensive and81 significantly increase the job's runtime.8283- **`eval_all_candidates_on_full_train`**: This is an **optional** boolean84 flag. When set to `True`, the job will generate85 `all_candidates_full_train_templates.json` and86 `all_candidates_full_train_eval_results.json`. These enable a detailed87 comparison of performance on the full training set versus the test set, and88 against batch training results, which is crucial for identifying89 overfitting. **Warning:** Enabling this flag can be computationally90 expensive and significantly increase the job's runtime.9192## 4. Data File Structure Details9394**Key Fields:**9596- In `_templates.json` files (e.g., `all_candidates_full_train_templates.json`,97 `test_templates.json`):98 - **`step`**: The optimization step where this candidate was generated or99 selected.100 - **`metrics`**: This object contains aggregated evaluation results101 (e.g., `ROUGE_L/mean` or `exact_match/mean`). The specific metric name102 will vary depending on the `eval_metric` configured. It also contains103 the "uid" which is an unique identifier consistent across all result104 files.105 - **`prompt`**: The prompt string itself.106107- In `_eval_results.json` files (e.g., `all_candidates_full_train_eval_results.json`,108 `test_eval_results.json`):109 - **`summary_results`**: This object contains the aggregated metrics for110 the entire evaluation.111 - **`metrics_table`**: This object contains the per-row evaluation112 results, useful for detailed debugging.113114## 5. Generating an Analysis Report115116The recommended way to analyze your results is to use a multi-step process117involving the tools provided and your reasoning capabilities:1181191. **Analyze Results:** First, call120 `analyze_data_driven_optimize_results(output_path, analysis_data_path="path/to/analysis_data.json")`121 to process the raw output files. Providing `analysis_data_path` is highly122 recommended as it saves the results into three separate files to avoid123 system size limits:124 - `analysis_data.json`: Core metadata (config, comparison, best prompt).125 - `analysis_data_metrics.json`: Detailed metrics for all candidates126 (no prompt text).127 - `analysis_data_prompts.json`: Mapping of top candidates' keys to full128 prompt texts.129 This tool returns a **minimal summary object** with the paths to the saved130 files and the best prompt score.1312. **Formulate Suggestions:** You should then analyze the `analysis_data`132 summary. Based on the guidelines in the **Data-Driven Optimize Tuning Guide**,133 formulate suggestions for the next run. This should result in a134 `suggested_config_data` dictionary, containing:135 - `"suggested_config"`: A dictionary of configuration modifications.136 - `"rationale"`: A string explaining the reasoning behind the137 suggestions.1383. **Generate HTML Report:** Finally, call `generate_html_report()` passing139 either the `analysis_data` object or the `analysis_data_path` obtained in140 Step 1, along with the `suggested_config_data`. Passing `analysis_data_path`141 is the most efficient way to handle large analysis results as it142 automatically re-joins the metadata, metrics, and prompts from the three143 split files.144145You can then open the generated HTML file in any web browser to view the full146analysis. For a deeper understanding of how to interpret these results and147iterate, please refer to the Data-Driven Optimize Tuning Guide.