Python
Enhance documentation for input/output modes
0b693149feb5a
diff --git a/src/evaluate_with_existing_criteria.py b/src/evaluate_with_existing_criteria.pyindex dfc8957..04cf615 100644--- a/src/evaluate_with_existing_criteria.py+++ b/src/evaluate_with_existing_criteria.py@@ -1,4 +1,4 @@-from __future__ import annotations+from __future__ import annotationsimport jsonimport osimport re@@ -26,18 +26,107 @@ from tqdm import tqdmcurrent_dir = os.path.dirname(os.path.abspath(__file__))+# =============================================================================+# HOW TO USE THE INPUT/OUTPUT MODES -- READ THIS BEFORE CHANGING CONFIG+#+# This script has TWO input modes, controlled by USE_FOLDER_MODE:+#+# -------------------------------------------------------------------------+# 1) SINGLE-FILE MODE (USE_FOLDER_MODE = False)+# Best for evaluating exactly ONE model result.+#+# INPUT:+# - The script reads exactly ONE Excel file: INPUT_XLSX.+# - In this repository the default file is:+# src/Cognivia_response.xlsx+# (that file is generated by src/fine-tuned_model_generate.py).+# - To score a different single file, just change INPUT_XLSX below.+#+# OUTPUT:+# - Results are written to OUTPUT_XLSX (default):+# src/evaluation_with_existing_criteria.xlsx+#+# Example single-file setup:+# 1) Put the model output at: src/Cognivia_response.xlsx+# 2) Run: python src/evaluate_with_existing_criteria.py+#+# -------------------------------------------------------------------------+# 2) FOLDER / MULTI-MODEL MODE (USE_FOLDER_MODE = True)+# Best for comparing several models at once.+#+# INPUT:+# - The script scans EVERY *.xlsx inside INPUT_DIR.+# - The file name (without .xlsx) is used as the model name, so:+# modelA.xlsx -> model "modelA"+# modelB.xlsx -> model "modelB"+# - Default input folder:+# src/baseline/+# - Steps to use this mode:+# a) Create the folder first: src/baseline/+# b) Put one Excel file per model inside it, e.g.:+# src/baseline/modelA.xlsx+# src/baseline/modelB.xlsx+# (every file must contain the columns listed under+# "Input Excel column names" below, e.g. user1 / assistant1)+# c) Run the script.+#+# OUTPUT:+# - Each model gets its own result file:+# src/evaluation_with_existing_criteria/<model>_eval.xlsx+# - When >=2 models are present, a comparison summary is also written:+# src/evaluation_with_existing_criteria/all_models_compare.xlsx+#+# -------------------------------------------------------------------------+# IMPORTANT PITFALL ABOUT INPUT (the most common mistake):+# * Even when USE_FOLDER_MODE = True, folder mode ONLY actually runs if+# INPUT_DIR exists AND contains at least one *.xlsx file.+# * If INPUT_DIR is missing or empty, the code silently falls back to+# SINGLE-FILE mode and reads INPUT_XLSX instead.+# * Therefore:+# - To really enable FOLDER mode you MUST create INPUT_DIR first and put+# the model .xlsx files inside it.+# - To use SINGLE-FILE mode just keep USE_FOLDER_MODE = False. You do NOT+# need to create the baseline folder at all.+#+# -------------------------------------------------------------------------+# OUTPUT PATH SUMMARY:+# * USE_FOLDER_MODE = False -> results go to OUTPUT_XLSX.+# * USE_FOLDER_MODE = True -> results go to+# OUTPUT_DIR/<model_name>_eval.xlsx+# (+ all_models_compare.xlsx when >=2 models).+# * NOTE: if USE_FOLDER_MODE = True but INPUT_DIR is missing, only the INPUT+# falls back to the single file; the OUTPUT is still written under+# OUTPUT_DIR. If you want BOTH input and output to stay single-file, keep+# USE_FOLDER_MODE = False.+# =============================================================================+# --- Single file mode ---+# Input file to score (used when USE_FOLDER_MODE = False).+# Point this to any single model-result Excel file to evaluate it.INPUT_XLSX = os.path.join(current_dir, "Cognivia_response.xlsx")-OUTPUT_XLSX = os.path.join(current_dir,"evaluation_with_existing_criteria.xlsx")++# Output file for single-file mode. Scores are written here.+OUTPUT_XLSX = os.path.join(current_dir, "evaluation_with_existing_criteria.xlsx")# --- Multi-model folder mode ---+# Input folder for folder mode: every *.xlsx inside it is treated as one model's+# output. Example: create src/baseline/ and put modelA.xlsx, modelB.xlsx there.INPUT_DIR = os.path.join(current_dir, "baseline")++# Output folder for folder mode: each model gets <model>_eval.xlsx here.OUTPUT_DIR = os.path.join(current_dir, "evaluation_with_existing_criteria")-OUTPUT_COMPARE_XLSX = os.path.join(OUTPUT_DIR,"all_models_compare.xlsx")-USE_FOLDER_MODE = True-# When folder mode has >=2 models, use same-Thought relative scoring (recommended).-# Absolute single-answer scoring collapses among strong models.+# Comparison summary file (generated when >=2 models are evaluated).+OUTPUT_COMPARE_XLSX = os.path.join(OUTPUT_DIR, "all_models_compare.xlsx")++# Master switch: False = single-file mode; True = folder mode.+USE_FOLDER_MODE = False++# Folder mode only: when INPUT_DIR contains >=2 models:+# True = relative cross-model scoring on the same Thought (recommended,+# it distinguishes strong models better);+# False = absolute scoring for each model independently.+# In single-file mode this flag has no effect (always absolute scoring).USE_RELATIVE_MULTI_MODEL = TrueAPI_KEY_ENV = "YOUR_SiliconFlow_API"@@ -52,9 +141,16 @@ TIMEOUT = 180.0SHEET = 0SLEEP_BETWEEN = 0.15-COL_THOUGHT = "Thought"-COL_ANSWER = "Rational Response"-COL_CONTEXT = "context"+# --- Input Excel column names ---+# These must match the columns of the Excel file(s) you are scoring.+# In this repository the default file comes from fine-tuned_model_generate.py:+# user1 = the user question / Thought+# assistant1 = the model-generated Rational Response+# If your input files use different column names, edit these values so the+# script can find the columns automatically.+COL_THOUGHT = "user1" # column holding the question / Thought+COL_ANSWER = "assistant1" # column holding the model answer / Rational Response+COL_CONTEXT = "context" # optional context column; if missing it is left emptySYSTEM_PROMPT = """You are a strict expert rater for CBT counseling responses.@@ -624,6 +720,12 @@ def print_summary(summary: dict[str, Any], title: str = "") -> None:def list_input_files() -> list[Path]:+ # Input mode is decided here:+ # 1) USE_FOLDER_MODE=True AND INPUT_DIR exists -> folder mode+ # (reads every *.xlsx under INPUT_DIR; create src/baseline/ and put the+ # model files there to use this mode).+ # 2) Otherwise -> single-file mode (reads INPUT_XLSX; change INPUT_XLSX to+ # point at the single Excel file you want to score).if USE_FOLDER_MODE and INPUT_DIR and Path(INPUT_DIR).is_dir():files = sorted(Path(INPUT_DIR).glob("*.xlsx"))files = [f for f in files if not f.name.startswith("~$")]