refactor: patchディレクトリを廃止し差分をdata/に統合

#4
by YUGOROU - opened
README.md ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # EQ-Bench3 日本語化パッチ (teememo-eq-bench-ja)
2
+
3
+ [EQ-Bench3](https://github.com/EQ-bench/eqbench3) を日本語で評価するための翻訳データと差分パッチのセットです。
4
+ **TeenEmo** (未踏ジュニア 2026 採択申請プロジェクト) のモデル評価基盤として作成しました。
5
+
6
+ ---
7
+
8
+ ## リポジトリ構成
9
+
10
+ ```
11
+ teememo-eq-bench-ja/
12
+ ├── apply_patch.sh # ← パッチ適用スクリプト(これを実行するだけ)
13
+ └── data/
14
+ ├── benchmark.patch # core/benchmark.py 差分 (Fix-B1)
15
+ ├── conversation.patch # core/conversation.py 差分 (Fix-C1)
16
+
17
+ ├── scenario_prompts_ja.txt # シナリオプロンプト (日本語)
18
+ ├── scenario_prompts_en.txt # シナリオプロンプト (英語・参照用)
19
+ ├── scenario_notes_ja.txt
20
+ ├── scenario_notes_en.txt
21
+ ├── scenario_master_prompt_ja.txt
22
+ ├── scenario_master_prompt_en.txt
23
+ ├── scenario_master_prompt_message_drafting_ja.txt
24
+ ├── scenario_master_prompt_message_drafting_en.txt
25
+ ├── scenario_master_prompt_analysis_ja.txt
26
+ ├── scenario_master_prompt_analysis_en.txt
27
+ ├── rubric_scoring_prompt_ja.txt
28
+ ├── rubric_scoring_prompt_en.txt
29
+ ├── rubric_scoring_prompt_analysis_ja.txt
30
+ ├── rubric_scoring_prompt_analysis_en.txt
31
+ ├── rubric_scoring_criteria_ja.txt # ※ファイル内は英語キーのまま
32
+ ├── rubric_scoring_criteria_en.txt
33
+ ├── rubric_scoring_criteria_analysis_ja.txt
34
+ ├── rubric_scoring_criteria_analysis_en.txt
35
+ ├── pairwise_prompt_eqbench3_ja.txt
36
+ ├── pairwise_prompt_eqbench3_en.txt
37
+ ├── pairwise_prompt_eqbench3_analysis_ja.txt
38
+ ├── pairwise_prompt_eqbench3_analysis_en.txt
39
+ ├── debrief_prompt_ja.txt
40
+ └── debrief_prompt_en.txt
41
+ ```
42
+
43
+ ---
44
+
45
+ ## クイックスタート
46
+
47
+ ```bash
48
+ # 1. EQ-Bench3 本体をクローン
49
+ git clone --depth=1 https://github.com/EQ-bench/eqbench3.git
50
+ cd eqbench3
51
+
52
+ # 2. このリポジトリをクローン
53
+ git clone https://huggingface.co/datasets/YUGOROU/teememo-eq-bench-ja ../teememo-eq-bench-ja
54
+
55
+ # 3. パッチを一括適用
56
+ bash ../teememo-eq-bench-ja/apply_patch.sh
57
+
58
+ # 4. 評価実行
59
+ python eqbench3.py \
60
+ --test-model <your_model> \
61
+ --judge-model openai/gpt-oss-120b \
62
+ --no-elo \
63
+ --save-interval 1
64
+ ```
65
+
66
+ ---
67
+
68
+ ## 変更内容の詳細
69
+
70
+ ### [Fix-D1] 日本語テキストファイルの配置
71
+
72
+ `data/*_ja.txt` を EQ-Bench3 の `data/` 配下の対応するベースファイル名へコピーします。
73
+ 元の英語ファイルは `.en.bak` として自動バックアップされます。
74
+
75
+ | コピー元 (`data/`) | コピー先 (`eqbench3/data/`) |
76
+ |---|---|
77
+ | `scenario_prompts_ja.txt` | `scenario_prompts.txt` |
78
+ | `rubric_scoring_prompt_ja.txt` | `rubric_scoring_prompt.txt` |
79
+ | `pairwise_prompt_eqbench3_ja.txt` | `pairwise_prompt_eqbench3.txt` |
80
+ | … (全12ファイル) | … |
81
+
82
+ > **注意**: `rubric_scoring_criteria_ja.txt` の**キー名は英語のまま**です (`demonstrated_empathy` など)。
83
+ > スコアリングロジックが英語キーで照合するため、値の説明文のみ日本語化しています。
84
+
85
+ ### [Fix-B1] `core/benchmark.py` — 動的 criteria 読み込み
86
+
87
+ `STANDARD_ALLOWED_RUBRIC_CRITERIA` のハードコードを除去し、`STANDARD_RUBRIC_CRITERIA_FILE` から動的に読み込むよう変更します。
88
+ 日本語版でも英語キーが一致するため、スコアが正しく集計されます。
89
+ 差分: [`data/benchmark.patch`](data/benchmark.patch)
90
+
91
+ ### [Fix-C1] `core/conversation.py` — 日本語セクションヘッダー対応
92
+
93
+ モデルが日本語でセクションヘッダーを返した場合のフォールバック正規表現を追加します。
94
+ 英語ヘッダー (`# My response` 等) が第一優先で、`master_prompt_ja.txt` も英語見出しを使用しています。
95
+ 差分: [`data/conversation.patch`](data/conversation.patch)
96
+
97
+ ---
98
+
99
+ ## 翻訳方針
100
+
101
+ - **シナリオプロンプト**: 文化的文脈を日本の高校生・大学生向けに自然に翻訳
102
+ - **プレースホルダー** (`{scenario_prompt}` 等): 変更なし
103
+ - **評価基準キー**: 英語キーを維持(スコアリングロジックとの互換性のため)
104
+ - **評価基準の説明文**: 日本語に翻訳
105
+
106
+ ---
107
+
108
+ ## 動作確認環境
109
+
110
+ - EQ-Bench3 `HEAD` (2025年5月時点)
111
+ - Judge model: `openai/gpt-oss-120b` (novita プロバイダー経由)
112
+ - Test model: `YUGOROU/TeenEmo-LFM2.5-1.2B-DPO` (LoRA adapter)
113
+ - GPU: NVIDIA RTX 4090 on Vast.ai
114
+
115
+ ---
116
+
117
+ ## ライセンス
118
+
119
+ 翻訳データは [EQ-Bench3](https://github.com/EQ-bench/eqbench3) のライセンスに準拠します。
120
+ TeenEmo プロジェクト固有の追加コードは MIT ライセンスで提供します。
patch/apply_patch.sh → apply_patch.sh RENAMED
@@ -1,16 +1,18 @@
1
  #!/usr/bin/env bash
2
  # =============================================================================
3
- # apply_patch.sh — EQ-Bench3 日本語パッチ適用スクリプト
4
  #
5
  # 使用方法:
6
  # git clone --depth=1 https://github.com/EQ-bench/eqbench3.git
7
  # cd eqbench3
8
  # bash /path/to/apply_patch.sh
9
  #
10
- # 修正れる問題:
11
- # [Fix-D1] data/ 以下の全日本語ファイルを配置
12
- # [Fix-D2] benchmark.py — STANDARD_ALLOWED_RUBRIC_CRITERIA を動的読込みに変更
13
- # [Fix-D3] conversation.py — セクション正規表現に日本語見出し追加
 
 
14
  # =============================================================================
15
 
16
  set -euo pipefail
@@ -70,7 +72,6 @@ for pair in "${FILES[@]}"; do
70
  continue
71
  fi
72
 
73
- # 英語版バックアップ(初回のみ)
74
  if [ -f "${DEST_PATH}" ] && [ ! -f "${DEST_PATH}.en.bak" ]; then
75
  cp "${DEST_PATH}" "${DEST_PATH}.en.bak"
76
  echo " [BACKUP] ${DEST_FILE}.en.bak"
@@ -82,73 +83,50 @@ for pair in "${FILES[@]}"; do
82
  done
83
 
84
  echo " 配置完了: ${OK_COUNT}/${#FILES[@]} ファイル"
85
- if [ "${FAIL_COUNT}" -gt 0 ]; then
86
- echo " [WARN] ${FAIL_COUNT} ファイルが見つかりませんでした"
87
- fi
88
 
89
- # ── [Fix-D2] benchmark.py パッチ ──────────────────────────
90
  echo ""
91
- echo "[Fix-D2] core/benchmark.py にパッチ適用中..."
92
- python3 "${SCRIPT_DIR}/patch_benchmark.py"
 
 
 
 
 
 
93
 
94
- # ── [Fix-D3] conversation.py パッチ ───────────────────────
95
  echo ""
96
- echo "[Fix-D3] core/conversation.py にパッチ適用中..."
97
- python3 "${SCRIPT_DIR}/patch_conversation.py"
 
 
 
 
 
 
98
 
99
  # ── 検証 ──────────────────────────────────────────────────
100
  echo ""
101
  echo "[verify] パッチ適用を検証中..."
102
-
103
  ERRORS=0
104
 
105
- # scenario_master_prompt.txt に {scenario_prompt} が含まれること
106
- if grep -q "{scenario_prompt}" "${DATA_DEST}/scenario_master_prompt.txt"; then
107
- echo " [OK] scenario_master_prompt.txt{scenario_prompt} プレースホルダー確認"
108
- else
109
- echo " [ERROR] scenario_master_prompt.txt {scenario_prompt} がありません"
110
- ERRORS=$((ERRORS + 1))
111
- fi
112
-
113
- # scenario_master_prompt_message_drafting.txt に {scenario_prompt} が含まれること
114
- if grep -q "{scenario_prompt}" "${DATA_DEST}/scenario_master_prompt_message_drafting.txt"; then
115
- echo " [OK] scenario_master_prompt_message_drafting.txt — {scenario_prompt} プレースホルダー確認"
116
- else
117
- echo " [ERROR] scenario_master_prompt_message_drafting.txt に {scenario_prompt} がありません"
118
- ERRORS=$((ERRORS + 1))
119
- fi
120
-
121
- # rubric_scoring_criteria.txt が英語キーであること
122
- if grep -q "demonstrated_empathy" "${DATA_DEST}/rubric_scoring_criteria.txt"; then
123
- echo " [OK] rubric_scoring_criteria.txt — 英語キー確認"
124
- else
125
- echo " [ERROR] rubric_scoring_criteria.txt に英語キーがありません"
126
- ERRORS=$((ERRORS + 1))
127
- fi
128
-
129
- # pairwise_prompt_eqbench3.txt に {conversation_history_A} が含まれること
130
- if grep -q "{conversation_history_A}" "${DATA_DEST}/pairwise_prompt_eqbench3.txt"; then
131
- echo " [OK] pairwise_prompt_eqbench3.txt — {conversation_history_A} プレースホルダー確認"
132
- else
133
- echo " [ERROR] pairwise_prompt_eqbench3.txt に {conversation_history_A} がありません"
134
- ERRORS=$((ERRORS + 1))
135
- fi
136
-
137
- # benchmark.py に JA-PATCH が適用されていること
138
- if grep -q "JA-PATCH Fix-B1" "${EQBENCH_DIR}/core/benchmark.py"; then
139
- echo " [OK] core/benchmark.py — Fix-B1 パッチ確認"
140
- else
141
- echo " [ERROR] core/benchmark.py — Fix-B1 パッチが適用されていません"
142
- ERRORS=$((ERRORS + 1))
143
- fi
144
 
145
- # conversation.py に JA-PATCH が適用されていること
146
- if grep -q "JA-PATCH Fix-C1" "${EQBENCH_DIR}/core/conversation.py"; then
147
- echo " [OK] core/conversation.py — Fix-C1 パッチ確認"
148
- else
149
- echo " [ERROR] core/conversation.pyFix-C1 パッチが適用されていません"
150
- ERRORS=$((ERRORS + 1))
151
- fi
152
 
153
  echo ""
154
  if [ "${ERRORS}" -eq 0 ]; then
@@ -157,14 +135,12 @@ if [ "${ERRORS}" -eq 0 ]; then
157
  echo "======================================================"
158
  else
159
  echo "======================================================"
160
- echo " ❌ パッチ適用完了 — ${ERRORS} 件のエラーが発生しました"
161
  echo "======================================================"
162
  exit 1
163
  fi
164
 
165
  echo ""
166
  echo "【次のステップ】"
167
- echo " 1. vLLM で受験者モデルを起動: serve_test_vast.sh"
168
- echo " 2. setup_eqbench_vast.sh でセットアップ"
169
- echo " 3. python eqbench3.py --test-model <lora_name> --judge-model openai/gpt-oss-120b --no-elo --save-interval 1"
170
  echo ""
 
1
  #!/usr/bin/env bash
2
  # =============================================================================
3
+ # apply_patch.sh — EQ-Bench3 日本語パッチ適用スクリプト
4
  #
5
  # 使用方法:
6
  # git clone --depth=1 https://github.com/EQ-bench/eqbench3.git
7
  # cd eqbench3
8
  # bash /path/to/apply_patch.sh
9
  #
10
+ # このスクリプトは data/ と同じディレクトリに置いて実行してくだい。
11
+ #
12
+ # 行う変更:
13
+ # [Fix-D1] data/ 以下の全日本語ファイル配置(英語版は .en.bak に退避)
14
+ # [Fix-B1] core/benchmark.py — STANDARD_ALLOWED_RUBRIC_CRITERIA を動的読込みに変更
15
+ # [Fix-C1] core/conversation.py — セクション正規表現に日本語見出しを追加
16
  # =============================================================================
17
 
18
  set -euo pipefail
 
72
  continue
73
  fi
74
 
 
75
  if [ -f "${DEST_PATH}" ] && [ ! -f "${DEST_PATH}.en.bak" ]; then
76
  cp "${DEST_PATH}" "${DEST_PATH}.en.bak"
77
  echo " [BACKUP] ${DEST_FILE}.en.bak"
 
83
  done
84
 
85
  echo " 配置完了: ${OK_COUNT}/${#FILES[@]} ファイル"
86
+ [ "${FAIL_COUNT}" -gt 0 ] && echo " [WARN] ${FAIL_COUNT} ファイルが見つかりませんでした"
 
 
87
 
88
+ # ── [Fix-B1] benchmark.py パッチ ──────────────────────────
89
  echo ""
90
+ echo "[Fix-B1] core/benchmark.py にパッチ適用中..."
91
+ if grep -q "\[JA-PATCH Fix-B1\]" "${EQBENCH_DIR}/core/benchmark.py"; then
92
+ echo " [SKIP] Fix-B1 は既に適用済みです"
93
+ else
94
+ cp "${EQBENCH_DIR}/core/benchmark.py" "${EQBENCH_DIR}/core/benchmark.py.orig"
95
+ patch -p1 < "${SCRIPT_DIR}/data/benchmark.patch"
96
+ echo " [OK] Fix-B1 適用完了"
97
+ fi
98
 
99
+ # ── [Fix-C1] conversation.py パッチ ───────────────────────
100
  echo ""
101
+ echo "[Fix-C1] core/conversation.py にパッチ適用中..."
102
+ if grep -q "\[JA-PATCH Fix-C1\]" "${EQBENCH_DIR}/core/conversation.py"; then
103
+ echo " [SKIP] Fix-C1 は既に適用済みです"
104
+ else
105
+ cp "${EQBENCH_DIR}/core/conversation.py" "${EQBENCH_DIR}/core/conversation.py.orig"
106
+ patch -p1 < "${SCRIPT_DIR}/data/conversation.patch"
107
+ echo " [OK] Fix-C1 適用完了"
108
+ fi
109
 
110
  # ── 検証 ──────────────────────────────────────────────────
111
  echo ""
112
  echo "[verify] パッチ適用を検証中..."
 
113
  ERRORS=0
114
 
115
+ _check() {
116
+ if grep -q "$1" "$2"; then
117
+ echo " [OK] $(basename $2) $3"
118
+ else
119
+ echo " [ERROR] $(basename $2) $3"
120
+ ERRORS=$((ERRORS + 1))
121
+ fi
122
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
+ _check "{scenario_prompt}" "${DATA_DEST}/scenario_master_prompt.txt" "{scenario_prompt} プレースホルダー"
125
+ _check "{scenario_prompt}" "${DATA_DEST}/scenario_master_prompt_message_drafting.txt" "{scenario_prompt} プレースホルダー"
126
+ _check "demonstrated_empathy" "${DATA_DEST}/rubric_scoring_criteria.txt" "英語キー"
127
+ _check "{conversation_history_A}" "${DATA_DEST}/pairwise_prompt_eqbench3.txt" "{conversation_history_A} プレースホルダー"
128
+ _check "JA-PATCH Fix-B1" "${EQBENCH_DIR}/core/benchmark.py" "Fix-B1 パッチ確認"
129
+ _check "JA-PATCH Fix-C1" "${EQBENCH_DIR}/core/conversation.py" "Fix-C1 パッチ確認"
 
130
 
131
  echo ""
132
  if [ "${ERRORS}" -eq 0 ]; then
 
135
  echo "======================================================"
136
  else
137
  echo "======================================================"
138
+ echo " ❌ ${ERRORS} 件のエラーが発生しました"
139
  echo "======================================================"
140
  exit 1
141
  fi
142
 
143
  echo ""
144
  echo "【次のステップ】"
145
+ echo " python eqbench3.py --test-model <model> --judge-model openai/gpt-oss-120b --no-elo --save-interval 1"
 
 
146
  echo ""
data/benchmark.patch ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --- a/core/benchmark.py
2
+ +++ b/core/benchmark.py
3
+ @@ -207,10 +207,15 @@
4
+ Considers different criteria sets for standard/drafting vs analysis tasks.
5
+ Averages scores for allowed criteria within a task first, then averages these task scores.
6
+ Returns (average_score, error_message).
7
+ """
8
+ - # Define the specific criteria to include for standard/drafting tasks
9
+ - STANDARD_ALLOWED_RUBRIC_CRITERIA = {
10
+ + # Define the specific criteria to include for standard/drafting tasks.
11
+ + # [JA-PATCH Fix-B1] Load from file instead of hardcoding so that the allowed
12
+ + # set always matches whatever keys are in the criteria file (English keys when
13
+ + # running the Japanese edition).
14
+ + # The scoring subset intentionally excludes style markers (boundary_setting,
15
+ + # moralising, sycophantic, etc.) – we keep only the EQ-positive criteria.
16
+ + _EQ_POSITIVE_CRITERIA = {
17
+ "demonstrated_empathy",
18
+ "pragmatic_ei",
19
+ "depth_of_insight",
20
+ "social_dexterity",
21
+ @@ -218,10 +223,31 @@
22
+ "message_tailoring",
23
+ "theory_of_mind",
24
+ "subtext_identification",
25
+ "intellectual_grounding",
26
+ - "correctness"
27
+ + "correctness",
28
+ }
29
+ + try:
30
+ + with open(C.STANDARD_RUBRIC_CRITERIA_FILE, 'r', encoding='utf-8') as _f:
31
+ + _file_criteria = {
32
+ + l.strip() for l in _f
33
+ + if l.strip() and not l.strip().startswith('#')
34
+ + }
35
+ + # Intersect file keys with the known EQ-positive set so we never
36
+ + # accidentally include style markers even if the file changes.
37
+ + STANDARD_ALLOWED_RUBRIC_CRITERIA = _EQ_POSITIVE_CRITERIA & _file_criteria
38
+ + if not STANDARD_ALLOWED_RUBRIC_CRITERIA:
39
+ + logging.warning(
40
+ + "[JA-PATCH] STANDARD_RUBRIC_CRITERIA_FILE yielded no EQ-positive "
41
+ + "criteria – falling back to hardcoded set."
42
+ + )
43
+ + STANDARD_ALLOWED_RUBRIC_CRITERIA = _EQ_POSITIVE_CRITERIA
44
+ + except Exception as _e:
45
+ + logging.warning(
46
+ + f"[JA-PATCH] Could not load standard rubric criteria file: {_e} "
47
+ + "– falling back to hardcoded set."
48
+ + )
49
+ + STANDARD_ALLOWED_RUBRIC_CRITERIA = _EQ_POSITIVE_CRITERIA
50
+ # Define the specific criteria to include for analysis tasks
51
+ # Assumes analysis criteria are loaded from ANALYSIS_RUBRIC_CRITERIA_FILE
52
+ # We need to load them here or pass them in. Let's load them.
53
+ analysis_criteria = []
data/conversation.patch ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --- a/core/conversation.py
2
+ +++ b/core/conversation.py
3
+ @@ -92,22 +92,24 @@
4
+ Only applicable for standard role-play and message drafting scenarios.
5
+ """
6
+ # Patterns for different scenario types that require parsing
7
+ # core/elo.py (or wherever you define _parse_response)
8
+ + # [JA-PATCH Fix-C1] Also accept Japanese section headers as fallback.
9
+ draft_patterns = {
10
+ - "perspective_taking": r"#\s*Perspective[- ]taking\s*\n([\s\S]*?)(?=#|\Z)",
11
+ - "draft_brainstorming": r"#\s*Draft brainstorming\s*\n([\s\S]*?)(?=#|\Z)",
12
+ - "draft": r"#\s*Draft\s*\n([\s\S]*?)(?=--|\Z)",
13
+ + "perspective_taking": r"#\s*(?:Perspective[- ]taking|視点の共有|視点取り)\s*\n([\s\S]*?)(?=#|\Z)",
14
+ + "draft_brainstorming": r"#\s*(?:Draft brainstorming|下書きのブレインストーミング|ブレインストーミング)\s*\n([\s\S]*?)(?=#|\Z)",
15
+ + "draft": r"#\s*(?:Draft|下書き)\s*\n([\s\S]*?)(?=--|\Z)",
16
+ }
17
+
18
+ - # Accept straight (') **or** curly (’ U+2019) apostrophes
19
+ + # Accept straight (’) **or** curly (‘ U+2019) apostrophes
20
+ + # [JA-PATCH Fix-C1] Also accept Japanese section headers as fallback.
21
+ rp_patterns = {
22
+ "thinking_feeling":
23
+ - r"#\s*I[’']m thinking & feeling\s*\n([\s\S]*?)(?=#|\Z)",
24
+ + r"#\s*(?:I['’]m thinking & feeling|私は考えているし、感じている|私の思考と感情)\s*\n([\s\S]*?)(?=#|\Z)",
25
+ "their_thinking_feeling":
26
+ - r"#\s*They[’']re thinking & feeling\s*\n([\s\S]*?)(?=#|\Z)",
27
+ + r"#\s*(?:They['’]re thinking & feeling|相手は考えているし、感じている|相手の思考と感情)\s*\n([\s\S]*?)(?=#|\Z)",
28
+ "response":
29
+ - r"#\s*My response\s*\n([\s\S]*?)(?=--|\Z)",
30
+ + r"#\s*(?:My response|私の応答|私の返答)\s*\n([\s\S]*?)(?=--|\Z)",
31
+ }
32
+
33
+
34
+ # Determine which patterns to use
patch/patch_benchmark.py DELETED
@@ -1,104 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- patch_benchmark.py
4
- EQ-Bench3 core/benchmark.py に日本語版パッチを適用する。
5
-
6
- 修正内容:
7
- Fix-B1: calculate_final_rubric_score() の STANDARD_ALLOWED_RUBRIC_CRITERIA を
8
- ハードコードではなく STANDARD_RUBRIC_CRITERIA_FILE から動的に読み込む。
9
- 日本語版ではファイル内を英語キーに統一しているため常に正しく一致する。
10
- """
11
-
12
- import re
13
- import sys
14
- import shutil
15
- from pathlib import Path
16
-
17
- BENCHMARK_FILE = Path("core/benchmark.py")
18
-
19
- OLD_BLOCK = '''\
20
- # Define the specific criteria to include for standard/drafting tasks
21
- STANDARD_ALLOWED_RUBRIC_CRITERIA = {
22
- "demonstrated_empathy",
23
- "pragmatic_ei",
24
- "depth_of_insight",
25
- "social_dexterity",
26
- "emotional_reasoning",
27
- "message_tailoring",
28
- "theory_of_mind",
29
- "subtext_identification",
30
- "intellectual_grounding",
31
- "correctness"
32
- }'''
33
-
34
- NEW_BLOCK = '''\
35
- # Define the specific criteria to include for standard/drafting tasks.
36
- # [JA-PATCH Fix-B1] Load from file instead of hardcoding so that the allowed
37
- # set always matches whatever keys are in the criteria file (English keys when
38
- # running the Japanese edition).
39
- # The scoring subset intentionally excludes style markers (boundary_setting,
40
- # moralising, sycophantic, etc.) – we keep only the EQ-positive criteria.
41
- _EQ_POSITIVE_CRITERIA = {
42
- "demonstrated_empathy",
43
- "pragmatic_ei",
44
- "depth_of_insight",
45
- "social_dexterity",
46
- "emotional_reasoning",
47
- "message_tailoring",
48
- "theory_of_mind",
49
- "subtext_identification",
50
- "intellectual_grounding",
51
- "correctness",
52
- }
53
- try:
54
- with open(C.STANDARD_RUBRIC_CRITERIA_FILE, \'r\', encoding=\'utf-8\') as _f:
55
- _file_criteria = {
56
- l.strip() for l in _f
57
- if l.strip() and not l.strip().startswith(\'#\')
58
- }
59
- # Intersect file keys with the known EQ-positive set so we never
60
- # accidentally include style markers even if the file changes.
61
- STANDARD_ALLOWED_RUBRIC_CRITERIA = _EQ_POSITIVE_CRITERIA & _file_criteria
62
- if not STANDARD_ALLOWED_RUBRIC_CRITERIA:
63
- logging.warning(
64
- "[JA-PATCH] STANDARD_RUBRIC_CRITERIA_FILE yielded no EQ-positive "
65
- "criteria – falling back to hardcoded set."
66
- )
67
- STANDARD_ALLOWED_RUBRIC_CRITERIA = _EQ_POSITIVE_CRITERIA
68
- except Exception as _e:
69
- logging.warning(
70
- f"[JA-PATCH] Could not load standard rubric criteria file: {_e} "
71
- "– falling back to hardcoded set."
72
- )
73
- STANDARD_ALLOWED_RUBRIC_CRITERIA = _EQ_POSITIVE_CRITERIA'''
74
-
75
-
76
- def apply_patch(path: Path) -> bool:
77
- source = path.read_text(encoding="utf-8")
78
-
79
- if "[JA-PATCH Fix-B1]" in source:
80
- print(f" [SKIP] {path} — Fix-B1 already applied.")
81
- return True
82
-
83
- if OLD_BLOCK not in source:
84
- print(f" [ERROR] {path} — target block not found. Check EQ-Bench3 version.")
85
- return False
86
-
87
- # Backup
88
- backup = path.with_suffix(".py.orig")
89
- if not backup.exists():
90
- shutil.copy2(path, backup)
91
- print(f" [BACKUP] {backup}")
92
-
93
- patched = source.replace(OLD_BLOCK, NEW_BLOCK, 1)
94
- path.write_text(patched, encoding="utf-8")
95
- print(f" [OK] Fix-B1 applied to {path}")
96
- return True
97
-
98
-
99
- if __name__ == "__main__":
100
- if not BENCHMARK_FILE.exists():
101
- print(f"ERROR: {BENCHMARK_FILE} not found. Run from eqbench3 root directory.")
102
- sys.exit(1)
103
- ok = apply_patch(BENCHMARK_FILE)
104
- sys.exit(0 if ok else 1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
patch/patch_conversation.py DELETED
@@ -1,127 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- patch_conversation.py
4
- EQ-Bench3 core/conversation.py に日本語版パッチを適用する。
5
-
6
- 修正内容:
7
- Fix-C1: _parse_response() のセクションヘッダー正規表現に日本語の見出しを追加する。
8
- 英語ヘッダーが第一優先(master_prompt_ja.txt は英語見出しを使用している)
9
- だが、モデルが日本語で返した場合のフォールバックとして機能する。
10
- """
11
-
12
- import shutil
13
- import sys
14
- from pathlib import Path
15
-
16
- CONVERSATION_FILE = Path("core/conversation.py")
17
-
18
- # ── Exact byte sequences from the repo (verified against eqbench3 HEAD) ──────
19
- # Each OLD_ string is the literal bytes in the source file.
20
-
21
- # Standard RP patterns block
22
- _OLD_RP_HEX = (
23
- "2020202020202020232041636365707420737472616967687420282729202a2a6f722a2a206375"
24
- "726c792028e2809920552b32303139292061706f7374726f706865730a2020202020202020"
25
- "72705f7061747465726e73203d207b0a20202020202020202020202022746869"
26
- "6e6b696e675f6665656c696e67223a0a2020202020202020202020202020202072222"
27
- "35c732a495be28099275d6d207468696e6b696e672026206665656c696e675c73"
28
- "2a5c6e285b5c735c535d2a3f29283f3d237c5c5a29222c0a20202020202020"
29
- "2020202020227468656972"
30
- "5f7468696e6b696e675f6665656c696e67223a0a20202020202020202020202020202020"
31
- "7222235c732a546865795be28099275d7265207468696e6b696e672026206665656c696e67"
32
- "5c732a5c6e285b5c735c535d2a3f29283f3d237c5c5a29222c0a2020202020202020"
33
- "2020202022726573706f6e7365223a0a20202020202020202020202020202020"
34
- "7222235c732a4d7920726573706f6e73655c732a5c6e285b5c735c535d2a3f29"
35
- "283f3d2d2d7c5c5a29222c0a20202020202020207d"
36
- )
37
- OLD_RP = bytes.fromhex(_OLD_RP_HEX.replace("\n", "").replace(" ", "")).decode("utf-8")
38
-
39
- NEW_RP = (
40
- " # Accept straight (\u2019) **or** curly (\u2018 U+2019) apostrophes\n"
41
- " # [JA-PATCH Fix-C1] Also accept Japanese section headers as fallback.\n"
42
- " rp_patterns = {\n"
43
- " \"thinking_feeling\":\n"
44
- " r\"#\\s*(?:I[\u2019']m thinking & feeling"
45
- "|\u79c1\u306f\u8003\u3048\u3066\u3044\u308b\u3057\u3001\u611f\u3058\u3066\u3044\u308b"
46
- "|\u79c1\u306e\u601d\u8003\u3068\u611f\u60c5)"
47
- "\\s*\\n([\\s\\S]*?)(?=#|\\Z)\",\n"
48
- " \"their_thinking_feeling\":\n"
49
- " r\"#\\s*(?:They[\u2019']re thinking & feeling"
50
- "|\u76f8\u624b\u306f\u8003\u3048\u3066\u3044\u308b\u3057\u3001\u611f\u3058\u3066\u3044\u308b"
51
- "|\u76f8\u624b\u306e\u601d\u8003\u3068\u611f\u60c5)"
52
- "\\s*\\n([\\s\\S]*?)(?=#|\\Z)\",\n"
53
- " \"response\":\n"
54
- " r\"#\\s*(?:My response|\u79c1\u306e\u5fdc\u7b54|\u79c1\u306e\u8fd4\u7b54)"
55
- "\\s*\\n([\\s\\S]*?)(?=--|\\Z)\",\n"
56
- " }"
57
- )
58
-
59
- # Message drafting patterns block
60
- OLD_DRAFT = (
61
- " draft_patterns = {\n"
62
- " \"perspective_taking\": r\"#\\s*Perspective[- ]taking\\s*\\n([\\s\\S]*?)(?=#|\\Z)\",\n"
63
- " \"draft_brainstorming\": r\"#\\s*Draft brainstorming\\s*\\n([\\s\\S]*?)(?=#|\\Z)\",\n"
64
- " \"draft\": r\"#\\s*Draft\\s*\\n([\\s\\S]*?)(?=--|\\Z)\",\n"
65
- " }"
66
- )
67
-
68
- NEW_DRAFT = (
69
- " # [JA-PATCH Fix-C1] Also accept Japanese section headers as fallback.\n"
70
- " draft_patterns = {\n"
71
- " \"perspective_taking\": r\"#\\s*(?:Perspective[- ]taking"
72
- "|\u8996\u70b9\u306e\u5171\u6709|\u8996\u70b9\u53d6\u308a)"
73
- "\\s*\\n([\\s\\S]*?)(?=#|\\Z)\",\n"
74
- " \"draft_brainstorming\": r\"#\\s*(?:Draft brainstorming"
75
- "|\u4e0b\u66f8\u304d\u306e\u30d6\u30ec\u30a4\u30f3\u30b9\u30c8\u30fc\u30df\u30f3\u30b0"
76
- "|\u30d6\u30ec\u30a4\u30f3\u30b9\u30c8\u30fc\u30df\u30f3\u30b0)"
77
- "\\s*\\n([\\s\\S]*?)(?=#|\\Z)\",\n"
78
- " \"draft\": r\"#\\s*(?:Draft|\u4e0b\u66f8\u304d)"
79
- "\\s*\\n([\\s\\S]*?)(?=--|\\Z)\",\n"
80
- " }"
81
- )
82
-
83
-
84
- def apply_patch(path: Path) -> bool:
85
- source = path.read_text(encoding="utf-8")
86
-
87
- if "[JA-PATCH Fix-C1]" in source:
88
- print(f" [SKIP] {path} \u2014 Fix-C1 already applied.")
89
- return True
90
-
91
- backup = path.with_suffix(".py.orig")
92
- if not backup.exists():
93
- shutil.copy2(path, backup)
94
- print(f" [BACKUP] {backup}")
95
-
96
- changed = False
97
-
98
- if OLD_RP in source:
99
- source = source.replace(OLD_RP, NEW_RP, 1)
100
- print(f" [OK] Fix-C1 RP patterns applied.")
101
- changed = True
102
- else:
103
- print(f" [WARN] RP patterns target block not found in {path}.")
104
- print(f" Japanese RP header fallback will not be active.")
105
- print(f" (Non-fatal: master_prompt_ja.txt uses English headers)")
106
-
107
- if OLD_DRAFT in source:
108
- source = source.replace(OLD_DRAFT, NEW_DRAFT, 1)
109
- print(f" [OK] Fix-C1 Draft patterns applied.")
110
- changed = True
111
- else:
112
- print(f" [WARN] Draft patterns target block not found in {path}.")
113
-
114
- if not changed:
115
- print(f" [ERROR] No patterns could be patched in {path}.")
116
- return False
117
-
118
- path.write_text(source, encoding="utf-8")
119
- return True
120
-
121
-
122
- if __name__ == "__main__":
123
- if not CONVERSATION_FILE.exists():
124
- print(f"ERROR: {CONVERSATION_FILE} not found. Run from eqbench3 root directory.")
125
- sys.exit(1)
126
- ok = apply_patch(CONVERSATION_FILE)
127
- sys.exit(0 if ok else 1)