Corin1998 commited on
Commit
5725d3f
·
verified ·
1 Parent(s): 58dc15f

Delete es_processor_main.py

Browse files
Files changed (1) hide show
  1. es_processor_main.py +0 -162
es_processor_main.py DELETED
@@ -1,162 +0,0 @@
1
- import json
2
- # 外部モジュールのインポートをシミュレート (実際には適切な方法でインポートが必要)
3
- # from model_initializer import initialize_tone_classifier, initialize_star_classifier
4
- # from tone_analyzer import analyze_tone
5
- # from star_checker import check_star_suitability
6
-
7
- # NOTE: 実行環境の制約上、ここでは前のファイルの内容を直接関数として再定義し、
8
- # 外部モジュールとして動作していることをシミュレーションします。
9
-
10
- # --- 1. model_initializer.py からの関数 (ここでは再定義) ---
11
- import torch
12
- from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
13
-
14
- def initialize_tone_classifier():
15
- TONE_MODEL_NAME = "cl-tohoku/bert-base-japanese-whole-word-masking"
16
- try:
17
- tone_classifier = pipeline(
18
- "sentiment-analysis",
19
- model="cl-tohoku/bert-base-japanese-whole-word-masking",
20
- tokenizer="cl-tohoku/bert-base-japanese-whole-word-masking"
21
- )
22
- return tone_classifier
23
- except Exception:
24
- classifier = pipeline(
25
- "text-classification",
26
- model=AutoModelForSequenceClassification.from_pretrained(TONE_MODEL_NAME),
27
- tokenizer=AutoTokenizer.from_pretrained(TONE_MODEL_NAME),
28
- id2label={0: "Negative", 1: "Positive"}
29
- )
30
- return classifier
31
-
32
- def initialize_star_classifier():
33
- try:
34
- star_classifier = pipeline(
35
- "zero-shot-classification",
36
- model="izumi-lab/bert-base-japanese-v2",
37
- tokenizer="izumi-lab/bert-base-japanese-v2",
38
- device=0 if torch.cuda.is_available() else -1
39
- )
40
- return star_classifier
41
- except Exception:
42
- star_classifier = pipeline(
43
- "zero-shot-classification",
44
- model="cl-tohoku/bert-base-japanese-whole-word-masking",
45
- tokenizer="cl-tohoku/bert-base-japanese-whole-word-masking",
46
- device=0 if torch.cuda.is_available() else -1
47
- )
48
- return star_classifier
49
-
50
- # --- 2. tone_analyzer.py からの関数 (ここでは再定義) ---
51
- def analyze_tone(text, tone_classifier):
52
- results = tone_classifier(text)
53
- result = results[0]
54
- sentiment_label = result['label']
55
- sentiment_score = result['score']
56
- enthusiasm_score = round(sentiment_score * 100, 2)
57
- return {
58
- "label": sentiment_label,
59
- "raw_score": sentiment_score,
60
- "enthusiasm_score": enthusiasm_score
61
- }
62
-
63
- # --- 3. star_checker.py からの関数 (ここでは再定義) ---
64
- def check_star_suitability(self_pr_text, star_classifier):
65
- candidate_labels = ["状況 (Situation)", "課題 (Task)", "行動 (Action)", "結果 (Result)"]
66
- star_results = star_classifier(
67
- self_pr_text,
68
- candidate_labels,
69
- multi_label=True
70
- )
71
- star_scores = {label: round(score * 100, 2) for label, score in zip(star_results['labels'], star_results['scores'])}
72
-
73
- insufficiency_threshold = 70.0
74
- missing_elements = []
75
- total_score = 0
76
- for label, score in star_scores.items():
77
- total_score += score
78
- if score < insufficiency_threshold:
79
- missing_elements.append(label)
80
-
81
- suitability_score = round(total_score / len(candidate_labels), 2)
82
-
83
- analysis_reason = {
84
- "suitability_score": suitability_score,
85
- "is_logical": suitability_score >= 75.0,
86
- "reason_code": "LOGICAL_STRUCTURE_GOOD" if not missing_elements else "ELEMENTS_MISSING",
87
- "missing_elements": missing_elements,
88
- "detail_scores": star_scores
89
- }
90
-
91
- return {
92
- "suitability_score": suitability_score,
93
- "analysis_json": analysis_reason
94
- }
95
- # --- ここまでシミュレーションのための再定義 ---
96
-
97
-
98
- def process_es_data(es_text, self_pr_text, tone_classifier, star_classifier):
99
- """
100
- ES全体のデータを受け取り、感情・トーン分析とSTAR適合度チェックを実行するメイン関数。
101
- """
102
- print("=========================================")
103
- print("🚀 新卒ES 自動評価パイプライン開始")
104
- print("=========================================")
105
-
106
- # 1. 感情・トーン分析
107
- print("\n--- 1. 感情・トーン分析の実行 ---")
108
- tone_analysis = analyze_tone(es_text, tone_classifier)
109
- print(f"熱意・トーン分析結果 (ポジティブ度): {tone_analysis['enthusiasm_score']} %")
110
- print(f"判定ラベル: {tone_analysis['label']}")
111
-
112
- # 2. STAR法適合度チェック
113
- print("\n--- 2. STAR法適合度チェックの実行 ---")
114
- star_analysis = check_star_suitability(self_pr_text, star_classifier)
115
- print(f"STAR法 総合適合度スコア: {star_analysis['suitability_score']} %")
116
- print(f"論理構造分析JSON (不足要素など):")
117
- print(json.dumps(star_analysis['analysis_json'], indent=4, ensure_ascii=False))
118
-
119
- # 最終スコアの統合(例: 感情スコア 50%, STARスコア 50% の重み付け)
120
- final_potential_score = (tone_analysis['enthusiasm_score'] * 0.5) + (star_analysis['suitability_score'] * 0.5)
121
-
122
- print("\n=========================================")
123
- print(f"✨ 最終ポテンシャル評価スコア (統合): {round(final_potential_score, 2)} / 100")
124
- print("=========================================")
125
-
126
- return {
127
- "final_score": round(final_potential_score, 2),
128
- "tone_analysis": tone_analysis,
129
- "star_analysis": star_analysis
130
- }
131
-
132
-
133
- if __name__ == '__main__':
134
- # 1. モデルの初期化
135
- print("Hugging Face パイプラインの初期化を開始します...")
136
- tc = initialize_tone_classifier()
137
- sc = initialize_star_classifier()
138
-
139
- # 2. 実行例
140
- # 実際のESテキスト(全体)
141
- es_full_text = """
142
- 貴社が推進する「グローバル×ローカル」のデジタル変革戦略に深く共感し、志望いたしました。私は大学時代、学園祭の実行委員長として、従来の集客方法に課題を感じ、SNSを活用した新しいプロモーション戦略を立案・実行しました。これにより、来場者数を前年比150%に増加させるという明確な結果を出しました。この経験から学んだ、現状を打破するための課題設定力と、関係者を巻き込む実行力を貴社で活かし、世界中の顧客に感動を届けるシステムを構築したいと強く願っています。
143
- """
144
-
145
- # STAR法チェックの対象となる自己PRセクション
146
- self_pr_text_star_focus = """
147
- 私は大学時代、学園祭の実行委員長として、従来の集客方法に課題を感じ、SNSを活用した新しいプロモーション戦略を立案・実行しました。これにより、来場者数を前年比150%に増加させるという明確な結果を出しました。課題はSNSチームのメンバーのモチベーション管理でしたが、個別の面談を通じて主体的な関与を引き出し、最終的に全員が目標達成に貢献しました。
148
- """
149
-
150
- # ESデータの処理を実行
151
- results = process_es_data(es_full_text, self_pr_text_star_focus, tc, sc)
152
-
153
- # 例: 不足要素がある場合のシミュレーション (結果が弱いES)
154
- print("\n\n--- 不足要素がある場合のシミュレーション (結果が弱いES) ---")
155
- weak_result_es = """
156
- 私はチームプロジェクトでリーダーシップを発揮しました(Action)。当初、目標達成が難しい状況(Situation)でしたが、諦めずにメンバーと協力し、最後までやり遂げました(Task)。結果、多くのことを学び、成長できました。
157
- """
158
-
159
- weak_results = check_star_suitability(weak_result_es, sc)
160
- print("STAR法 総合適合度スコア:", weak_results['suitability_score'], "%")
161
- print("論理構造分析JSON (結果が弱いES):")
162
- print(json.dumps(weak_results['analysis_json'], indent=4, ensure_ascii=False))