Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Princeton nlp SimPO Post Process Script

From Leeroopedia


Knowledge Sources
Domains Data_Engineering, NLP
Last Updated 2026-02-08 04:30 GMT

Overview

Concrete tool for combining multi-seed generation outputs and filtering identical responses, implemented as a standalone Python script.

Description

The post_process.py script reads all output_*.json files from a generation directory, combines responses per prompt (matching by index across files), and writes a single all_outputs.json file. Prompts where all seed responses are identical are filtered out and counted. This is a Pattern Doc — it documents a user-defined data processing script, not a library API.

Usage

Run after all decode.py seeds have completed. The output is consumed by the reward model annotation script.

Code Reference

Source Location

  • Repository: SimPO
  • File: on_policy_data_gen/post_process.py (Lines 1-45)

Signature

# CLI script (no importable function):
# python on_policy_data_gen/post_process.py --generation_file_dir <dir>

# Internal logic:
# 1. Read all output_*.json files from generation_file_dir
# 2. For each prompt index i:
#    - Collect generated_text from each seed file
#    - If all texts identical: skip (increment num_identical counter)
#    - Else: append {"prompt": str, "all_generated_responses": List[str]}
# 3. Write all_outputs.json

Import

# This is a standalone CLI script, not a library module
# Run directly: python on_policy_data_gen/post_process.py

I/O Contract

Inputs

Name Type Required Description
--generation_file_dir str No Directory with output_*.json files (default: "datasets/gemma2_ultrafeedback")

Outputs

Name Type Description
all_outputs.json JSON file List of {"prompt": str, "all_generated_responses": List[str]} objects (filtered)
Console output str Count of filtered identical-response prompts

Usage Examples

Running Post-Processing

# After generating with seeds 42, 43, 44:
# datasets/gemma2_ultrafeedback/output_42.json
# datasets/gemma2_ultrafeedback/output_43.json
# datasets/gemma2_ultrafeedback/output_44.json

python on_policy_data_gen/post_process.py \
    --generation_file_dir datasets/gemma2_ultrafeedback

# Output:
# Filtered out 150 samples with identical generated responses
# Processed outputs saved to datasets/gemma2_ultrafeedback/all_outputs.json

Output Format

# all_outputs.json structure:
[
    {
        "prompt": "What is machine learning?",
        "all_generated_responses": [
            "Machine learning is a subset of AI...",   # seed 42
            "ML refers to algorithms that learn...",    # seed 43
            "Machine learning involves training...",    # seed 44
        ]
    },
    # ... more prompts
]

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment