kevineen commited on
Commit
509018d
1 Parent(s): 7118c82

詳細モード追加

Browse files
Files changed (3) hide show
  1. .gitignore +5 -1
  2. app.py +1105 -148
  3. run.py +1105 -146
.gitignore CHANGED
@@ -165,4 +165,8 @@ user_annotation/*
165
  run.py
166
  backup.py
167
  huggingface_dataset.txt
168
- note.txt
 
 
 
 
 
165
  run.py
166
  backup.py
167
  huggingface_dataset.txt
168
+ note.txt
169
+ type/
170
+ claude/
171
+ app_backup.py
172
+ run copy.py
app.py CHANGED
@@ -26,14 +26,14 @@ else:
26
  print("Warning: HF_TOKEN not found. Please set it in your Space secrets.")
27
 
28
  # HFデータセット アップロード先
29
- # (切替てテストする用に配列)
30
- output_dataset = [
31
  "team-hatakeyama-phase2/annotation_tanuki_phase2",
32
  "kevineen/Tanuki-Phase2-annotation-dataset", # 出力テスト
33
  ]
34
 
35
  # アノテーション対象データセット
36
- annotation_dataset_list = [
37
  "hatakeyama-llm-team/AutoGeneratedJapaneseQA",
38
  "hatakeyama-llm-team/AutoGeneratedJapaneseQA-other",
39
  "kanhatakeyama/ChatbotArenaJaMixtral8x22b",
@@ -44,9 +44,11 @@ annotation_dataset_list = [
44
  # "hatakeyama-llm-team/WikiBookJa",
45
  # "kanhatakeyama/AutoWikiQA",
46
  # "susumuota/SyntheticTextWikiTranslate-askllm-v1", # Ask-LLM 翻訳
 
 
47
  ]
48
 
49
- multi_turn_annotation_dataset_list = [
50
  # マルチターン 未対応
51
  "kanhatakeyama/AutoMultiTurnByMixtral8x22b",
52
  ]
@@ -58,58 +60,151 @@ is_selected_dataset = gr.State(False)
58
  is_loaded_dataset = gr.State(False)
59
 
60
  # 選択中のデータセットリスト
61
- dropdown_dataset_list = gr.State(value=annotation_dataset_list)
 
62
  # 現在の対象データセット 初期値は"hatakeyama-llm-team/AutoGeneratedJapaneseQA",
63
  select_dropdown_dataset = gr.State(dropdown_dataset_list.value[0])
64
  select_dataset = gr.State(None) # 現在のデータセット
65
  select_dataset_total_len = gr.State(0) # 現在のデータセットの長さ
66
  select_idx = gr.State(0) # 現在のインデックス (ランダムモードにするなら不要?
67
- random_mode = gr.State(False)
68
 
69
  # 回答者がアノテーションしたデータセット
70
  annotated_dataset = gr.State(
71
  pd.DataFrame({
72
- 'dataset_name': [],
73
- 'dataset_id': [],
74
- 'who': [],
75
- 'good': [],
76
- 'bad': [],
77
- 'unknown_quality': [], # 新しいデータフィールドを追加
78
- 'score': [],
79
- 'is_proofreading_1': [],
80
  'answer_text_1': [],
81
- 'is_proofreading_2': [], # マルチターン用
82
- 'answer_text_2': [], # マルチターン用
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  })
84
  )
85
 
86
- initial_answer_text_1 = gr.State("") # 回答1を整形したかチェック用
87
- initial_answer_text_2 = gr.State("") # 回答2を整形したかチェック用
88
-
89
- is_dataset_loaded = gr.State(False)
90
 
91
  you_dataset_id = gr.State(0) # 回答者がアノテーションしているデータのID
92
  dataset_name = gr.State("") # 編集に使用したデータセット名
93
  dataset_id = gr.State(0) # 加工元データセットのindex
94
  who = gr.State("") # アノテーション者名
 
 
 
95
  good = gr.State(False) # 良
96
  bad = gr.State(False) # 悪
97
- unknown_quality = gr.State(False) # 分からない # 新しいデータフィールドを追加
98
- score = gr.State(3) # スコア 初期値は3
 
 
99
  is_proofreading_1 = gr.State(False) # 回答1を整形したか_1
100
  answer_text_1 = gr.State("") # answer_1 回答
101
  is_proofreading_2 = gr.State(False) # 回答2を整形したか_2
102
  answer_text_2 = gr.State("") # answer_2 回答
103
 
104
- # 未整理
105
- # データ読み込み ========================================
106
-
107
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  def dataset_load_fn() -> Tuple[
109
  str,
110
  str,
111
  str,
112
  str,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  gr.update,
114
  gr.update,
115
  gr.update,
@@ -118,9 +213,12 @@ def dataset_load_fn() -> Tuple[
118
  gr.update,
119
  gr.update,
120
  gr.update,
121
- gr.update]:
 
 
 
122
 
123
- is_dataset_loaded.value = False # ロード状態
124
 
125
  select_dataset.value = load_dataset(
126
  select_dropdown_dataset.value
@@ -129,6 +227,7 @@ def dataset_load_fn() -> Tuple[
129
  # DatasetオブジェクトをPandas DataFrameに変換
130
  df = select_dataset.value["train"].to_pandas()
131
 
 
132
  # index列を追加し、シャッフル
133
  df = df.reset_index(drop=False) # 元のindexを保持
134
  df = df.sample(frac=1).reset_index(drop=True) # シャッフル
@@ -138,7 +237,7 @@ def dataset_load_fn() -> Tuple[
138
  select_dataset_total_len.value = len(df) # 長さを取得
139
  is_dataset_loaded.value = True # ロード完了
140
 
141
- # データロード時に初期値を設定
142
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
143
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
144
 
@@ -146,6 +245,39 @@ def dataset_load_fn() -> Tuple[
146
  df.iloc[select_idx.value]["answer"], \
147
  df.iloc[select_idx.value]["question"], \
148
  df.iloc[select_idx.value]["answer"], \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  gr.update(interactive=True), \
150
  gr.update(interactive=True), \
151
  gr.update(interactive=True), \
@@ -164,7 +296,7 @@ annotation_file = Path("user_annotation/") / f"data_{uuid.uuid4()}.json"
164
  annotated_folder = annotation_file.parent
165
 
166
  scheduler = CommitScheduler(
167
- repo_id=output_dataset[0],
168
  repo_type="dataset",
169
  folder_path=annotated_folder,
170
  path_in_repo="data", # Spaceの場合の保存先フォルダー
@@ -172,19 +304,58 @@ scheduler = CommitScheduler(
172
  every=5, # 5分毎にアップロード HuggingFAce_Documentの最低推奨値
173
  )
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  # CommitScheduler (HFへのデータアップロード
176
  def save_annotation(
177
  dataset_name: str,
178
  dataset_id: int,
179
  who: str,
 
180
  good: bool,
181
  bad: bool,
182
- unknown_quality: bool,
183
- score: int,
184
  is_proofreading_1: bool,
185
  answer_text_1: str,
186
  is_proofreading_2: bool,
187
- answer_text_2: str) -> None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
  annotated_dataset.value = pd.concat([
190
  annotated_dataset.value,
@@ -192,33 +363,82 @@ def save_annotation(
192
  'dataset_name': [dataset_name],
193
  'dataset_id': [dataset_id],
194
  'who': [who],
 
195
  'good': [good],
196
  'bad': [bad],
197
- 'unknown_quality': [unknown_quality],
198
- 'score': [score],
199
  'is_proofreading_1': [is_proofreading_1],
200
  "answer_text_1": [answer_text_1],
201
  'is_proofreading_2': [is_proofreading_2],
202
- 'answer_text_2': [answer_text_2]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  })], ignore_index=True).reset_index(drop=True)
204
 
205
  # 書き込み
206
  with scheduler.lock:
207
  with annotation_file.open("a", encoding='utf-8') as f:
208
  data_to_write = {
209
- # "id": , CommitSchedulerだと取得して末尾idを付与することが無理?
210
  "datetime": str(datetime.datetime.now().isoformat()),
211
  "dataset_name": dataset_name,
212
  "dataset_id": int(dataset_id),
213
  "who": who,
 
214
  "good": good,
215
  "bad": bad,
216
- "unknown_quality": unknown_quality, # 新しいデータフィールドを追加
217
- "score": score,
218
  "is_proofreading_1": is_proofreading_1,
219
  "answer_text_1": answer_text_1,
220
  "is_proofreading_2": is_proofreading_2,
221
  "answer_text_2": answer_text_2,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  }
223
  f.write(json.dumps(data_to_write, ensure_ascii=False))
224
  f.write("\n")
@@ -230,7 +450,6 @@ def save_annotation(
230
 
231
  # ユーザー名表示
232
 
233
-
234
  def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
235
  if profile is None:
236
  return "プライベートデータセット取得のためにログインしてください。", who.value
@@ -242,30 +461,40 @@ def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
242
  theme_ = gr.themes.Default()
243
 
244
  # 後のCSSデザイン変更用
245
-
246
-
247
  def load_css():
248
  with open("style.css", "r") as file:
249
  css_content = file.read()
250
  return css_content
251
 
252
-
253
  # Gradio 画面 ============================================
254
  with gr.Blocks(theme=theme_, css=load_css()) as demo:
255
 
256
  gr.Markdown("# データセット アノテーション for Tanuki (Phase2)")
257
- gr.Markdown("### GENIACにて開発中のLLM用データセットに対してアノテーションするSpaceです\n入力されたデータは使用される可能性があるため、個人情報・秘匿情報などは入力しないでください。\nテスト中です。")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
 
259
  with gr.Tab("アノテーション (シングルターン)"):
260
 
261
- with gr.Row(equal_height=True):
262
-
263
- gr.LoginButton(value="HuggingFace ログイン",
264
- logout_value="HuggingFace ログアウト", scale=1)
265
-
266
  # ユーザー名
267
- gr_profile_name = gr.Markdown()
268
- demo.load(hello, inputs=None, outputs=[gr_profile_name, who])
269
 
270
  with gr.Row():
271
 
@@ -288,76 +517,353 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
288
  gr_data_load_btn = gr.Button("② データセットを読み込む")
289
 
290
  with gr.Column() as content_column:
 
291
  with gr.Tab("③ シンプル(良・悪)"):
292
  with gr.Column():
293
  with gr.Row(equal_height=True):
294
- good_btn = gr.Button("良い", interactive=False)
295
- unknown_btn = gr.Button(
296
  "分からない", interactive=False) # 「分からない」ボタンを追加
297
- bad_btn = gr.Button("悪い", interactive=False)
298
 
299
- gr_question_text_1 = gr.Textbox(
300
  label="質問: ", lines=5, interactive=False)
301
 
302
- gr_answer_text_1 = gr.Textbox(
303
- label="回答: 訂正頂けると品質が上がります。",
304
  lines=20,
305
- interactive=True)
 
 
 
 
 
 
 
 
 
 
 
 
306
 
307
- with gr.Tab("③ 5段階評価"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
 
309
- gr_question_text_3 = gr.Textbox(
310
- label="質問: ", lines=5, interactive=False)
311
 
312
- with gr.Row() as score_btn:
313
- gr_score_5 = gr.Button("5: 高品質", interactive=False)
314
- gr_score_4 = gr.Button("4: 良い", interactive=False)
315
- gr_score_3 = gr.Button("3: 普通", interactive=False)
316
- gr_score_2 = gr.Button("2: 悪い", interactive=False)
317
- gr_score_1 = gr.Button("1: 低品質", interactive=False)
318
 
319
- gr_answer_text_3 = gr.Textbox(
320
- label="回答: 訂正して頂けると品質が上がります。", lines=20, interactive=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
 
322
  # 5段階評価ボタンのクリックイベントを定義
323
  def score_button_clicked(button_value):
 
324
  good.value = False
325
  bad.value = False
326
- unknown_quality.value = False # 「分からない」の状態をリセット
327
- score.value = button_value
328
-
329
- gr_data_load_btn.click(
330
- dataset_load_fn,
331
- inputs=None,
332
- outputs=[gr_question_text_1,
333
- gr_answer_text_1,
334
- gr_question_text_3,
335
- gr_answer_text_3,
336
- good_btn,
337
- unknown_btn, # 「分からない」ボタンを追加
338
- bad_btn,
339
- gr_score_1,
340
- gr_score_2,
341
- gr_score_3,
342
- gr_score_4,
343
- gr_score_5,
344
- ]
345
- )
346
 
 
347
  def update_annotation(
348
  input_ans_1: str = None,
349
- input_ans_3: str = None,
350
  is_good: bool = None, # good/bad を表すフラグを追加
351
  is_unknown: bool = None, # 「分からない」を表すフラグを追加
 
352
  score_value: int = None # 5段階評価の値、good/badの場合はNone
353
- ) -> Tuple[gr.update, gr.update, gr.update, gr.update]:
 
 
 
 
 
 
354
 
355
  # good/bad/unknown と score の状態を更新
356
  update_evaluation_state(is_good, is_unknown, score_value)
357
 
358
  # 変更を検知 (5段階評価の場合も処理するように変更)
359
- update_answer_state(input_ans_1, input_ans_3)
360
-
361
  # 表示更新
362
  # indexを進める
363
  select_idx.value += 1
@@ -367,19 +873,31 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
367
  # ループさせるか、エラー処理を行う
368
  if select_idx.value >= len(df):
369
  select_idx.value = 0
 
 
 
 
370
 
371
  # データセットに追加
372
- # 元のindex番号(dataset_id)を指定して保存
373
  save_annotation_data(df)
374
 
375
  # Nextデータ初期化
376
  initialize_next_data(df)
 
 
 
377
 
378
  return gr.update(value=df.iloc[select_idx.value]["question"]), \
379
  gr.update(value=df.iloc[select_idx.value]["answer"]), \
380
  gr.update(value=df.iloc[select_idx.value]["question"]), \
381
- gr.update(value=df.iloc[select_idx.value]["answer"])
 
 
 
 
382
 
 
383
  def update_evaluation_state(is_good, is_unknown, score_value):
384
  if score_value is not None: # 5段階評価の場合
385
  good.value = False
@@ -391,100 +909,539 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
391
  bad.value = not is_good if not is_unknown else False
392
  unknown_quality.value = is_unknown # 「分からない」の状態を設定
393
 
394
- def update_answer_state(input_ans_1, input_ans_3):
 
395
  if input_ans_1 is not None and initial_answer_text_1.value != input_ans_1:
396
  is_proofreading_1.value = True
397
  answer_text_1.value = input_ans_1
398
  else:
399
  answer_text_1.value = ""
400
 
401
- if input_ans_3 is not None and initial_answer_text_2.value != input_ans_3:
 
402
  is_proofreading_2.value = True
403
- answer_text_2.value = input_ans_3
404
  else:
405
  answer_text_2.value = ""
406
 
 
407
  def save_annotation_data(df):
408
  save_annotation(
409
  select_dropdown_dataset.value,
410
  # datasetIdは元のindex番号を使用
411
  df.iloc[select_idx.value]['index'],
412
  who.value,
 
413
  good.value,
414
  bad.value,
415
- unknown_quality.value, # 「分からない」の状態を追加
416
- score.value,
417
  is_proofreading_1.value,
418
  answer_text_1.value,
419
  is_proofreading_2.value,
420
- answer_text_2.value
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  )
422
 
 
423
  def initialize_next_data(df):
424
  is_proofreading_1.value = False
425
  is_proofreading_2.value = False
426
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
427
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
428
-
429
- def good_click(input_ans_1, input_ans_3):
430
- return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=True, is_unknown=False)
431
-
432
- good_btn.click(
433
- good_click,
434
- inputs=[
435
- gr_answer_text_1,
436
- gr_answer_text_3
437
- ],
438
- outputs=[gr_question_text_1,
439
- gr_answer_text_1,
440
- gr_question_text_3,
441
- gr_answer_text_3]
442
- )
443
-
444
- def unknown_click(input_ans_1, input_ans_3):
445
  good.value = False
446
  bad.value = False
447
- return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=False, is_unknown=True)
448
-
449
- unknown_btn.click(
 
 
 
 
 
 
 
 
450
  unknown_click,
451
  inputs=[
452
- gr_answer_text_1,
453
- gr_answer_text_3
454
  ],
455
- outputs=[gr_question_text_1,
456
- gr_answer_text_1,
457
- gr_question_text_3,
458
- gr_answer_text_3]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  )
460
 
461
- def bad_click(input_ans_1, input_ans_3):
462
- return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=False, is_unknown=False)
463
-
464
- bad_btn.click(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
  bad_click,
466
  inputs=[
467
- gr_answer_text_1,
468
- gr_answer_text_3
469
  ],
470
- outputs=[gr_question_text_1,
471
- gr_answer_text_1,
472
- gr_question_text_3,
473
- gr_answer_text_3]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  )
475
 
476
  # 5段階評価ボタンのクリックイベント
477
- gr_score_1.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=1),
478
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
479
- gr_score_2.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=2),
480
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
481
- gr_score_3.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=3),
482
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
483
- gr_score_4.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=4),
484
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
485
- gr_score_5.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=5),
486
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
487
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  # TODO Tab切り替えで、アノテ済みの一覧を表示する
489
  # with gr.Tab("アノテ済みデータセット(管理画面)"):
490
  # タブを切り替えた時にデータ表示を更新する
 
26
  print("Warning: HF_TOKEN not found. Please set it in your Space secrets.")
27
 
28
  # HFデータセット アップロード先
29
+ # (切り替えてテストする用に配列)
30
+ OUTPUT_DATASET = [
31
  "team-hatakeyama-phase2/annotation_tanuki_phase2",
32
  "kevineen/Tanuki-Phase2-annotation-dataset", # 出力テスト
33
  ]
34
 
35
  # アノテーション対象データセット
36
+ ANNOTATION_DATASET = [
37
  "hatakeyama-llm-team/AutoGeneratedJapaneseQA",
38
  "hatakeyama-llm-team/AutoGeneratedJapaneseQA-other",
39
  "kanhatakeyama/ChatbotArenaJaMixtral8x22b",
 
44
  # "hatakeyama-llm-team/WikiBookJa",
45
  # "kanhatakeyama/AutoWikiQA",
46
  # "susumuota/SyntheticTextWikiTranslate-askllm-v1", # Ask-LLM 翻訳
47
+
48
+ # Nomotron データ (将来用
49
  ]
50
 
51
+ MULTITURN_ANNOTATION_DATASET = [
52
  # マルチターン 未対応
53
  "kanhatakeyama/AutoMultiTurnByMixtral8x22b",
54
  ]
 
60
  is_loaded_dataset = gr.State(False)
61
 
62
  # 選択中のデータセットリスト
63
+ dropdown_dataset_list = gr.State(value=ANNOTATION_DATASET)
64
+
65
  # 現在の対象データセット 初期値は"hatakeyama-llm-team/AutoGeneratedJapaneseQA",
66
  select_dropdown_dataset = gr.State(dropdown_dataset_list.value[0])
67
  select_dataset = gr.State(None) # 現在のデータセット
68
  select_dataset_total_len = gr.State(0) # 現在のデータセットの長さ
69
  select_idx = gr.State(0) # 現在のインデックス (ランダムモードにするなら不要?
70
+ # random_mode = gr.State(False) # ランダムモード
71
 
72
  # 回答者がアノテーションしたデータセット
73
  annotated_dataset = gr.State(
74
  pd.DataFrame({
75
+ 'dataset_name': [], # 対象データセット
76
+ 'dataset_id': [], # データセットindex
77
+ 'who': [], # アノテーション者名
78
+ 'unknown_quality': [], # 不明能
79
+ 'good': [], # 良
80
+ 'bad': [], #
81
+ 'is_proofreading_1': [], # テキストに修正があったか
 
82
  'answer_text_1': [],
83
+ 'is_proofreading_2': [], # 2ターン目用
84
+ 'answer_text_2': [], # 2ターン目用
85
+
86
+ # 5段階評価
87
+ 'score': [], # 総合 (5段階評価)
88
+ 'helphulness': [], # 有用性 (5段階評価)
89
+ 'correcthness': [], # 正確さ (5段階評価)
90
+ 'coherence': [], # 一貫性 (5段階評価)
91
+ 'complexity': [], # 複雑さ (5段階評価)
92
+ 'verbosity': [], # 冗長性 (5段階評価)
93
+ 'humor': [], # ユーモア (SteerLM)
94
+ 'creativity': [], # 創造性 (SteerLM)
95
+ 'appropriate': [], # 適切性 (SteerLMでは不適)
96
+ 'following_instructions': [], # 指示が合った場合、従っているか (SteerLMのfails_taskに該当)
97
+ 'politeness': [], # 礼儀正しさ (minnadechat)
98
+ 'harmfulness': [], # 有性 (minnadechat)
99
+
100
+ # 0: 分からない(未設定) 1: 無 2: 有
101
+ 'typos': [], # 誤字脱字 (minnadechat)
102
+ 'hate': [], # ヘイト
103
+ 'sexual': [], # 性的
104
+ 'violence': [], # 暴力
105
+ 'suicide': [], # 自殺
106
+ 'threat': [], # 犯罪
107
+ 'gun': [], # 重火器
108
+ 'controlled_substance': [], # 規制対象物質
109
+ 'climinal_planing': [], # 犯罪計画
110
+ 'privacy': [], # 個人情報
111
+ 'harassment': [], # ハラスメント
112
+ 'profanity': [], # 冒涜
113
+ 'political_content': [], # 政治的内容 (SteerLM)
114
+ 'moral_judgement': [], # 非道徳 (SteerLM)
115
  })
116
  )
117
 
118
+ is_dataset_loaded = gr.State(False) # データセットロード状態
 
 
 
119
 
120
  you_dataset_id = gr.State(0) # 回答者がアノテーションしているデータのID
121
  dataset_name = gr.State("") # 編集に使用したデータセット名
122
  dataset_id = gr.State(0) # 加工元データセットのindex
123
  who = gr.State("") # アノテーション者名
124
+
125
+ # シンプルモード
126
+ unknown_quality = gr.State(False) # 分からない(未設定)
127
  good = gr.State(False) # 良
128
  bad = gr.State(False) # 悪
129
+
130
+ initial_answer_text_1 = gr.State("") # 回��1を整形したかチェック用
131
+ initial_answer_text_2 = gr.State("") # 回答2を整形したかチェック用
132
+
133
  is_proofreading_1 = gr.State(False) # 回答1を整形したか_1
134
  answer_text_1 = gr.State("") # answer_1 回答
135
  is_proofreading_2 = gr.State(False) # 回答2を整形したか_2
136
  answer_text_2 = gr.State("") # answer_2 回答
137
 
138
+ # (5段階評価)
139
+ # 0は判断していない、又は判断が難しいという特徴量にする
140
+ score = gr.State(3) # 総合スコア 初期値は3 (最低限必須)
141
+ helphulness = gr.State(0) # 有用性
142
+ correcthness = gr.State(0) # 正確さ
143
+ coherenece = gr.State(0) # 一貫性
144
+ complexity = gr.State(0) # 複雑さ
145
+ verbosity = gr.State(0) # 冗長性
146
+ humor = gr.State(0) # ユーモア (SteerLM)
147
+ creativity = gr.State(0) # 創造性 (SteerLM)
148
+ appropriate = gr.State(0) # 適切性 (SteerLMではnot_appropriate)
149
+ following_instructions = gr.State(0) # 指示への忠実度 (SteerLMのfails_task)
150
+ politeness = gr.State(0) # 礼儀正しさ (minnadechat)
151
+ harmfulness = gr.State(0) # 有度 (minnadechat)
152
+
153
+ # (有無評価)
154
+ # 0は判断していない、又は判断が難しいという特徴量にする
155
+ hate = gr.State(0) # ヘイト
156
+ sexual = gr.State(0) # 性的
157
+ violence = gr.State(0) # 暴力
158
+ suicide = gr.State(0) # 自殺
159
+ threat = gr.State(0) # 犯罪
160
+ gun = gr.State(0) # 銃・重火器
161
+ controlled_substance = gr.State(0) # 規制対象物質
162
+ climinal_planing = gr.State(0) # 犯罪計画
163
+ privacy = gr.State(0) # 個人情報・プライバシー情報
164
+ harassment = gr.State(0) # ハラスメント
165
+ profanity = gr.State(0) # 冒涜
166
+ political_content = gr.State(0) # 政治的内容 (SteerLM)
167
+ moral_judgement = gr.State(0) # 非道徳 (SteerLM)
168
+ typos = gr.State(0) # 誤字脱字(minnadechat)
169
+
170
+ # 未整理 ========================================
171
+
172
+ # データセット読み込み
173
  def dataset_load_fn() -> Tuple[
174
  str,
175
  str,
176
  str,
177
  str,
178
+ str,
179
+ str,
180
+ gr.update,
181
+ gr.update,
182
+ gr.update,
183
+ gr.update,
184
+ gr.update,
185
+ gr.update,
186
+ gr.update,
187
+ gr.update,
188
+ gr.update,
189
+ gr.update,
190
+ gr.update,
191
+ gr.update,
192
+ gr.update,
193
+ gr.update,
194
+ gr.update,
195
+ gr.update,
196
+ gr.update,
197
+ gr.update,
198
+ gr.update,
199
+ gr.update,
200
+ gr.update,
201
+ gr.update,
202
+ gr.update,
203
+ gr.update,
204
+ gr.update,
205
+ gr.update,
206
+ gr.update,
207
+ gr.update,
208
  gr.update,
209
  gr.update,
210
  gr.update,
 
213
  gr.update,
214
  gr.update,
215
  gr.update,
216
+ gr.update,
217
+ gr.update,
218
+ gr.update,
219
+ ]:
220
 
221
+ is_dataset_loaded.value = False # ロード状態初期化
222
 
223
  select_dataset.value = load_dataset(
224
  select_dropdown_dataset.value
 
227
  # DatasetオブジェクトをPandas DataFrameに変換
228
  df = select_dataset.value["train"].to_pandas()
229
 
230
+ # ランダム化実施
231
  # index列を追加し、シャッフル
232
  df = df.reset_index(drop=False) # 元のindexを保持
233
  df = df.sample(frac=1).reset_index(drop=True) # シャッフル
 
237
  select_dataset_total_len.value = len(df) # 長さを取得
238
  is_dataset_loaded.value = True # ロード完了
239
 
240
+ # データロード時にテキストの初期値を設定
241
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
242
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
243
 
 
245
  df.iloc[select_idx.value]["answer"], \
246
  df.iloc[select_idx.value]["question"], \
247
  df.iloc[select_idx.value]["answer"], \
248
+ df.iloc[select_idx.value]["question"], \
249
+ df.iloc[select_idx.value]["answer"], \
250
+ gr.update(interactive=True), \
251
+ gr.update(interactive=True), \
252
+ gr.update(interactive=True), \
253
+ gr.update(interactive=True), \
254
+ gr.update(interactive=True), \
255
+ gr.update(interactive=True), \
256
+ gr.update(interactive=True), \
257
+ gr.update(interactive=True), \
258
+ gr.update(interactive=True), \
259
+ gr.update(interactive=True), \
260
+ gr.update(interactive=True), \
261
+ gr.update(interactive=True), \
262
+ gr.update(interactive=True), \
263
+ gr.update(interactive=True), \
264
+ gr.update(interactive=True), \
265
+ gr.update(interactive=True), \
266
+ gr.update(interactive=True), \
267
+ gr.update(interactive=True), \
268
+ gr.update(interactive=True), \
269
+ gr.update(interactive=True), \
270
+ gr.update(interactive=True), \
271
+ gr.update(interactive=True), \
272
+ gr.update(interactive=True), \
273
+ gr.update(interactive=True), \
274
+ gr.update(interactive=True), \
275
+ gr.update(interactive=True), \
276
+ gr.update(interactive=True), \
277
+ gr.update(interactive=True), \
278
+ gr.update(interactive=True), \
279
+ gr.update(interactive=True), \
280
+ gr.update(interactive=True), \
281
  gr.update(interactive=True), \
282
  gr.update(interactive=True), \
283
  gr.update(interactive=True), \
 
296
  annotated_folder = annotation_file.parent
297
 
298
  scheduler = CommitScheduler(
299
+ repo_id=OUTPUT_DATASET[1],
300
  repo_type="dataset",
301
  folder_path=annotated_folder,
302
  path_in_repo="data", # Spaceの場合の保存先フォルダー
 
304
  every=5, # 5分毎にアップロード HuggingFAce_Documentの最低推奨値
305
  )
306
 
307
+ # チェックボックスをintに変換
308
+ def checkbox_to_int(checkbox_value) -> int:
309
+ if checkbox_value == "不明":
310
+ output = 0
311
+ elif checkbox_value == "有":
312
+ output = 1
313
+ elif checkbox_value == "無":
314
+ output = 2
315
+ else :
316
+ output = 0
317
+ print("error: ")
318
+ return output
319
+
320
  # CommitScheduler (HFへのデータアップロード
321
  def save_annotation(
322
  dataset_name: str,
323
  dataset_id: int,
324
  who: str,
325
+ unknown_quality: bool,
326
  good: bool,
327
  bad: bool,
 
 
328
  is_proofreading_1: bool,
329
  answer_text_1: str,
330
  is_proofreading_2: bool,
331
+ answer_text_2: str,
332
+ score: int,
333
+ helphulness: int,
334
+ correcthness: int,
335
+ coherence: int,
336
+ complexity: int,
337
+ verbosity: int,
338
+ humor: int,
339
+ creativity: int,
340
+ appropriate: int,
341
+ following_instructions: int,
342
+ politeness: int,
343
+ harmfulness: int,
344
+ hate: int,
345
+ sexual: int,
346
+ violence: int,
347
+ suicide: int,
348
+ threat: int,
349
+ gun: int,
350
+ controlled_substance: int,
351
+ climinal_planing: int,
352
+ privacy: int,
353
+ harassment: int,
354
+ profanity: int,
355
+ political_content: int,
356
+ moral_judgement: int,
357
+ typos: int,
358
+ ) -> None:
359
 
360
  annotated_dataset.value = pd.concat([
361
  annotated_dataset.value,
 
363
  'dataset_name': [dataset_name],
364
  'dataset_id': [dataset_id],
365
  'who': [who],
366
+ 'unknown_quality': [unknown_quality],
367
  'good': [good],
368
  'bad': [bad],
 
 
369
  'is_proofreading_1': [is_proofreading_1],
370
  "answer_text_1": [answer_text_1],
371
  'is_proofreading_2': [is_proofreading_2],
372
+ 'answer_text_2': [answer_text_2],
373
+ 'score': [score],
374
+ 'helphullness': [helphulness],
375
+ 'correcthness': [correcthness],
376
+ 'complexity': [complexity],
377
+ 'verbosity': [verbosity],
378
+ 'humor': [humor],
379
+ 'creativity': [creativity],
380
+ 'appropriate': [appropriate],
381
+ 'following_finstructions': [following_instructions],
382
+ 'politeness': [politeness],
383
+ 'harmfulness': [harmfulness],
384
+ 'hate': [hate],
385
+ 'sextual': [sexual],
386
+ 'violence': [violence],
387
+ 'suicide': [suicide],
388
+ 'threat': [threat],
389
+ 'gun': [gun],
390
+ 'controlled_substance': [controlled_substance],
391
+ 'climinal_planing': [climinal_planing],
392
+ 'privacy': [privacy],
393
+ 'harassment': [harassment],
394
+ 'profanity': [profanity],
395
+ 'political_content': [political_content],
396
+ 'moral_judgement': [moral_judgement],
397
+ 'types': [typos]
398
  })], ignore_index=True).reset_index(drop=True)
399
 
400
  # 書き込み
401
  with scheduler.lock:
402
  with annotation_file.open("a", encoding='utf-8') as f:
403
  data_to_write = {
404
+ # "id": , CommitSchedulerは、取得して末尾idを付与することが不可能?
405
  "datetime": str(datetime.datetime.now().isoformat()),
406
  "dataset_name": dataset_name,
407
  "dataset_id": int(dataset_id),
408
  "who": who,
409
+ "unknown_quality": unknown_quality,
410
  "good": good,
411
  "bad": bad,
 
 
412
  "is_proofreading_1": is_proofreading_1,
413
  "answer_text_1": answer_text_1,
414
  "is_proofreading_2": is_proofreading_2,
415
  "answer_text_2": answer_text_2,
416
+ "score": int(score),
417
+ "helphulness": int(helphulness),
418
+ "correcthness": int(correcthness),
419
+ "coherence": int(coherence),
420
+ "complexity": int(complexity),
421
+ "verbosity": int(verbosity),
422
+ "humor": int(humor),
423
+ "creativity": int(creativity),
424
+ "appropriate": int(appropriate),
425
+ "following_instructions": int(following_instructions),
426
+ "politeness": int(politeness),
427
+ "harmfulness": int(harmfulness),
428
+ "hate": int(hate),
429
+ "sexual": int(sexual),
430
+ "violence": int(violence),
431
+ "suicide": int(suicide),
432
+ "threat": int(threat),
433
+ "gun": int(gun),
434
+ "controlled_substance": int(controlled_substance),
435
+ "climinal_planing": int(climinal_planing),
436
+ "privacy": int(privacy),
437
+ "harassment": int(harassment),
438
+ "profanity": int(profanity),
439
+ "policital_content": int(political_content),
440
+ "moral_judgement": int(moral_judgement),
441
+ "typos": int(typos)
442
  }
443
  f.write(json.dumps(data_to_write, ensure_ascii=False))
444
  f.write("\n")
 
450
 
451
  # ユーザー名表示
452
 
 
453
  def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
454
  if profile is None:
455
  return "プライベートデータセット取得のためにログインしてください。", who.value
 
461
  theme_ = gr.themes.Default()
462
 
463
  # 後のCSSデザイン変更用
 
 
464
  def load_css():
465
  with open("style.css", "r") as file:
466
  css_content = file.read()
467
  return css_content
468
 
 
469
  # Gradio 画面 ============================================
470
  with gr.Blocks(theme=theme_, css=load_css()) as demo:
471
 
472
  gr.Markdown("# データセット アノテーション for Tanuki (Phase2)")
473
+
474
+ with gr.Row():
475
+ gr.Markdown("### GENIACにて開発中のLLM用データセットに対してアノテーションするSpaceです\n \
476
+ 入力されたデータは使用される可能性があるため、個人情報・秘匿情報などは入力しないでください。\n \
477
+ テスト中です。")
478
+ gr_who = gr.TextArea(value=who.value, lines=1, max_lines=1, label="ユーザー名 (入力してください)")
479
+
480
+ def change_name(name: str):
481
+ who.value = name
482
+
483
+ gr_who.change(
484
+ change_name,
485
+ inputs=[gr_who],
486
+ outputs=[]
487
+ )
488
 
489
  with gr.Tab("アノテーション (シングルターン)"):
490
 
491
+ # HF login 機能
492
+ # with gr.Row(equal_height=True):
493
+ # gr.LoginButton(value="HuggingFace ログイン",
494
+ # logout_value="HuggingFace ログアウト", scale=1)
 
495
  # ユーザー名
496
+ # gr_profile_name = gr.Markdown()
497
+ # demo.load(hello, inputs=None, outputs=[gr_profile_name, who])
498
 
499
  with gr.Row():
500
 
 
517
  gr_data_load_btn = gr.Button("② データセットを読み込む")
518
 
519
  with gr.Column() as content_column:
520
+
521
  with gr.Tab("③ シンプル(良・悪)"):
522
  with gr.Column():
523
  with gr.Row(equal_height=True):
524
+ gr_good_btn = gr.Button("良い", interactive=False)
525
+ gr_unknown_btn = gr.Button(
526
  "分からない", interactive=False) # 「分からない」ボタンを追加
527
+ gr_bad_btn = gr.Button("悪い", interactive=False)
528
 
529
+ gr_question_text_1_1 = gr.Textbox(
530
  label="質問: ", lines=5, interactive=False)
531
 
532
+ gr_answer_text_1_1 = gr.Textbox(
533
+ label="回答: 訂正して頂けると、品質が上がります。",
534
  lines=20,
535
+ interactive=False)
536
+
537
+ with gr.Tab("③ 5段階評価(シンプル)"):
538
+
539
+ with gr.Row() as simple_score_btn:
540
+ gr_score_5_btn = gr.Button("5: 高品質", interactive=False)
541
+ gr_score_4_btn = gr.Button("4: 良い", interactive=False)
542
+ gr_score_3_btn = gr.Button("3: 普通", interactive=False)
543
+ gr_score_2_btn = gr.Button("2: 悪い", interactive=False)
544
+ gr_score_1_btn = gr.Button("1: 低品質", interactive=False)
545
+
546
+ gr_question_text_2_1 = gr.Textbox(
547
+ label="質問: ", lines=5, interactive=False)
548
 
549
+ gr_answer_text_2_1 = gr.Textbox(
550
+ label="回答: 訂正して頂けると、品質が上がります。", lines=20, interactive=False)
551
+
552
+ with gr.Tab("③ 5段階評価 (詳細)"):
553
+
554
+ with gr.Row():
555
+
556
+ with gr.Column() as EvalFive:
557
+
558
+ gr_question_text_3_1 = gr.Textbox(
559
+ label="質問: ", lines=10, interactive=False)
560
+
561
+ # gr_explain = gr.Markdown("回答")
562
+
563
+ gr_answer_text_3_1 = gr.Textbox(
564
+ label="回答: 訂正して頂けると、品質が上がります。", lines=35, interactive=False)
565
+
566
+ with gr.Column() as EvalFiveDetail:
567
+
568
+ with gr.Row():
569
+ gr_submit_score = gr.Button("評価送信", interactive=False)
570
+ gr_score_reset = gr.Button("スコアリセット", interactive=False)
571
+
572
+ gr_score_detail = gr.Slider(label="総合スコア 【必須】",value=3, minimum=1, maximum=5, step=1, interactive=False)
573
+ gr_evalannotation_explain = gr.Markdown("詳細アノテーション (5点満点)")
574
+
575
+ with gr.Row() :
576
+ gr_helphulness = gr.Slider(label="有用性", minimum=0, value=0, maximum=5, step=1, interactive=False)
577
+ gr_correcthness = gr.Slider(label="正確さ", minimum=0, value=0, maximum=5, step=1, interactive=False)
578
+ gr_coherence = gr.Slider(label="一貫性", minimum=0, value=0, maximum=5, step=1, interactive=False)
579
+ gr_complexity = gr.Slider(label="複雑さ", minimum=0, value=0, maximum=5, step=1, interactive=False)
580
+
581
+ with gr.Row() :
582
+ gr_verbosity = gr.Slider(label="冗長性", minimum=0, value=0, maximum=5, step=1, interactive=False)
583
+ gr_humor = gr.Slider(label="ユーモア", minimum=0, value=0, maximum=5, step=1, interactive=False)
584
+ gr_creativity = gr.Slider(label="創造性", minimum=0, value=0, maximum=5, step=1, interactive=False)
585
+ gr_appropriate = gr.Slider(label="適切性", minimum=0, value=0, maximum=5, step=1, interactive=False)
586
+
587
+ with gr.Row() :
588
+ gr_following_instructions = gr.Slider(label="忠実性", minimum=0, value=0, maximum=5, step=1, interactive=False)
589
+ gr_politeness = gr.Slider(label="礼儀正しさ", minimum=0, value=0, maximum=5, step=1, interactive=False)
590
+ gr_harmfulness = gr.Slider(label="有害性", minimum=0, value=0, maximum=5, step=1, interactive=False)
591
+ gr_text_4 = gr.Markdown("判断可能な物のみ\n\nスコアを付けてください。")
592
+
593
+ gr_text_5 = gr.Markdown("")
594
+
595
+ with gr.Row():
596
+ gr_typos = gr.Radio(label="誤字・脱字", choices=["不明", "有", "無"], value="不明", interactive=False)
597
+ gr_moral_judgement = gr.Radio(label="非道徳", choices=["不明", "有", "無"], value="不明", interactive=False)
598
+
599
+ with gr.Row():
600
+ gr_hate = gr.Radio(label="ヘイト", choices=["不明", "有", "無"], value="不明", interactive=False)
601
+ gr_sexual = gr.Radio(label="性的内容", choices=["不明", "有", "無"], value="不明", interactive=False)
602
+
603
+ with gr.Row():
604
+ gr_violence = gr.Radio(label="暴力的", choices=["不明", "有", "無"], value="不��", interactive=False)
605
+ gr_suicide = gr.Radio(label="自殺行為", choices=["不明", "有", "無"], value="不明", interactive=False)
606
+
607
+ with gr.Row():
608
+ gr_threat = gr.Radio(label="犯罪", choices=["不明", "有", "無"], value="不明", interactive=False)
609
+ gr_gun = gr.Radio(label="銃等", choices=["不明", "有", "無"], value="不明", interactive=False)
610
+
611
+ with gr.Row():
612
+ gr_controlled_substance = gr.Radio(label="規制対象物質", choices=["不明", "有", "無"], value="不明", interactive=False)
613
+ gr_climinal_planing = gr.Radio(label="犯罪計画", choices=["不明", "有", "無"], value="不明", interactive=False)
614
+
615
+ with gr.Row():
616
+ gr_privacy = gr.Radio(label="個人情報", choices=["不明", "有", "無"], value="不明", interactive=False)
617
+ gr_harassment = gr.Radio(label="ハラスメント", choices=["不明", "有", "無"], value="不明", interactive=False)
618
+
619
+ with gr.Row():
620
+ gr_profanity = gr.Radio(label="冒涜行為", choices=["不明", "有", "無"], value="不明", interactive=False)
621
+ gr_political_content = gr.Radio(label="政治的内容", choices=["不明", "有", "無"], value="不明", interactive=False)
622
+
623
+
624
+ # 5段階評価 詳細のgr.State Update
625
+ def eval_submit(
626
+ # text
627
+ g_answer_text_3_1: str,
628
+
629
+ # slicer
630
+ g_score: int,
631
+ g_helphulness: int,
632
+ g_correcthness: int,
633
+ g_coherenece: int,
634
+ g_complexity: int,
635
+ g_verbosity: int,
636
+ g_humor: int,
637
+ g_creativity: int,
638
+ g_appropriate: int,
639
+ g_following_instructions: int,
640
+ g_politeness: int,
641
+ g_harmfulness: int,
642
+
643
+ # checkbox
644
+ g_hate: str,
645
+ g_sexual: str,
646
+ g_violence: str,
647
+ g_suicide: str,
648
+ g_threat: str,
649
+ g_gun: str,
650
+ g_controlled_substance: str,
651
+ g_climinal_planing: str,
652
+ g_privacy: str,
653
+ g_harassment: str,
654
+ g_profanity: str,
655
+ g_political_content: str,
656
+ g_moral_judgement: str,
657
+ g_typos: str,
658
+ ):
659
+ # 状態初期化
660
+ good.value = False
661
+ bad.value = False
662
+ unknown_quality.value = False
663
+
664
+ # テキストに更新があったかどうかチェック
665
+ if initial_answer_text_1.value != g_answer_text_3_1:
666
+ is_proofreading_1.value = True
667
+ answer_text_1.value = g_answer_text_3_1
668
+ else:
669
+ is_proofreading_1.value = False
670
+ answer_text_1.value = ""
671
+
672
+ # 送信用データ更新
673
+ score.value = g_score
674
+ helphulness.value = g_helphulness
675
+ correcthness.value = g_correcthness
676
+ coherenece.value = g_coherenece
677
+ complexity.value = g_complexity
678
+ verbosity.value = g_verbosity
679
+ humor.value = g_humor
680
+ creativity.value = g_creativity
681
+ appropriate.value = g_appropriate
682
+ following_instructions.value = g_following_instructions
683
+ politeness.value = g_politeness
684
+ harmfulness.value = g_harmfulness
685
+
686
+ hate.value = checkbox_to_int(g_hate)
687
+ sexual.value = checkbox_to_int(g_sexual)
688
+ violence.value = checkbox_to_int(g_violence)
689
+ suicide.value = checkbox_to_int(g_suicide)
690
+ threat.value = checkbox_to_int(g_threat)
691
+ gun.value = checkbox_to_int(g_gun)
692
+ controlled_substance.value = checkbox_to_int(g_controlled_substance)
693
+ climinal_planing.value = checkbox_to_int(g_climinal_planing)
694
+ privacy.value = checkbox_to_int(g_privacy)
695
+ harassment.value = checkbox_to_int(g_harassment)
696
+ profanity.value = checkbox_to_int(g_profanity)
697
+ political_content.value = checkbox_to_int(g_political_content)
698
+ moral_judgement.value = checkbox_to_int(g_moral_judgement)
699
+ typos.value = checkbox_to_int(g_typos)
700
+
701
+ # データ送信
702
+
703
+ # 表示更新
704
+ # indexを進める
705
+ select_idx.value += 1
706
 
707
+ df = select_dataset.value["train"]
 
708
 
709
+ # ループさせるか、エラー処理を行う
710
+ if select_idx.value >= len(df):
711
+ select_idx.value = 0
 
 
 
712
 
713
+ # データセットに追加
714
+ df = select_dataset.value["train"]
715
+ save_annotation(
716
+ select_dropdown_dataset.value,
717
+ df.iloc[select_idx.value]['index'],
718
+ who.value,
719
+ unknown_quality.value,
720
+ good.value,
721
+ bad.value,
722
+ is_proofreading_1.value,
723
+ answer_text_1.value,
724
+ is_proofreading_2.value,
725
+ answer_text_2.value,
726
+ score.value,
727
+ helphulness.value,
728
+ correcthness.value,
729
+ coherenece.value,
730
+ complexity.value,
731
+ verbosity.value,
732
+ humor.value,
733
+ creativity.value,
734
+ appropriate.value,
735
+ following_instructions.value,
736
+ politeness.value,
737
+ harmfulness.value,
738
+ hate.value,
739
+ sexual.value,
740
+ violence.value,
741
+ suicide.value,
742
+ threat.value,
743
+ gun.value,
744
+ controlled_substance.value,
745
+ climinal_planing.value,
746
+ privacy.value,
747
+ harassment.value,
748
+ profanity.value,
749
+ political_content.value,
750
+ moral_judgement.value,
751
+ typos.value,
752
+ )
753
+
754
+ # Nextデータ初期化
755
+ initialize_next_data(df)
756
+
757
+ # 5段階評価をリセット
758
+ score_reset_display()
759
+
760
+ # UI更新のための返り値
761
+ return gr.update(value=df.iloc[select_idx.value]["question"]), \
762
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
763
+ gr.update(value=df.iloc[select_idx.value]["question"]), \
764
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
765
+ gr.update(value=df.iloc[select_idx.value]["question"]), \
766
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
767
+ *score_reset_display() # スコアリセット用の返り値
768
+
769
+ gr_submit_score.click(
770
+ eval_submit,
771
+ inputs=[
772
+ gr_answer_text_3_1,
773
+ gr_score_detail,
774
+ gr_helphulness,
775
+ gr_correcthness,
776
+ gr_coherence,
777
+ gr_complexity,
778
+ gr_verbosity,
779
+ gr_humor,
780
+ gr_creativity,
781
+ gr_appropriate,
782
+ gr_following_instructions,
783
+ gr_politeness,
784
+ gr_harmfulness,
785
+ gr_hate,
786
+ gr_sexual,
787
+ gr_violence,
788
+ gr_suicide,
789
+ gr_threat,
790
+ gr_gun,
791
+ gr_controlled_substance,
792
+ gr_climinal_planing,
793
+ gr_privacy,
794
+ gr_harassment,
795
+ gr_profanity,
796
+ gr_political_content,
797
+ gr_moral_judgement,
798
+ gr_typos
799
+ ],
800
+ # UI更新
801
+ outputs=[
802
+ gr_question_text_1_1,
803
+ gr_answer_text_1_1,
804
+ gr_question_text_2_1,
805
+ gr_answer_text_2_1,
806
+ gr_question_text_3_1,
807
+ gr_answer_text_3_1,
808
+ gr_score_detail,
809
+ gr_helphulness,
810
+ gr_correcthness,
811
+ gr_coherence,
812
+ gr_complexity,
813
+ gr_verbosity,
814
+ gr_humor,
815
+ gr_creativity,
816
+ gr_appropriate,
817
+ gr_following_instructions,
818
+ gr_politeness,
819
+ gr_harmfulness,
820
+ gr_hate,
821
+ gr_sexual,
822
+ gr_violence,
823
+ gr_suicide,
824
+ gr_threat,
825
+ gr_gun,
826
+ gr_controlled_substance,
827
+ gr_climinal_planing,
828
+ gr_privacy,
829
+ gr_harassment,
830
+ gr_profanity,
831
+ gr_political_content,
832
+ gr_moral_judgement,
833
+ gr_typos
834
+ ],
835
+ )
836
 
837
  # 5段階評価ボタンのクリックイベントを定義
838
  def score_button_clicked(button_value):
839
+ # 状態初期化
840
  good.value = False
841
  bad.value = False
842
+ unknown_quality.value = False
843
+ score.value = button_value
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
844
 
845
+ # 5段階評価クリック
846
  def update_annotation(
847
  input_ans_1: str = None,
848
+ input_ans_2: str = None,
849
  is_good: bool = None, # good/bad を表すフラグを追加
850
  is_unknown: bool = None, # 「分からない」を表すフラグを追加
851
+ is_simple: bool = None,
852
  score_value: int = None # 5段階評価の値、good/badの場合はNone
853
+ ) -> Tuple[
854
+ gr.update,
855
+ gr.update,
856
+ gr.update,
857
+ gr.update,
858
+ gr.update,
859
+ ]:
860
 
861
  # good/bad/unknown と score の状態を更新
862
  update_evaluation_state(is_good, is_unknown, score_value)
863
 
864
  # 変更を検知 (5段階評価の場合も処理するように変更)
865
+ update_answer_state(input_ans_1, input_ans_2)
866
+
867
  # 表示更新
868
  # indexを進める
869
  select_idx.value += 1
 
873
  # ループさせるか、エラー処理を行う
874
  if select_idx.value >= len(df):
875
  select_idx.value = 0
876
+
877
+ # シンプルモードクリックで、scoreを0に設定
878
+ if is_simple == True:
879
+ score.value = 0
880
 
881
  # データセットに追加
882
+ # 元のindex番号(dataset_id)を指定して保存
883
  save_annotation_data(df)
884
 
885
  # Nextデータ初期化
886
  initialize_next_data(df)
887
+
888
+ # 5段階評価をリセット
889
+ reset_values = score_reset_display()
890
 
891
  return gr.update(value=df.iloc[select_idx.value]["question"]), \
892
  gr.update(value=df.iloc[select_idx.value]["answer"]), \
893
  gr.update(value=df.iloc[select_idx.value]["question"]), \
894
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
895
+ gr.update(value=df.iloc[select_idx.value]["question"]), \
896
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
897
+ *reset_values
898
+
899
 
900
+ # 評価状態リセット
901
  def update_evaluation_state(is_good, is_unknown, score_value):
902
  if score_value is not None: # 5段階評価の場合
903
  good.value = False
 
909
  bad.value = not is_good if not is_unknown else False
910
  unknown_quality.value = is_unknown # 「分からない」の状態を設定
911
 
912
+ # 変更を検知して値を設定
913
+ def update_answer_state(input_ans_1, input_ans_2):
914
  if input_ans_1 is not None and initial_answer_text_1.value != input_ans_1:
915
  is_proofreading_1.value = True
916
  answer_text_1.value = input_ans_1
917
  else:
918
  answer_text_1.value = ""
919
 
920
+ # 2ターン目用
921
+ if input_ans_2 is not None and initial_answer_text_2.value != input_ans_2:
922
  is_proofreading_2.value = True
923
+ answer_text_2.value = input_ans_2
924
  else:
925
  answer_text_2.value = ""
926
 
927
+ # データ保存
928
  def save_annotation_data(df):
929
  save_annotation(
930
  select_dropdown_dataset.value,
931
  # datasetIdは元のindex番号を使用
932
  df.iloc[select_idx.value]['index'],
933
  who.value,
934
+ unknown_quality.value,
935
  good.value,
936
  bad.value,
 
 
937
  is_proofreading_1.value,
938
  answer_text_1.value,
939
  is_proofreading_2.value,
940
+ answer_text_2.value,
941
+ score.value,
942
+ helphulness.value,
943
+ correcthness.value,
944
+ coherenece.value,
945
+ complexity.value,
946
+ verbosity.value,
947
+ humor.value,
948
+ creativity.value,
949
+ appropriate.value,
950
+ following_instructions.value,
951
+ politeness.value,
952
+ harmfulness.value,
953
+ hate.value,
954
+ sexual.value,
955
+ violence.value,
956
+ suicide.value,
957
+ threat.value,
958
+ gun.value,
959
+ controlled_substance.value,
960
+ climinal_planing.value,
961
+ privacy.value,
962
+ harassment.value,
963
+ profanity.value,
964
+ political_content.value,
965
+ moral_judgement.value,
966
+ typos.value,
967
  )
968
 
969
+ # 次データ読込時の初期化
970
  def initialize_next_data(df):
971
  is_proofreading_1.value = False
972
  is_proofreading_2.value = False
973
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
974
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
975
+
976
+ # 評価不可
977
+ def unknown_click(input_ans_1, input_ans_2):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
978
  good.value = False
979
  bad.value = False
980
+ score_reset_display()
981
+ return update_annotation(
982
+ input_ans_1=input_ans_1,
983
+ input_ans_2=input_ans_2,
984
+ is_good=False,
985
+ is_unknown=True,
986
+ is_simple=True,
987
+ )
988
+
989
+ # 評価不可クリックイベント
990
+ gr_unknown_btn.click(
991
  unknown_click,
992
  inputs=[
993
+ gr_answer_text_1_1,
994
+ gr_answer_text_2_1
995
  ],
996
+ outputs=[
997
+ gr_question_text_1_1,
998
+ gr_answer_text_1_1,
999
+ gr_question_text_2_1,
1000
+ gr_answer_text_2_1,
1001
+ gr_question_text_3_1,
1002
+ gr_answer_text_3_1,
1003
+ gr_score_detail,
1004
+ gr_helphulness,
1005
+ gr_correcthness,
1006
+ gr_coherence,
1007
+ gr_complexity,
1008
+ gr_verbosity,
1009
+ gr_humor,
1010
+ gr_creativity,
1011
+ gr_appropriate,
1012
+ gr_following_instructions,
1013
+ gr_politeness,
1014
+ gr_harmfulness,
1015
+ gr_hate,
1016
+ gr_sexual,
1017
+ gr_violence,
1018
+ gr_suicide,
1019
+ gr_threat,
1020
+ gr_gun,
1021
+ gr_controlled_substance,
1022
+ gr_climinal_planing,
1023
+ gr_privacy,
1024
+ gr_harassment,
1025
+ gr_profanity,
1026
+ gr_political_content,
1027
+ gr_moral_judgement,
1028
+ gr_typos
1029
+ ]
1030
  )
1031
 
1032
+ # 良いクリック
1033
+ def good_click(input_ans_1, input_ans_2):
1034
+ score_reset_display()
1035
+ return update_annotation(
1036
+ input_ans_1=input_ans_1,
1037
+ input_ans_2=input_ans_2,
1038
+ is_good=True,
1039
+ is_unknown=False,
1040
+ is_simple=True,
1041
+ )
1042
+
1043
+ # 良いクリック
1044
+ gr_good_btn.click(
1045
+ good_click,
1046
+ inputs=[
1047
+ gr_answer_text_1_1,
1048
+ gr_answer_text_2_1
1049
+ ],
1050
+ outputs=[
1051
+ gr_question_text_1_1,
1052
+ gr_answer_text_1_1,
1053
+ gr_question_text_2_1,
1054
+ gr_answer_text_2_1,
1055
+ gr_question_text_3_1,
1056
+ gr_answer_text_3_1,
1057
+ gr_score_detail,
1058
+ gr_helphulness,
1059
+ gr_correcthness,
1060
+ gr_coherence,
1061
+ gr_complexity,
1062
+ gr_verbosity,
1063
+ gr_humor,
1064
+ gr_creativity,
1065
+ gr_appropriate,
1066
+ gr_following_instructions,
1067
+ gr_politeness,
1068
+ gr_harmfulness,
1069
+ gr_hate,
1070
+ gr_sexual,
1071
+ gr_violence,
1072
+ gr_suicide,
1073
+ gr_threat,
1074
+ gr_gun,
1075
+ gr_controlled_substance,
1076
+ gr_climinal_planing,
1077
+ gr_privacy,
1078
+ gr_harassment,
1079
+ gr_profanity,
1080
+ gr_political_content,
1081
+ gr_moral_judgement,
1082
+ gr_typos
1083
+ ]
1084
+ )
1085
+
1086
+ # 低評価クリック
1087
+ def bad_click(input_ans_1, input_ans_2):
1088
+ score_reset_display()
1089
+ return update_annotation(
1090
+ input_ans_1=input_ans_1,
1091
+ input_ans_2=input_ans_2,
1092
+ is_good=False,
1093
+ is_unknown=False,
1094
+ is_simple=True,
1095
+ )
1096
+
1097
+ # 低評価クリックイベント
1098
+ gr_bad_btn.click(
1099
  bad_click,
1100
  inputs=[
1101
+ gr_answer_text_1_1,
1102
+ gr_answer_text_2_1
1103
  ],
1104
+ outputs=[
1105
+ gr_question_text_1_1,
1106
+ gr_answer_text_1_1,
1107
+ gr_question_text_2_1,
1108
+ gr_answer_text_2_1,
1109
+ gr_question_text_3_1,
1110
+ gr_answer_text_3_1,
1111
+ gr_score_detail,
1112
+ gr_helphulness,
1113
+ gr_correcthness,
1114
+ gr_coherence,
1115
+ gr_complexity,
1116
+ gr_verbosity,
1117
+ gr_humor,
1118
+ gr_creativity,
1119
+ gr_appropriate,
1120
+ gr_following_instructions,
1121
+ gr_politeness,
1122
+ gr_harmfulness,
1123
+ gr_hate,
1124
+ gr_sexual,
1125
+ gr_violence,
1126
+ gr_suicide,
1127
+ gr_threat,
1128
+ gr_gun,
1129
+ gr_controlled_substance,
1130
+ gr_climinal_planing,
1131
+ gr_privacy,
1132
+ gr_harassment,
1133
+ gr_profanity,
1134
+ gr_political_content,
1135
+ gr_moral_judgement,
1136
+ gr_typos
1137
+ ]
1138
  )
1139
 
1140
  # 5段階評価ボタンのクリックイベント
1141
+ gr_score_1_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=1),
1142
+ inputs=[gr_answer_text_2_1],
1143
+ outputs=[
1144
+ gr_question_text_1_1,
1145
+ gr_answer_text_1_1,
1146
+ gr_question_text_2_1,
1147
+ gr_answer_text_2_1,
1148
+ gr_question_text_3_1,
1149
+ gr_answer_text_3_1,
1150
+ gr_score_detail,
1151
+ gr_helphulness,
1152
+ gr_correcthness,
1153
+ gr_coherence,
1154
+ gr_complexity,
1155
+ gr_verbosity,
1156
+ gr_humor,
1157
+ gr_creativity,
1158
+ gr_appropriate,
1159
+ gr_following_instructions,
1160
+ gr_politeness,
1161
+ gr_harmfulness,
1162
+ gr_hate,
1163
+ gr_sexual,
1164
+ gr_violence,
1165
+ gr_suicide,
1166
+ gr_threat,
1167
+ gr_gun,
1168
+ gr_controlled_substance,
1169
+ gr_climinal_planing,
1170
+ gr_privacy,
1171
+ gr_harassment,
1172
+ gr_profanity,
1173
+ gr_political_content,
1174
+ gr_moral_judgement,
1175
+ gr_typos
1176
+ ])
1177
+ gr_score_2_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=2),
1178
+ inputs=[gr_answer_text_2_1],
1179
+ outputs=[
1180
+ gr_question_text_1_1,
1181
+ gr_answer_text_1_1,
1182
+ gr_question_text_2_1,
1183
+ gr_answer_text_2_1,
1184
+ gr_question_text_3_1,
1185
+ gr_answer_text_3_1,
1186
+ gr_score_detail,
1187
+ gr_helphulness,
1188
+ gr_correcthness,
1189
+ gr_coherence,
1190
+ gr_complexity,
1191
+ gr_verbosity,
1192
+ gr_humor,
1193
+ gr_creativity,
1194
+ gr_appropriate,
1195
+ gr_following_instructions,
1196
+ gr_politeness,
1197
+ gr_harmfulness,
1198
+ gr_hate,
1199
+ gr_sexual,
1200
+ gr_violence,
1201
+ gr_suicide,
1202
+ gr_threat,
1203
+ gr_gun,
1204
+ gr_controlled_substance,
1205
+ gr_climinal_planing,
1206
+ gr_privacy,
1207
+ gr_harassment,
1208
+ gr_profanity,
1209
+ gr_political_content,
1210
+ gr_moral_judgement,
1211
+ gr_typos
1212
+ ])
1213
+ gr_score_3_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=3),
1214
+ inputs=[gr_answer_text_2_1],
1215
+ outputs=[
1216
+ gr_question_text_1_1,
1217
+ gr_answer_text_1_1,
1218
+ gr_question_text_2_1,
1219
+ gr_answer_text_2_1,
1220
+ gr_question_text_3_1,
1221
+ gr_answer_text_3_1,
1222
+ gr_score_detail,
1223
+ gr_helphulness,
1224
+ gr_correcthness,
1225
+ gr_coherence,
1226
+ gr_complexity,
1227
+ gr_verbosity,
1228
+ gr_humor,
1229
+ gr_creativity,
1230
+ gr_appropriate,
1231
+ gr_following_instructions,
1232
+ gr_politeness,
1233
+ gr_harmfulness,
1234
+ gr_hate,
1235
+ gr_sexual,
1236
+ gr_violence,
1237
+ gr_suicide,
1238
+ gr_threat,
1239
+ gr_gun,
1240
+ gr_controlled_substance,
1241
+ gr_climinal_planing,
1242
+ gr_privacy,
1243
+ gr_harassment,
1244
+ gr_profanity,
1245
+ gr_political_content,
1246
+ gr_moral_judgement,
1247
+ gr_typos
1248
+ ])
1249
+ gr_score_4_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=4),
1250
+ inputs=[gr_answer_text_2_1],
1251
+ outputs=[
1252
+ gr_question_text_1_1,
1253
+ gr_answer_text_1_1,
1254
+ gr_question_text_2_1,
1255
+ gr_answer_text_2_1,
1256
+ gr_question_text_3_1,
1257
+ gr_answer_text_3_1,
1258
+ gr_score_detail,
1259
+ gr_helphulness,
1260
+ gr_correcthness,
1261
+ gr_coherence,
1262
+ gr_complexity,
1263
+ gr_verbosity,
1264
+ gr_humor,
1265
+ gr_creativity,
1266
+ gr_appropriate,
1267
+ gr_following_instructions,
1268
+ gr_politeness,
1269
+ gr_harmfulness,
1270
+ gr_hate,
1271
+ gr_sexual,
1272
+ gr_violence,
1273
+ gr_suicide,
1274
+ gr_threat,
1275
+ gr_gun,
1276
+ gr_controlled_substance,
1277
+ gr_climinal_planing,
1278
+ gr_privacy,
1279
+ gr_harassment,
1280
+ gr_profanity,
1281
+ gr_political_content,
1282
+ gr_moral_judgement,
1283
+ gr_typos
1284
+ ])
1285
+ gr_score_5_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=5),
1286
+ inputs=[gr_answer_text_2_1],
1287
+ outputs=[
1288
+ gr_question_text_1_1,
1289
+ gr_answer_text_1_1,
1290
+ gr_question_text_2_1,
1291
+ gr_answer_text_2_1,
1292
+ gr_question_text_3_1,
1293
+ gr_answer_text_3_1,
1294
+ gr_score_detail,
1295
+ gr_helphulness,
1296
+ gr_correcthness,
1297
+ gr_coherence,
1298
+ gr_complexity,
1299
+ gr_verbosity,
1300
+ gr_humor,
1301
+ gr_creativity,
1302
+ gr_appropriate,
1303
+ gr_following_instructions,
1304
+ gr_politeness,
1305
+ gr_harmfulness,
1306
+ gr_hate,
1307
+ gr_sexual,
1308
+ gr_violence,
1309
+ gr_suicide,
1310
+ gr_threat,
1311
+ gr_gun,
1312
+ gr_controlled_substance,
1313
+ gr_climinal_planing,
1314
+ gr_privacy,
1315
+ gr_harassment,
1316
+ gr_profanity,
1317
+ gr_political_content,
1318
+ gr_moral_judgement,
1319
+ gr_typos
1320
+ ])
1321
+
1322
+ # Scoreリセット
1323
+ def score_reset_display():
1324
+ # gr.State
1325
+ score.value = 3
1326
+ helphulness.value = 0
1327
+ correcthness.value = 0
1328
+ coherenece.value = 0
1329
+ complexity.value = 0
1330
+ verbosity.value = 0
1331
+ humor.value = 0
1332
+ creativity.value = 0
1333
+ appropriate.value = 0
1334
+ following_instructions.value = 0
1335
+ politeness.value = 0
1336
+ harmfulness.value = 0
1337
+ hate.value = 0
1338
+ sexual.value = 0
1339
+ violence.value = 0
1340
+ suicide.value = 0
1341
+ threat.value = 0
1342
+ gun.value = 0
1343
+ controlled_substance.vlaue = 0
1344
+ climinal_planing.value = 0
1345
+ privacy.value = 0
1346
+ harassment.value = 0
1347
+ profanity.value = 0
1348
+ political_content.value = 0
1349
+ moral_judgement.value = 0
1350
+ typos.value = 0
1351
+
1352
+ return 3,0,0,0,0,0,0,0,0,0,0,0, \
1353
+ "不明", "不明", "不明", "不明", "不明", \
1354
+ "不明", "不明", "不明", "不明", "不明", \
1355
+ "不明", "不明", "不明", "不明"
1356
+
1357
+ # Scoreリセット
1358
+ gr_score_reset.click(
1359
+ score_reset_display,
1360
+ inputs=[],
1361
+ outputs=[
1362
+ gr_score_detail,
1363
+ gr_helphulness,
1364
+ gr_correcthness,
1365
+ gr_coherence,
1366
+ gr_complexity,
1367
+ gr_verbosity,
1368
+ gr_humor,
1369
+ gr_creativity,
1370
+ gr_appropriate,
1371
+ gr_following_instructions,
1372
+ gr_politeness,
1373
+ gr_harmfulness,
1374
+ gr_hate,
1375
+ gr_sexual,
1376
+ gr_violence,
1377
+ gr_suicide,
1378
+ gr_threat,
1379
+ gr_gun,
1380
+ gr_controlled_substance,
1381
+ gr_climinal_planing,
1382
+ gr_privacy,
1383
+ gr_harassment,
1384
+ gr_profanity,
1385
+ gr_political_content,
1386
+ gr_moral_judgement,
1387
+ gr_typos
1388
+ ]
1389
+ )
1390
+
1391
+ # データ読込
1392
+ gr_data_load_btn.click(
1393
+ dataset_load_fn,
1394
+ inputs=None,
1395
+ # textをセットし、intractiveをTrueにする (UI更新)
1396
+ outputs=[
1397
+ gr_question_text_1_1,
1398
+ gr_answer_text_1_1,
1399
+ gr_question_text_2_1,
1400
+ gr_answer_text_2_1,
1401
+ gr_question_text_3_1,
1402
+ gr_answer_text_3_1,
1403
+ gr_answer_text_1_1,
1404
+ gr_answer_text_2_1,
1405
+ gr_answer_text_3_1,
1406
+ gr_unknown_btn,
1407
+ gr_good_btn,
1408
+ gr_bad_btn,
1409
+ gr_score_5_btn,
1410
+ gr_score_4_btn,
1411
+ gr_score_3_btn,
1412
+ gr_score_2_btn,
1413
+ gr_score_1_btn,
1414
+ gr_submit_score,
1415
+ gr_score_detail,
1416
+ gr_score_reset,
1417
+ gr_helphulness,
1418
+ gr_correcthness,
1419
+ gr_coherence,
1420
+ gr_complexity,
1421
+ gr_verbosity,
1422
+ gr_humor,
1423
+ gr_creativity,
1424
+ gr_appropriate,
1425
+ gr_following_instructions,
1426
+ gr_politeness,
1427
+ gr_harmfulness,
1428
+ gr_hate,
1429
+ gr_sexual,
1430
+ gr_violence,
1431
+ gr_suicide,
1432
+ gr_threat,
1433
+ gr_gun,
1434
+ gr_controlled_substance,
1435
+ gr_climinal_planing,
1436
+ gr_privacy,
1437
+ gr_harassment,
1438
+ gr_profanity,
1439
+ gr_political_content,
1440
+ gr_moral_judgement,
1441
+ gr_typos
1442
+ ]
1443
+ )
1444
+
1445
  # TODO Tab切り替えで、アノテ済みの一覧を表示する
1446
  # with gr.Tab("アノテ済みデータセット(管理画面)"):
1447
  # タブを切り替えた時にデータ表示を更新する
run.py CHANGED
@@ -28,14 +28,14 @@ else:
28
  print("Warning: HF_TOKEN not found. Please set it in your Space secrets.")
29
 
30
  # HFデータセット アップロード先
31
- # (切替てテストする用に配列)
32
- output_dataset = [
33
  "team-hatakeyama-phase2/annotation_tanuki_phase2",
34
  "kevineen/Tanuki-Phase2-annotation-dataset", # 出力テスト
35
  ]
36
 
37
  # アノテーション対象データセット
38
- annotation_dataset_list = [
39
  "hatakeyama-llm-team/AutoGeneratedJapaneseQA",
40
  "hatakeyama-llm-team/AutoGeneratedJapaneseQA-other",
41
  "kanhatakeyama/ChatbotArenaJaMixtral8x22b",
@@ -46,9 +46,11 @@ annotation_dataset_list = [
46
  # "hatakeyama-llm-team/WikiBookJa",
47
  # "kanhatakeyama/AutoWikiQA",
48
  # "susumuota/SyntheticTextWikiTranslate-askllm-v1", # Ask-LLM 翻訳
 
 
49
  ]
50
 
51
- multi_turn_annotation_dataset_list = [
52
  # マルチターン 未対応
53
  "kanhatakeyama/AutoMultiTurnByMixtral8x22b",
54
  ]
@@ -60,56 +62,152 @@ is_selected_dataset = gr.State(False)
60
  is_loaded_dataset = gr.State(False)
61
 
62
  # 選択中のデータセットリスト
63
- dropdown_dataset_list = gr.State(value=annotation_dataset_list)
 
64
  # 現在の対象データセット 初期値は"hatakeyama-llm-team/AutoGeneratedJapaneseQA",
65
  select_dropdown_dataset = gr.State(dropdown_dataset_list.value[0])
66
  select_dataset = gr.State(None) # 現在のデータセット
67
  select_dataset_total_len = gr.State(0) # 現在のデータセットの長さ
68
  select_idx = gr.State(0) # 現在のインデックス (ランダムモードにするなら不要?
69
- random_mode = gr.State(False)
70
 
71
  # 回答者がアノテーションしたデータセット
72
  annotated_dataset = gr.State(
73
  pd.DataFrame({
74
- 'dataset_name': [],
75
- 'dataset_id': [],
76
- 'who': [],
77
- 'good': [],
78
- 'bad': [],
79
- 'unknown_quality': [], # 新しいデータフィールドを追加
80
- 'score': [],
81
- 'is_proofreading_1': [],
82
  'answer_text_1': [],
83
- 'is_proofreading_2': [], # マルチターン用
84
- 'answer_text_2': [], # マルチターン用
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  })
86
  )
87
 
88
- initial_answer_text_1 = gr.State("") # 回答1を整形したかチェック用
89
- initial_answer_text_2 = gr.State("") # 回答2を整形したかチェック用
90
-
91
- is_dataset_loaded = gr.State(False)
92
 
93
  you_dataset_id = gr.State(0) # 回答者がアノテーションしているデータのID
94
  dataset_name = gr.State("") # 編集に使用したデータセット名
95
  dataset_id = gr.State(0) # 加工元データセットのindex
96
  who = gr.State("") # アノテーション者名
 
 
 
97
  good = gr.State(False) # 良
98
  bad = gr.State(False) # 悪
99
- unknown_quality = gr.State(False) # 分からない # 新しいデータフィールドを追加
100
- score = gr.State(3) # スコア 初期値は3
 
 
101
  is_proofreading_1 = gr.State(False) # 回答1を整形したか_1
102
  answer_text_1 = gr.State("") # answer_1 回答
103
  is_proofreading_2 = gr.State(False) # 回答2を整形したか_2
104
  answer_text_2 = gr.State("") # answer_2 回答
105
 
106
- # 未整理
107
- # データ読み込み ========================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  def dataset_load_fn() -> Tuple[
109
  str,
110
  str,
111
  str,
112
  str,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  gr.update,
114
  gr.update,
115
  gr.update,
@@ -118,9 +216,11 @@ def dataset_load_fn() -> Tuple[
118
  gr.update,
119
  gr.update,
120
  gr.update,
121
- gr.update]:
 
 
122
 
123
- is_dataset_loaded.value = False # ロード状態
124
 
125
  select_dataset.value = load_dataset(
126
  select_dropdown_dataset.value
@@ -129,6 +229,7 @@ def dataset_load_fn() -> Tuple[
129
  # DatasetオブジェクトをPandas DataFrameに変換
130
  df = select_dataset.value["train"].to_pandas()
131
 
 
132
  # index列を追加し、シャッフル
133
  df = df.reset_index(drop=False) # 元のindexを保持
134
  df = df.sample(frac=1).reset_index(drop=True) # シャッフル
@@ -138,7 +239,7 @@ def dataset_load_fn() -> Tuple[
138
  select_dataset_total_len.value = len(df) # 長さを取得
139
  is_dataset_loaded.value = True # ロード完了
140
 
141
- # データロード時に初期値を設定
142
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
143
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
144
 
@@ -146,6 +247,39 @@ def dataset_load_fn() -> Tuple[
146
  df.iloc[select_idx.value]["answer"], \
147
  df.iloc[select_idx.value]["question"], \
148
  df.iloc[select_idx.value]["answer"], \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  gr.update(interactive=True), \
150
  gr.update(interactive=True), \
151
  gr.update(interactive=True), \
@@ -164,7 +298,7 @@ annotation_file = Path("user_annotation/") / f"data_{uuid.uuid4()}.json"
164
  annotated_folder = annotation_file.parent
165
 
166
  scheduler = CommitScheduler(
167
- repo_id=output_dataset[1],
168
  repo_type="dataset",
169
  folder_path=annotated_folder,
170
  path_in_repo="data", # Spaceの場合の保存先フォルダー
@@ -172,19 +306,58 @@ scheduler = CommitScheduler(
172
  every=5, # 5分毎にアップロード HuggingFAce_Documentの最低推奨値
173
  )
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  # CommitScheduler (HFへのデータアップロード
176
  def save_annotation(
177
  dataset_name: str,
178
  dataset_id: int,
179
  who: str,
 
180
  good: bool,
181
  bad: bool,
182
- unknown_quality: bool,
183
- score: int,
184
  is_proofreading_1: bool,
185
  answer_text_1: str,
186
  is_proofreading_2: bool,
187
- answer_text_2: str) -> None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
  annotated_dataset.value = pd.concat([
190
  annotated_dataset.value,
@@ -192,33 +365,82 @@ def save_annotation(
192
  'dataset_name': [dataset_name],
193
  'dataset_id': [dataset_id],
194
  'who': [who],
 
195
  'good': [good],
196
  'bad': [bad],
197
- 'unknown_quality': [unknown_quality],
198
- 'score': [score],
199
  'is_proofreading_1': [is_proofreading_1],
200
  "answer_text_1": [answer_text_1],
201
  'is_proofreading_2': [is_proofreading_2],
202
- 'answer_text_2': [answer_text_2]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  })], ignore_index=True).reset_index(drop=True)
204
 
205
  # 書き込み
206
  with scheduler.lock:
207
  with annotation_file.open("a", encoding='utf-8') as f:
208
  data_to_write = {
209
- # "id": , CommitSchedulerだと取得して末尾idを付与することが無理?
210
  "datetime": str(datetime.datetime.now().isoformat()),
211
  "dataset_name": dataset_name,
212
  "dataset_id": int(dataset_id),
213
  "who": who,
 
214
  "good": good,
215
  "bad": bad,
216
- "unknown_quality": unknown_quality, # 新しいデータフィールドを追加
217
- "score": score,
218
  "is_proofreading_1": is_proofreading_1,
219
  "answer_text_1": answer_text_1,
220
  "is_proofreading_2": is_proofreading_2,
221
  "answer_text_2": answer_text_2,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  }
223
  f.write(json.dumps(data_to_write, ensure_ascii=False))
224
  f.write("\n")
@@ -230,7 +452,6 @@ def save_annotation(
230
 
231
  # ユーザー名表示
232
 
233
-
234
  def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
235
  if profile is None:
236
  return "プライベートデータセット取得のためにログインしてください。", who.value
@@ -242,30 +463,40 @@ def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
242
  theme_ = gr.themes.Default()
243
 
244
  # 後のCSSデザイン変更用
245
-
246
-
247
  def load_css():
248
  with open("style.css", "r") as file:
249
  css_content = file.read()
250
  return css_content
251
 
252
-
253
  # Gradio 画面 ============================================
254
  with gr.Blocks(theme=theme_, css=load_css()) as demo:
255
 
256
  gr.Markdown("# データセット アノテーション for Tanuki (Phase2)")
257
- gr.Markdown("### GENIACにて開発中のLLM用データセットに対してアノテーションするSpaceです\n入力されたデータは使用される可能性があるため、個人情報・秘匿情報などは入力しないでください。\nテスト中です。")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
 
259
  with gr.Tab("アノテーション (シングルターン)"):
260
 
261
- with gr.Row(equal_height=True):
262
-
263
- gr.LoginButton(value="HuggingFace ログイン",
264
- logout_value="HuggingFace ログアウト", scale=1)
265
-
266
  # ユーザー名
267
- gr_profile_name = gr.Markdown()
268
- demo.load(hello, inputs=None, outputs=[gr_profile_name, who])
269
 
270
  with gr.Row():
271
 
@@ -288,76 +519,353 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
288
  gr_data_load_btn = gr.Button("② データセットを読み込む")
289
 
290
  with gr.Column() as content_column:
 
291
  with gr.Tab("③ シンプル(良・悪)"):
292
  with gr.Column():
293
  with gr.Row(equal_height=True):
294
- good_btn = gr.Button("良い", interactive=False)
295
- unknown_btn = gr.Button(
296
  "分からない", interactive=False) # 「分からない」ボタンを追加
297
- bad_btn = gr.Button("悪い", interactive=False)
298
 
299
- gr_question_text_1 = gr.Textbox(
300
  label="質問: ", lines=5, interactive=False)
301
 
302
- gr_answer_text_1 = gr.Textbox(
303
- label="回答: 訂正頂けると品質が上がります。",
304
  lines=20,
305
- interactive=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
 
307
- with gr.Tab("③ ���段階評価"):
308
 
309
- gr_question_text_3 = gr.Textbox(
310
- label="質問: ", lines=5, interactive=False)
 
311
 
312
- with gr.Row() as score_btn:
313
- gr_score_5 = gr.Button("5: 高品質", interactive=False)
314
- gr_score_4 = gr.Button("4: 良い", interactive=False)
315
- gr_score_3 = gr.Button("3: 普通", interactive=False)
316
- gr_score_2 = gr.Button("2: 悪い", interactive=False)
317
- gr_score_1 = gr.Button("1: 低品質", interactive=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
 
319
- gr_answer_text_3 = gr.Textbox(
320
- label="回答: 訂正して頂けると品質が上がります。", lines=20, interactive=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
 
322
  # 5段階評価ボタンのクリックイベントを定義
323
  def score_button_clicked(button_value):
 
324
  good.value = False
325
  bad.value = False
326
- unknown_quality.value = False # 「分からない」の状態をリセット
327
- score.value = button_value
328
-
329
- gr_data_load_btn.click(
330
- dataset_load_fn,
331
- inputs=None,
332
- outputs=[gr_question_text_1,
333
- gr_answer_text_1,
334
- gr_question_text_3,
335
- gr_answer_text_3,
336
- good_btn,
337
- unknown_btn, # 「分からない」ボタンを追加
338
- bad_btn,
339
- gr_score_1,
340
- gr_score_2,
341
- gr_score_3,
342
- gr_score_4,
343
- gr_score_5,
344
- ]
345
- )
346
 
 
347
  def update_annotation(
348
  input_ans_1: str = None,
349
- input_ans_3: str = None,
350
  is_good: bool = None, # good/bad を表すフラグを追加
351
  is_unknown: bool = None, # 「分からない」を表すフラグを追加
 
352
  score_value: int = None # 5段階評価の値、good/badの場合はNone
353
- ) -> Tuple[gr.update, gr.update, gr.update, gr.update]:
 
 
 
 
 
 
354
 
355
  # good/bad/unknown と score の状態を更新
356
  update_evaluation_state(is_good, is_unknown, score_value)
357
 
358
  # 変更を検知 (5段階評価の場合も処理するように変更)
359
- update_answer_state(input_ans_1, input_ans_3)
360
-
361
  # 表示更新
362
  # indexを進める
363
  select_idx.value += 1
@@ -367,19 +875,31 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
367
  # ループさせるか、エラー処理を行う
368
  if select_idx.value >= len(df):
369
  select_idx.value = 0
 
 
 
 
370
 
371
  # データセットに追加
372
- # 元のindex番号(dataset_id)を指定して保存
373
  save_annotation_data(df)
374
 
375
  # Nextデータ初期化
376
  initialize_next_data(df)
 
 
 
377
 
378
  return gr.update(value=df.iloc[select_idx.value]["question"]), \
379
  gr.update(value=df.iloc[select_idx.value]["answer"]), \
380
  gr.update(value=df.iloc[select_idx.value]["question"]), \
381
- gr.update(value=df.iloc[select_idx.value]["answer"])
 
 
 
 
382
 
 
383
  def update_evaluation_state(is_good, is_unknown, score_value):
384
  if score_value is not None: # 5段階評価の場合
385
  good.value = False
@@ -391,100 +911,539 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
391
  bad.value = not is_good if not is_unknown else False
392
  unknown_quality.value = is_unknown # 「分からない」の状態を設定
393
 
394
- def update_answer_state(input_ans_1, input_ans_3):
 
395
  if input_ans_1 is not None and initial_answer_text_1.value != input_ans_1:
396
  is_proofreading_1.value = True
397
  answer_text_1.value = input_ans_1
398
  else:
399
  answer_text_1.value = ""
400
 
401
- if input_ans_3 is not None and initial_answer_text_2.value != input_ans_3:
 
402
  is_proofreading_2.value = True
403
- answer_text_2.value = input_ans_3
404
  else:
405
  answer_text_2.value = ""
406
 
 
407
  def save_annotation_data(df):
408
  save_annotation(
409
  select_dropdown_dataset.value,
410
  # datasetIdは元のindex番号を使用
411
  df.iloc[select_idx.value]['index'],
412
  who.value,
 
413
  good.value,
414
  bad.value,
415
- unknown_quality.value, # 「分からない」の状態を追加
416
- score.value,
417
  is_proofreading_1.value,
418
  answer_text_1.value,
419
  is_proofreading_2.value,
420
- answer_text_2.value
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  )
422
 
 
423
  def initialize_next_data(df):
424
  is_proofreading_1.value = False
425
  is_proofreading_2.value = False
426
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
427
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
428
-
429
- def good_click(input_ans_1, input_ans_3):
430
- return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=True, is_unknown=False)
431
-
432
- good_btn.click(
433
- good_click,
434
- inputs=[
435
- gr_answer_text_1,
436
- gr_answer_text_3
437
- ],
438
- outputs=[gr_question_text_1,
439
- gr_answer_text_1,
440
- gr_question_text_3,
441
- gr_answer_text_3]
442
- )
443
-
444
- def unknown_click(input_ans_1, input_ans_3):
445
  good.value = False
446
  bad.value = False
447
- return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=False, is_unknown=True)
448
-
449
- unknown_btn.click(
 
 
 
 
 
 
 
 
450
  unknown_click,
451
  inputs=[
452
- gr_answer_text_1,
453
- gr_answer_text_3
454
  ],
455
- outputs=[gr_question_text_1,
456
- gr_answer_text_1,
457
- gr_question_text_3,
458
- gr_answer_text_3]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  )
460
 
461
- def bad_click(input_ans_1, input_ans_3):
462
- return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=False, is_unknown=False)
463
-
464
- bad_btn.click(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
  bad_click,
466
  inputs=[
467
- gr_answer_text_1,
468
- gr_answer_text_3
469
  ],
470
- outputs=[gr_question_text_1,
471
- gr_answer_text_1,
472
- gr_question_text_3,
473
- gr_answer_text_3]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  )
475
 
476
  # 5段階評価ボタンのクリックイベント
477
- gr_score_1.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=1),
478
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
479
- gr_score_2.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=2),
480
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
481
- gr_score_3.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=3),
482
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
483
- gr_score_4.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=4),
484
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
485
- gr_score_5.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=5),
486
- inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
487
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  # TODO Tab切り替えで、アノテ済みの一覧を表示する
489
  # with gr.Tab("アノテ済みデータセット(管理画面)"):
490
  # タブを切り替えた時にデータ表示を更新する
 
28
  print("Warning: HF_TOKEN not found. Please set it in your Space secrets.")
29
 
30
  # HFデータセット アップロード先
31
+ # (切り替えてテストする用に配列)
32
+ OUTPUT_DATASET = [
33
  "team-hatakeyama-phase2/annotation_tanuki_phase2",
34
  "kevineen/Tanuki-Phase2-annotation-dataset", # 出力テスト
35
  ]
36
 
37
  # アノテーション対象データセット
38
+ ANNOTATION_DATASET = [
39
  "hatakeyama-llm-team/AutoGeneratedJapaneseQA",
40
  "hatakeyama-llm-team/AutoGeneratedJapaneseQA-other",
41
  "kanhatakeyama/ChatbotArenaJaMixtral8x22b",
 
46
  # "hatakeyama-llm-team/WikiBookJa",
47
  # "kanhatakeyama/AutoWikiQA",
48
  # "susumuota/SyntheticTextWikiTranslate-askllm-v1", # Ask-LLM 翻訳
49
+
50
+ # Nomotron データ (将来用
51
  ]
52
 
53
+ MULTITURN_ANNOTATION_DATASET = [
54
  # マルチターン 未対応
55
  "kanhatakeyama/AutoMultiTurnByMixtral8x22b",
56
  ]
 
62
  is_loaded_dataset = gr.State(False)
63
 
64
  # 選択中のデータセットリスト
65
+ dropdown_dataset_list = gr.State(value=ANNOTATION_DATASET)
66
+
67
  # 現在の対象データセット 初期値は"hatakeyama-llm-team/AutoGeneratedJapaneseQA",
68
  select_dropdown_dataset = gr.State(dropdown_dataset_list.value[0])
69
  select_dataset = gr.State(None) # 現在のデータセット
70
  select_dataset_total_len = gr.State(0) # 現在のデータセットの長さ
71
  select_idx = gr.State(0) # 現在のインデックス (ランダムモードにするなら不要?
72
+ # random_mode = gr.State(False) # ランダムモード
73
 
74
  # 回答者がアノテーションしたデータセット
75
  annotated_dataset = gr.State(
76
  pd.DataFrame({
77
+ 'dataset_name': [], # 対象データセット
78
+ 'dataset_id': [], # データセットindex
79
+ 'who': [], # アノテーション者名
80
+ 'unknown_quality': [], # 不明能
81
+ 'good': [], # 良
82
+ 'bad': [], #
83
+ 'is_proofreading_1': [], # テキストに修正があったか
 
84
  'answer_text_1': [],
85
+ 'is_proofreading_2': [], # 2ターン目用
86
+ 'answer_text_2': [], # 2ターン目用
87
+
88
+ # 5段階評価
89
+ 'score': [], # 総合 (5段階評価)
90
+ 'helphulness': [], # 有用性 (5段階評価)
91
+ 'correcthness': [], # 正確さ (5段階評価)
92
+ 'coherence': [], # 一貫性 (5段階評価)
93
+ 'complexity': [], # 複雑さ (5段階評価)
94
+ 'verbosity': [], # 冗長性 (5段階評価)
95
+ 'humor': [], # ユーモア (SteerLM)
96
+ 'creativity': [], # 創造性 (SteerLM)
97
+ 'appropriate': [], # 適切性 (SteerLMでは不適)
98
+ 'following_instructions': [], # 指示が合った場合、従っているか (SteerLMのfails_taskに該当)
99
+ 'politeness': [], # 礼儀正しさ (minnadechat)
100
+ 'harmfulness': [], # 有性 (minnadechat)
101
+
102
+ # 0: 分からない(未設定) 1: 無 2: 有
103
+ 'typos': [], # 誤字脱字 (minnadechat)
104
+ 'hate': [], # ヘイト
105
+ 'sexual': [], # 性的
106
+ 'violence': [], # 暴力
107
+ 'suicide': [], # 自殺
108
+ 'threat': [], # 犯罪
109
+ 'gun': [], # 重火器
110
+ 'controlled_substance': [], # 規制対象物質
111
+ 'climinal_planing': [], # 犯罪計画
112
+ 'privacy': [], # 個人情報
113
+ 'harassment': [], # ハラスメント
114
+ 'profanity': [], # 冒涜
115
+ 'political_content': [], # 政治的内容 (SteerLM)
116
+ 'moral_judgement': [], # 非道徳 (SteerLM)
117
  })
118
  )
119
 
120
+ is_dataset_loaded = gr.State(False) # データセットロード状態
 
 
 
121
 
122
  you_dataset_id = gr.State(0) # 回答者がアノテーションしているデータのID
123
  dataset_name = gr.State("") # 編集に使用したデータセット名
124
  dataset_id = gr.State(0) # 加工元データセットのindex
125
  who = gr.State("") # アノテーション者名
126
+
127
+ # シンプルモード
128
+ unknown_quality = gr.State(False) # 分からない(未設定)
129
  good = gr.State(False) # 良
130
  bad = gr.State(False) # 悪
131
+
132
+ initial_answer_text_1 = gr.State("") # 回��1を整形したかチェック用
133
+ initial_answer_text_2 = gr.State("") # 回答2を整形したかチェック用
134
+
135
  is_proofreading_1 = gr.State(False) # 回答1を整形したか_1
136
  answer_text_1 = gr.State("") # answer_1 回答
137
  is_proofreading_2 = gr.State(False) # 回答2を整形したか_2
138
  answer_text_2 = gr.State("") # answer_2 回答
139
 
140
+ # (5段階評価)
141
+ # 0は判断していない、又は判断が難しいという特徴量にする
142
+ score = gr.State(3) # 総合スコア 初期値は3 (最低限必須)
143
+ helphulness = gr.State(0) # 有用性
144
+ correcthness = gr.State(0) # 正確さ
145
+ coherenece = gr.State(0) # 一貫性
146
+ complexity = gr.State(0) # 複雑さ
147
+ verbosity = gr.State(0) # 冗長性
148
+ humor = gr.State(0) # ユーモア (SteerLM)
149
+ creativity = gr.State(0) # 創造性 (SteerLM)
150
+ appropriate = gr.State(0) # 適切性 (SteerLMではnot_appropriate)
151
+ following_instructions = gr.State(0) # 指示への忠実度 (SteerLMのfails_task)
152
+ politeness = gr.State(0) # 礼儀正しさ (minnadechat)
153
+ harmfulness = gr.State(0) # 有度 (minnadechat)
154
+
155
+ # (有無評価)
156
+ # 0は判断していない、又は判断が難しいという特徴量にする
157
+ hate = gr.State(0) # ヘイト
158
+ sexual = gr.State(0) # 性的
159
+ violence = gr.State(0) # 暴力
160
+ suicide = gr.State(0) # 自殺
161
+ threat = gr.State(0) # 犯罪
162
+ gun = gr.State(0) # 銃・重火器
163
+ controlled_substance = gr.State(0) # 規制対象物質
164
+ climinal_planing = gr.State(0) # 犯罪計画
165
+ privacy = gr.State(0) # 個人情報・プライバシー情報
166
+ harassment = gr.State(0) # ハラスメント
167
+ profanity = gr.State(0) # 冒涜
168
+ political_content = gr.State(0) # 政治的内容 (SteerLM)
169
+ moral_judgement = gr.State(0) # 非道徳 (SteerLM)
170
+ typos = gr.State(0) # 誤字脱字(minnadechat)
171
+
172
+ # 未整理 ========================================
173
+
174
+ # データセット読み込み
175
  def dataset_load_fn() -> Tuple[
176
  str,
177
  str,
178
  str,
179
  str,
180
+ str,
181
+ str,
182
+ gr.update,
183
+ gr.update,
184
+ gr.update,
185
+ gr.update,
186
+ gr.update,
187
+ gr.update,
188
+ gr.update,
189
+ gr.update,
190
+ gr.update,
191
+ gr.update,
192
+ gr.update,
193
+ gr.update,
194
+ gr.update,
195
+ gr.update,
196
+ gr.update,
197
+ gr.update,
198
+ gr.update,
199
+ gr.update,
200
+ gr.update,
201
+ gr.update,
202
+ gr.update,
203
+ gr.update,
204
+ gr.update,
205
+ gr.update,
206
+ gr.update,
207
+ gr.update,
208
+ gr.update,
209
+ gr.update,
210
+ gr.update,
211
  gr.update,
212
  gr.update,
213
  gr.update,
 
216
  gr.update,
217
  gr.update,
218
  gr.update,
219
+ gr.update,
220
+ gr.update,
221
+ ]:
222
 
223
+ is_dataset_loaded.value = False # ロード状態初期化
224
 
225
  select_dataset.value = load_dataset(
226
  select_dropdown_dataset.value
 
229
  # DatasetオブジェクトをPandas DataFrameに変換
230
  df = select_dataset.value["train"].to_pandas()
231
 
232
+ # ランダム化実施
233
  # index列を追加し、シャッフル
234
  df = df.reset_index(drop=False) # 元のindexを保持
235
  df = df.sample(frac=1).reset_index(drop=True) # シャッフル
 
239
  select_dataset_total_len.value = len(df) # 長さを取得
240
  is_dataset_loaded.value = True # ロード完了
241
 
242
+ # データロード時にテキストの初期値を設定
243
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
244
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
245
 
 
247
  df.iloc[select_idx.value]["answer"], \
248
  df.iloc[select_idx.value]["question"], \
249
  df.iloc[select_idx.value]["answer"], \
250
+ df.iloc[select_idx.value]["question"], \
251
+ df.iloc[select_idx.value]["answer"], \
252
+ gr.update(interactive=True), \
253
+ gr.update(interactive=True), \
254
+ gr.update(interactive=True), \
255
+ gr.update(interactive=True), \
256
+ gr.update(interactive=True), \
257
+ gr.update(interactive=True), \
258
+ gr.update(interactive=True), \
259
+ gr.update(interactive=True), \
260
+ gr.update(interactive=True), \
261
+ gr.update(interactive=True), \
262
+ gr.update(interactive=True), \
263
+ gr.update(interactive=True), \
264
+ gr.update(interactive=True), \
265
+ gr.update(interactive=True), \
266
+ gr.update(interactive=True), \
267
+ gr.update(interactive=True), \
268
+ gr.update(interactive=True), \
269
+ gr.update(interactive=True), \
270
+ gr.update(interactive=True), \
271
+ gr.update(interactive=True), \
272
+ gr.update(interactive=True), \
273
+ gr.update(interactive=True), \
274
+ gr.update(interactive=True), \
275
+ gr.update(interactive=True), \
276
+ gr.update(interactive=True), \
277
+ gr.update(interactive=True), \
278
+ gr.update(interactive=True), \
279
+ gr.update(interactive=True), \
280
+ gr.update(interactive=True), \
281
+ gr.update(interactive=True), \
282
+ gr.update(interactive=True), \
283
  gr.update(interactive=True), \
284
  gr.update(interactive=True), \
285
  gr.update(interactive=True), \
 
298
  annotated_folder = annotation_file.parent
299
 
300
  scheduler = CommitScheduler(
301
+ repo_id=OUTPUT_DATASET[1],
302
  repo_type="dataset",
303
  folder_path=annotated_folder,
304
  path_in_repo="data", # Spaceの場合の保存先フォルダー
 
306
  every=5, # 5分毎にアップロード HuggingFAce_Documentの最低推奨値
307
  )
308
 
309
+ # チェックボックスをintに変換
310
+ def checkbox_to_int(checkbox_value) -> int:
311
+ if checkbox_value == "不明":
312
+ output = 0
313
+ elif checkbox_value == "有":
314
+ output = 1
315
+ elif checkbox_value == "無":
316
+ output = 2
317
+ else :
318
+ output = 0
319
+ print("error: ")
320
+ return output
321
+
322
  # CommitScheduler (HFへのデータアップロード
323
  def save_annotation(
324
  dataset_name: str,
325
  dataset_id: int,
326
  who: str,
327
+ unknown_quality: bool,
328
  good: bool,
329
  bad: bool,
 
 
330
  is_proofreading_1: bool,
331
  answer_text_1: str,
332
  is_proofreading_2: bool,
333
+ answer_text_2: str,
334
+ score: int,
335
+ helphulness: int,
336
+ correcthness: int,
337
+ coherence: int,
338
+ complexity: int,
339
+ verbosity: int,
340
+ humor: int,
341
+ creativity: int,
342
+ appropriate: int,
343
+ following_instructions: int,
344
+ politeness: int,
345
+ harmfulness: int,
346
+ hate: int,
347
+ sexual: int,
348
+ violence: int,
349
+ suicide: int,
350
+ threat: int,
351
+ gun: int,
352
+ controlled_substance: int,
353
+ climinal_planing: int,
354
+ privacy: int,
355
+ harassment: int,
356
+ profanity: int,
357
+ political_content: int,
358
+ moral_judgement: int,
359
+ typos: int,
360
+ ) -> None:
361
 
362
  annotated_dataset.value = pd.concat([
363
  annotated_dataset.value,
 
365
  'dataset_name': [dataset_name],
366
  'dataset_id': [dataset_id],
367
  'who': [who],
368
+ 'unknown_quality': [unknown_quality],
369
  'good': [good],
370
  'bad': [bad],
 
 
371
  'is_proofreading_1': [is_proofreading_1],
372
  "answer_text_1": [answer_text_1],
373
  'is_proofreading_2': [is_proofreading_2],
374
+ 'answer_text_2': [answer_text_2],
375
+ 'score': [score],
376
+ 'helphullness': [helphulness],
377
+ 'correcthness': [correcthness],
378
+ 'complexity': [complexity],
379
+ 'verbosity': [verbosity],
380
+ 'humor': [humor],
381
+ 'creativity': [creativity],
382
+ 'appropriate': [appropriate],
383
+ 'following_finstructions': [following_instructions],
384
+ 'politeness': [politeness],
385
+ 'harmfulness': [harmfulness],
386
+ 'hate': [hate],
387
+ 'sextual': [sexual],
388
+ 'violence': [violence],
389
+ 'suicide': [suicide],
390
+ 'threat': [threat],
391
+ 'gun': [gun],
392
+ 'controlled_substance': [controlled_substance],
393
+ 'climinal_planing': [climinal_planing],
394
+ 'privacy': [privacy],
395
+ 'harassment': [harassment],
396
+ 'profanity': [profanity],
397
+ 'political_content': [political_content],
398
+ 'moral_judgement': [moral_judgement],
399
+ 'types': [typos]
400
  })], ignore_index=True).reset_index(drop=True)
401
 
402
  # 書き込み
403
  with scheduler.lock:
404
  with annotation_file.open("a", encoding='utf-8') as f:
405
  data_to_write = {
406
+ # "id": , CommitSchedulerは、取得して末尾idを付与することが不可能?
407
  "datetime": str(datetime.datetime.now().isoformat()),
408
  "dataset_name": dataset_name,
409
  "dataset_id": int(dataset_id),
410
  "who": who,
411
+ "unknown_quality": unknown_quality,
412
  "good": good,
413
  "bad": bad,
 
 
414
  "is_proofreading_1": is_proofreading_1,
415
  "answer_text_1": answer_text_1,
416
  "is_proofreading_2": is_proofreading_2,
417
  "answer_text_2": answer_text_2,
418
+ "score": int(score),
419
+ "helphulness": int(helphulness),
420
+ "correcthness": int(correcthness),
421
+ "coherence": int(coherence),
422
+ "complexity": int(complexity),
423
+ "verbosity": int(verbosity),
424
+ "humor": int(humor),
425
+ "creativity": int(creativity),
426
+ "appropriate": int(appropriate),
427
+ "following_instructions": int(following_instructions),
428
+ "politeness": int(politeness),
429
+ "harmfulness": int(harmfulness),
430
+ "hate": int(hate),
431
+ "sexual": int(sexual),
432
+ "violence": int(violence),
433
+ "suicide": int(suicide),
434
+ "threat": int(threat),
435
+ "gun": int(gun),
436
+ "controlled_substance": int(controlled_substance),
437
+ "climinal_planing": int(climinal_planing),
438
+ "privacy": int(privacy),
439
+ "harassment": int(harassment),
440
+ "profanity": int(profanity),
441
+ "policital_content": int(political_content),
442
+ "moral_judgement": int(moral_judgement),
443
+ "typos": int(typos)
444
  }
445
  f.write(json.dumps(data_to_write, ensure_ascii=False))
446
  f.write("\n")
 
452
 
453
  # ユーザー名表示
454
 
 
455
  def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
456
  if profile is None:
457
  return "プライベートデータセット取得のためにログインしてください。", who.value
 
463
  theme_ = gr.themes.Default()
464
 
465
  # 後のCSSデザイン変更用
 
 
466
  def load_css():
467
  with open("style.css", "r") as file:
468
  css_content = file.read()
469
  return css_content
470
 
 
471
  # Gradio 画面 ============================================
472
  with gr.Blocks(theme=theme_, css=load_css()) as demo:
473
 
474
  gr.Markdown("# データセット アノテーション for Tanuki (Phase2)")
475
+
476
+ with gr.Row():
477
+ gr.Markdown("### GENIACにて開発中のLLM用データセットに対してアノテーションするSpaceです\n \
478
+ 入力されたデータは使用される可能性があるため、個人情報・秘匿情報などは入力しないでください。\n \
479
+ テスト中です。")
480
+ gr_who = gr.TextArea(value=who.value, lines=1, max_lines=1, label="ユーザー名 (入力してください)")
481
+
482
+ def change_name(name: str):
483
+ who.value = name
484
+
485
+ gr_who.change(
486
+ change_name,
487
+ inputs=[gr_who],
488
+ outputs=[]
489
+ )
490
 
491
  with gr.Tab("アノテーション (シングルターン)"):
492
 
493
+ # HF login 機能
494
+ # with gr.Row(equal_height=True):
495
+ # gr.LoginButton(value="HuggingFace ログイン",
496
+ # logout_value="HuggingFace ログアウト", scale=1)
 
497
  # ユーザー名
498
+ # gr_profile_name = gr.Markdown()
499
+ # demo.load(hello, inputs=None, outputs=[gr_profile_name, who])
500
 
501
  with gr.Row():
502
 
 
519
  gr_data_load_btn = gr.Button("② データセットを読み込む")
520
 
521
  with gr.Column() as content_column:
522
+
523
  with gr.Tab("③ シンプル(良・悪)"):
524
  with gr.Column():
525
  with gr.Row(equal_height=True):
526
+ gr_good_btn = gr.Button("良い", interactive=False)
527
+ gr_unknown_btn = gr.Button(
528
  "分からない", interactive=False) # 「分からない」ボタンを追加
529
+ gr_bad_btn = gr.Button("悪い", interactive=False)
530
 
531
+ gr_question_text_1_1 = gr.Textbox(
532
  label="質問: ", lines=5, interactive=False)
533
 
534
+ gr_answer_text_1_1 = gr.Textbox(
535
+ label="回答: 訂正して頂けると、品質が上がります。",
536
  lines=20,
537
+ interactive=False)
538
+
539
+ with gr.Tab("③ 5段階評価(シンプル)"):
540
+
541
+ with gr.Row() as simple_score_btn:
542
+ gr_score_5_btn = gr.Button("5: 高品質", interactive=False)
543
+ gr_score_4_btn = gr.Button("4: 良い", interactive=False)
544
+ gr_score_3_btn = gr.Button("3: 普通", interactive=False)
545
+ gr_score_2_btn = gr.Button("2: 悪い", interactive=False)
546
+ gr_score_1_btn = gr.Button("1: 低品質", interactive=False)
547
+
548
+ gr_question_text_2_1 = gr.Textbox(
549
+ label="質問: ", lines=5, interactive=False)
550
+
551
+ gr_answer_text_2_1 = gr.Textbox(
552
+ label="回答: 訂正して頂けると、品質が上がります。", lines=20, interactive=False)
553
+
554
+ with gr.Tab("③ 5段階評価 (詳細)"):
555
+
556
+ with gr.Row():
557
+
558
+ with gr.Column() as EvalFive:
559
+
560
+ gr_question_text_3_1 = gr.Textbox(
561
+ label="質問: ", lines=10, interactive=False)
562
+
563
+ # gr_explain = gr.Markdown("回答")
564
+
565
+ gr_answer_text_3_1 = gr.Textbox(
566
+ label="回答: 訂正して頂けると、品質が上がります。", lines=35, interactive=False)
567
+
568
+ with gr.Column() as EvalFiveDetail:
569
+
570
+ with gr.Row():
571
+ gr_submit_score = gr.Button("評価送信", interactive=False)
572
+ gr_score_reset = gr.Button("スコアリセット", interactive=False)
573
+
574
+ gr_score_detail = gr.Slider(label="総合スコア 【必須】",value=3, minimum=1, maximum=5, step=1, interactive=False)
575
+ gr_evalannotation_explain = gr.Markdown("詳細アノテーション (5点満点)")
576
+
577
+ with gr.Row() :
578
+ gr_helphulness = gr.Slider(label="有用性", minimum=0, value=0, maximum=5, step=1, interactive=False)
579
+ gr_correcthness = gr.Slider(label="正確さ", minimum=0, value=0, maximum=5, step=1, interactive=False)
580
+ gr_coherence = gr.Slider(label="一貫性", minimum=0, value=0, maximum=5, step=1, interactive=False)
581
+ gr_complexity = gr.Slider(label="複雑さ", minimum=0, value=0, maximum=5, step=1, interactive=False)
582
+
583
+ with gr.Row() :
584
+ gr_verbosity = gr.Slider(label="冗長性", minimum=0, value=0, maximum=5, step=1, interactive=False)
585
+ gr_humor = gr.Slider(label="ユーモア", minimum=0, value=0, maximum=5, step=1, interactive=False)
586
+ gr_creativity = gr.Slider(label="創造性", minimum=0, value=0, maximum=5, step=1, interactive=False)
587
+ gr_appropriate = gr.Slider(label="適切性", minimum=0, value=0, maximum=5, step=1, interactive=False)
588
+
589
+ with gr.Row() :
590
+ gr_following_instructions = gr.Slider(label="忠実性", minimum=0, value=0, maximum=5, step=1, interactive=False)
591
+ gr_politeness = gr.Slider(label="礼儀正しさ", minimum=0, value=0, maximum=5, step=1, interactive=False)
592
+ gr_harmfulness = gr.Slider(label="有害性", minimum=0, value=0, maximum=5, step=1, interactive=False)
593
+ gr_text_4 = gr.Markdown("判断可能な物のみ\n\nスコアを付けてください。")
594
+
595
+ gr_text_5 = gr.Markdown("")
596
+
597
+ with gr.Row():
598
+ gr_typos = gr.Radio(label="誤字・脱字", choices=["不明", "有", "無"], value="不明", interactive=False)
599
+ gr_moral_judgement = gr.Radio(label="非道徳", choices=["不明", "有", "無"], value="不明", interactive=False)
600
+
601
+ with gr.Row():
602
+ gr_hate = gr.Radio(label="ヘイト", choices=["不明", "有", "無"], value="不明", interactive=False)
603
+ gr_sexual = gr.Radio(label="性的内容", choices=["不明", "有", "無"], value="不明", interactive=False)
604
+
605
+ with gr.Row():
606
+ gr_violence = gr.Radio(label="暴力的", choices=["不明", "有", "無"], value="不明", interactive=False)
607
+ gr_suicide = gr.Radio(label="自殺行為", choices=["不明", "有", "無"], value="不明", interactive=False)
608
+
609
+ with gr.Row():
610
+ gr_threat = gr.Radio(label="犯罪", choices=["不明", "有", "無"], value="不明", interactive=False)
611
+ gr_gun = gr.Radio(label="銃等", choices=["不明", "有", "無"], value="不明", interactive=False)
612
+
613
+ with gr.Row():
614
+ gr_controlled_substance = gr.Radio(label="規制対象物質", choices=["不明", "有", "無"], value="不明", interactive=False)
615
+ gr_climinal_planing = gr.Radio(label="犯罪計画", choices=["不明", "有", "無"], value="不明", interactive=False)
616
+
617
+ with gr.Row():
618
+ gr_privacy = gr.Radio(label="個人情報", choices=["不明", "有", "無"], value="不明", interactive=False)
619
+ gr_harassment = gr.Radio(label="ハラスメント", choices=["不明", "有", "無"], value="不明", interactive=False)
620
+
621
+ with gr.Row():
622
+ gr_profanity = gr.Radio(label="冒涜行為", choices=["不明", "有", "無"], value="不明", interactive=False)
623
+ gr_political_content = gr.Radio(label="政治的内容", choices=["不明", "有", "無"], value="不明", interactive=False)
624
+
625
+
626
+ # 5段階評価 詳細のgr.State Update
627
+ def eval_submit(
628
+ # text
629
+ g_answer_text_3_1: str,
630
+
631
+ # slicer
632
+ g_score: int,
633
+ g_helphulness: int,
634
+ g_correcthness: int,
635
+ g_coherenece: int,
636
+ g_complexity: int,
637
+ g_verbosity: int,
638
+ g_humor: int,
639
+ g_creativity: int,
640
+ g_appropriate: int,
641
+ g_following_instructions: int,
642
+ g_politeness: int,
643
+ g_harmfulness: int,
644
+
645
+ # checkbox
646
+ g_hate: str,
647
+ g_sexual: str,
648
+ g_violence: str,
649
+ g_suicide: str,
650
+ g_threat: str,
651
+ g_gun: str,
652
+ g_controlled_substance: str,
653
+ g_climinal_planing: str,
654
+ g_privacy: str,
655
+ g_harassment: str,
656
+ g_profanity: str,
657
+ g_political_content: str,
658
+ g_moral_judgement: str,
659
+ g_typos: str,
660
+ ):
661
+ # 状態初期化
662
+ good.value = False
663
+ bad.value = False
664
+ unknown_quality.value = False
665
+
666
+ # テキストに更新があったかどうかチェック
667
+ if initial_answer_text_1.value != g_answer_text_3_1:
668
+ is_proofreading_1.value = True
669
+ answer_text_1.value = g_answer_text_3_1
670
+ else:
671
+ is_proofreading_1.value = False
672
+ answer_text_1.value = ""
673
+
674
+ # 送信用データ更新
675
+ score.value = g_score
676
+ helphulness.value = g_helphulness
677
+ correcthness.value = g_correcthness
678
+ coherenece.value = g_coherenece
679
+ complexity.value = g_complexity
680
+ verbosity.value = g_verbosity
681
+ humor.value = g_humor
682
+ creativity.value = g_creativity
683
+ appropriate.value = g_appropriate
684
+ following_instructions.value = g_following_instructions
685
+ politeness.value = g_politeness
686
+ harmfulness.value = g_harmfulness
687
+
688
+ hate.value = checkbox_to_int(g_hate)
689
+ sexual.value = checkbox_to_int(g_sexual)
690
+ violence.value = checkbox_to_int(g_violence)
691
+ suicide.value = checkbox_to_int(g_suicide)
692
+ threat.value = checkbox_to_int(g_threat)
693
+ gun.value = checkbox_to_int(g_gun)
694
+ controlled_substance.value = checkbox_to_int(g_controlled_substance)
695
+ climinal_planing.value = checkbox_to_int(g_climinal_planing)
696
+ privacy.value = checkbox_to_int(g_privacy)
697
+ harassment.value = checkbox_to_int(g_harassment)
698
+ profanity.value = checkbox_to_int(g_profanity)
699
+ political_content.value = checkbox_to_int(g_political_content)
700
+ moral_judgement.value = checkbox_to_int(g_moral_judgement)
701
+ typos.value = checkbox_to_int(g_typos)
702
+
703
+ # データ送信
704
+
705
+ # 表示更新
706
+ # indexを進める
707
+ select_idx.value += 1
708
 
709
+ df = select_dataset.value["train"]
710
 
711
+ # ループさせるか、エラー処理を行う
712
+ if select_idx.value >= len(df):
713
+ select_idx.value = 0
714
 
715
+ # データセットに追加
716
+ df = select_dataset.value["train"]
717
+ save_annotation(
718
+ select_dropdown_dataset.value,
719
+ df.iloc[select_idx.value]['index'],
720
+ who.value,
721
+ unknown_quality.value,
722
+ good.value,
723
+ bad.value,
724
+ is_proofreading_1.value,
725
+ answer_text_1.value,
726
+ is_proofreading_2.value,
727
+ answer_text_2.value,
728
+ score.value,
729
+ helphulness.value,
730
+ correcthness.value,
731
+ coherenece.value,
732
+ complexity.value,
733
+ verbosity.value,
734
+ humor.value,
735
+ creativity.value,
736
+ appropriate.value,
737
+ following_instructions.value,
738
+ politeness.value,
739
+ harmfulness.value,
740
+ hate.value,
741
+ sexual.value,
742
+ violence.value,
743
+ suicide.value,
744
+ threat.value,
745
+ gun.value,
746
+ controlled_substance.value,
747
+ climinal_planing.value,
748
+ privacy.value,
749
+ harassment.value,
750
+ profanity.value,
751
+ political_content.value,
752
+ moral_judgement.value,
753
+ typos.value,
754
+ )
755
 
756
+ # Nextデータ初期化
757
+ initialize_next_data(df)
758
+
759
+ # 5段階評価をリセット
760
+ score_reset_display()
761
+
762
+ # UI更新のための返り値
763
+ return gr.update(value=df.iloc[select_idx.value]["question"]), \
764
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
765
+ gr.update(value=df.iloc[select_idx.value]["question"]), \
766
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
767
+ gr.update(value=df.iloc[select_idx.value]["question"]), \
768
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
769
+ *score_reset_display() # スコアリセット用の返り値
770
+
771
+ gr_submit_score.click(
772
+ eval_submit,
773
+ inputs=[
774
+ gr_answer_text_3_1,
775
+ gr_score_detail,
776
+ gr_helphulness,
777
+ gr_correcthness,
778
+ gr_coherence,
779
+ gr_complexity,
780
+ gr_verbosity,
781
+ gr_humor,
782
+ gr_creativity,
783
+ gr_appropriate,
784
+ gr_following_instructions,
785
+ gr_politeness,
786
+ gr_harmfulness,
787
+ gr_hate,
788
+ gr_sexual,
789
+ gr_violence,
790
+ gr_suicide,
791
+ gr_threat,
792
+ gr_gun,
793
+ gr_controlled_substance,
794
+ gr_climinal_planing,
795
+ gr_privacy,
796
+ gr_harassment,
797
+ gr_profanity,
798
+ gr_political_content,
799
+ gr_moral_judgement,
800
+ gr_typos
801
+ ],
802
+ # UI更新
803
+ outputs=[
804
+ gr_question_text_1_1,
805
+ gr_answer_text_1_1,
806
+ gr_question_text_2_1,
807
+ gr_answer_text_2_1,
808
+ gr_question_text_3_1,
809
+ gr_answer_text_3_1,
810
+ gr_score_detail,
811
+ gr_helphulness,
812
+ gr_correcthness,
813
+ gr_coherence,
814
+ gr_complexity,
815
+ gr_verbosity,
816
+ gr_humor,
817
+ gr_creativity,
818
+ gr_appropriate,
819
+ gr_following_instructions,
820
+ gr_politeness,
821
+ gr_harmfulness,
822
+ gr_hate,
823
+ gr_sexual,
824
+ gr_violence,
825
+ gr_suicide,
826
+ gr_threat,
827
+ gr_gun,
828
+ gr_controlled_substance,
829
+ gr_climinal_planing,
830
+ gr_privacy,
831
+ gr_harassment,
832
+ gr_profanity,
833
+ gr_political_content,
834
+ gr_moral_judgement,
835
+ gr_typos
836
+ ],
837
+ )
838
 
839
  # 5段階評価ボタンのクリックイベントを定義
840
  def score_button_clicked(button_value):
841
+ # 状態初期化
842
  good.value = False
843
  bad.value = False
844
+ unknown_quality.value = False
845
+ score.value = button_value
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
846
 
847
+ # 5段階評価クリック
848
  def update_annotation(
849
  input_ans_1: str = None,
850
+ input_ans_2: str = None,
851
  is_good: bool = None, # good/bad を表すフラグを追加
852
  is_unknown: bool = None, # 「分からない」を表すフラグを追加
853
+ is_simple: bool = None,
854
  score_value: int = None # 5段階評価の値、good/badの場合はNone
855
+ ) -> Tuple[
856
+ gr.update,
857
+ gr.update,
858
+ gr.update,
859
+ gr.update,
860
+ gr.update,
861
+ ]:
862
 
863
  # good/bad/unknown と score の状態を更新
864
  update_evaluation_state(is_good, is_unknown, score_value)
865
 
866
  # 変更を検知 (5段階評価の場合も処理するように変更)
867
+ update_answer_state(input_ans_1, input_ans_2)
868
+
869
  # 表示更新
870
  # indexを進める
871
  select_idx.value += 1
 
875
  # ループさせるか、エラー処理を行う
876
  if select_idx.value >= len(df):
877
  select_idx.value = 0
878
+
879
+ # シンプルモードクリックで、scoreを0に設定
880
+ if is_simple == True:
881
+ score.value = 0
882
 
883
  # データセットに追加
884
+ # 元のindex番号(dataset_id)を指定して保存
885
  save_annotation_data(df)
886
 
887
  # Nextデータ初期化
888
  initialize_next_data(df)
889
+
890
+ # 5段階評価をリセット
891
+ reset_values = score_reset_display()
892
 
893
  return gr.update(value=df.iloc[select_idx.value]["question"]), \
894
  gr.update(value=df.iloc[select_idx.value]["answer"]), \
895
  gr.update(value=df.iloc[select_idx.value]["question"]), \
896
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
897
+ gr.update(value=df.iloc[select_idx.value]["question"]), \
898
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
899
+ *reset_values
900
+
901
 
902
+ # 評価状態リセット
903
  def update_evaluation_state(is_good, is_unknown, score_value):
904
  if score_value is not None: # 5段階評価の場合
905
  good.value = False
 
911
  bad.value = not is_good if not is_unknown else False
912
  unknown_quality.value = is_unknown # 「分からない」の状態を設定
913
 
914
+ # 変更を検知して値を設定
915
+ def update_answer_state(input_ans_1, input_ans_2):
916
  if input_ans_1 is not None and initial_answer_text_1.value != input_ans_1:
917
  is_proofreading_1.value = True
918
  answer_text_1.value = input_ans_1
919
  else:
920
  answer_text_1.value = ""
921
 
922
+ # 2ターン目用
923
+ if input_ans_2 is not None and initial_answer_text_2.value != input_ans_2:
924
  is_proofreading_2.value = True
925
+ answer_text_2.value = input_ans_2
926
  else:
927
  answer_text_2.value = ""
928
 
929
+ # データ保存
930
  def save_annotation_data(df):
931
  save_annotation(
932
  select_dropdown_dataset.value,
933
  # datasetIdは元のindex番号を使用
934
  df.iloc[select_idx.value]['index'],
935
  who.value,
936
+ unknown_quality.value,
937
  good.value,
938
  bad.value,
 
 
939
  is_proofreading_1.value,
940
  answer_text_1.value,
941
  is_proofreading_2.value,
942
+ answer_text_2.value,
943
+ score.value,
944
+ helphulness.value,
945
+ correcthness.value,
946
+ coherenece.value,
947
+ complexity.value,
948
+ verbosity.value,
949
+ humor.value,
950
+ creativity.value,
951
+ appropriate.value,
952
+ following_instructions.value,
953
+ politeness.value,
954
+ harmfulness.value,
955
+ hate.value,
956
+ sexual.value,
957
+ violence.value,
958
+ suicide.value,
959
+ threat.value,
960
+ gun.value,
961
+ controlled_substance.value,
962
+ climinal_planing.value,
963
+ privacy.value,
964
+ harassment.value,
965
+ profanity.value,
966
+ political_content.value,
967
+ moral_judgement.value,
968
+ typos.value,
969
  )
970
 
971
+ # 次データ読込時の初期化
972
  def initialize_next_data(df):
973
  is_proofreading_1.value = False
974
  is_proofreading_2.value = False
975
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
976
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
977
+
978
+ # 評価不可
979
+ def unknown_click(input_ans_1, input_ans_2):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
980
  good.value = False
981
  bad.value = False
982
+ score_reset_display()
983
+ return update_annotation(
984
+ input_ans_1=input_ans_1,
985
+ input_ans_2=input_ans_2,
986
+ is_good=False,
987
+ is_unknown=True,
988
+ is_simple=True,
989
+ )
990
+
991
+ # 評価不可クリックイベント
992
+ gr_unknown_btn.click(
993
  unknown_click,
994
  inputs=[
995
+ gr_answer_text_1_1,
996
+ gr_answer_text_2_1
997
  ],
998
+ outputs=[
999
+ gr_question_text_1_1,
1000
+ gr_answer_text_1_1,
1001
+ gr_question_text_2_1,
1002
+ gr_answer_text_2_1,
1003
+ gr_question_text_3_1,
1004
+ gr_answer_text_3_1,
1005
+ gr_score_detail,
1006
+ gr_helphulness,
1007
+ gr_correcthness,
1008
+ gr_coherence,
1009
+ gr_complexity,
1010
+ gr_verbosity,
1011
+ gr_humor,
1012
+ gr_creativity,
1013
+ gr_appropriate,
1014
+ gr_following_instructions,
1015
+ gr_politeness,
1016
+ gr_harmfulness,
1017
+ gr_hate,
1018
+ gr_sexual,
1019
+ gr_violence,
1020
+ gr_suicide,
1021
+ gr_threat,
1022
+ gr_gun,
1023
+ gr_controlled_substance,
1024
+ gr_climinal_planing,
1025
+ gr_privacy,
1026
+ gr_harassment,
1027
+ gr_profanity,
1028
+ gr_political_content,
1029
+ gr_moral_judgement,
1030
+ gr_typos
1031
+ ]
1032
  )
1033
 
1034
+ # 良いクリック
1035
+ def good_click(input_ans_1, input_ans_2):
1036
+ score_reset_display()
1037
+ return update_annotation(
1038
+ input_ans_1=input_ans_1,
1039
+ input_ans_2=input_ans_2,
1040
+ is_good=True,
1041
+ is_unknown=False,
1042
+ is_simple=True,
1043
+ )
1044
+
1045
+ # 良いクリック
1046
+ gr_good_btn.click(
1047
+ good_click,
1048
+ inputs=[
1049
+ gr_answer_text_1_1,
1050
+ gr_answer_text_2_1
1051
+ ],
1052
+ outputs=[
1053
+ gr_question_text_1_1,
1054
+ gr_answer_text_1_1,
1055
+ gr_question_text_2_1,
1056
+ gr_answer_text_2_1,
1057
+ gr_question_text_3_1,
1058
+ gr_answer_text_3_1,
1059
+ gr_score_detail,
1060
+ gr_helphulness,
1061
+ gr_correcthness,
1062
+ gr_coherence,
1063
+ gr_complexity,
1064
+ gr_verbosity,
1065
+ gr_humor,
1066
+ gr_creativity,
1067
+ gr_appropriate,
1068
+ gr_following_instructions,
1069
+ gr_politeness,
1070
+ gr_harmfulness,
1071
+ gr_hate,
1072
+ gr_sexual,
1073
+ gr_violence,
1074
+ gr_suicide,
1075
+ gr_threat,
1076
+ gr_gun,
1077
+ gr_controlled_substance,
1078
+ gr_climinal_planing,
1079
+ gr_privacy,
1080
+ gr_harassment,
1081
+ gr_profanity,
1082
+ gr_political_content,
1083
+ gr_moral_judgement,
1084
+ gr_typos
1085
+ ]
1086
+ )
1087
+
1088
+ # 低評価クリック
1089
+ def bad_click(input_ans_1, input_ans_2):
1090
+ score_reset_display()
1091
+ return update_annotation(
1092
+ input_ans_1=input_ans_1,
1093
+ input_ans_2=input_ans_2,
1094
+ is_good=False,
1095
+ is_unknown=False,
1096
+ is_simple=True,
1097
+ )
1098
+
1099
+ # 低評価クリックイベント
1100
+ gr_bad_btn.click(
1101
  bad_click,
1102
  inputs=[
1103
+ gr_answer_text_1_1,
1104
+ gr_answer_text_2_1
1105
  ],
1106
+ outputs=[
1107
+ gr_question_text_1_1,
1108
+ gr_answer_text_1_1,
1109
+ gr_question_text_2_1,
1110
+ gr_answer_text_2_1,
1111
+ gr_question_text_3_1,
1112
+ gr_answer_text_3_1,
1113
+ gr_score_detail,
1114
+ gr_helphulness,
1115
+ gr_correcthness,
1116
+ gr_coherence,
1117
+ gr_complexity,
1118
+ gr_verbosity,
1119
+ gr_humor,
1120
+ gr_creativity,
1121
+ gr_appropriate,
1122
+ gr_following_instructions,
1123
+ gr_politeness,
1124
+ gr_harmfulness,
1125
+ gr_hate,
1126
+ gr_sexual,
1127
+ gr_violence,
1128
+ gr_suicide,
1129
+ gr_threat,
1130
+ gr_gun,
1131
+ gr_controlled_substance,
1132
+ gr_climinal_planing,
1133
+ gr_privacy,
1134
+ gr_harassment,
1135
+ gr_profanity,
1136
+ gr_political_content,
1137
+ gr_moral_judgement,
1138
+ gr_typos
1139
+ ]
1140
  )
1141
 
1142
  # 5段階評価ボタンのクリックイベント
1143
+ gr_score_1_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=1),
1144
+ inputs=[gr_answer_text_2_1],
1145
+ outputs=[
1146
+ gr_question_text_1_1,
1147
+ gr_answer_text_1_1,
1148
+ gr_question_text_2_1,
1149
+ gr_answer_text_2_1,
1150
+ gr_question_text_3_1,
1151
+ gr_answer_text_3_1,
1152
+ gr_score_detail,
1153
+ gr_helphulness,
1154
+ gr_correcthness,
1155
+ gr_coherence,
1156
+ gr_complexity,
1157
+ gr_verbosity,
1158
+ gr_humor,
1159
+ gr_creativity,
1160
+ gr_appropriate,
1161
+ gr_following_instructions,
1162
+ gr_politeness,
1163
+ gr_harmfulness,
1164
+ gr_hate,
1165
+ gr_sexual,
1166
+ gr_violence,
1167
+ gr_suicide,
1168
+ gr_threat,
1169
+ gr_gun,
1170
+ gr_controlled_substance,
1171
+ gr_climinal_planing,
1172
+ gr_privacy,
1173
+ gr_harassment,
1174
+ gr_profanity,
1175
+ gr_political_content,
1176
+ gr_moral_judgement,
1177
+ gr_typos
1178
+ ])
1179
+ gr_score_2_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=2),
1180
+ inputs=[gr_answer_text_2_1],
1181
+ outputs=[
1182
+ gr_question_text_1_1,
1183
+ gr_answer_text_1_1,
1184
+ gr_question_text_2_1,
1185
+ gr_answer_text_2_1,
1186
+ gr_question_text_3_1,
1187
+ gr_answer_text_3_1,
1188
+ gr_score_detail,
1189
+ gr_helphulness,
1190
+ gr_correcthness,
1191
+ gr_coherence,
1192
+ gr_complexity,
1193
+ gr_verbosity,
1194
+ gr_humor,
1195
+ gr_creativity,
1196
+ gr_appropriate,
1197
+ gr_following_instructions,
1198
+ gr_politeness,
1199
+ gr_harmfulness,
1200
+ gr_hate,
1201
+ gr_sexual,
1202
+ gr_violence,
1203
+ gr_suicide,
1204
+ gr_threat,
1205
+ gr_gun,
1206
+ gr_controlled_substance,
1207
+ gr_climinal_planing,
1208
+ gr_privacy,
1209
+ gr_harassment,
1210
+ gr_profanity,
1211
+ gr_political_content,
1212
+ gr_moral_judgement,
1213
+ gr_typos
1214
+ ])
1215
+ gr_score_3_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=3),
1216
+ inputs=[gr_answer_text_2_1],
1217
+ outputs=[
1218
+ gr_question_text_1_1,
1219
+ gr_answer_text_1_1,
1220
+ gr_question_text_2_1,
1221
+ gr_answer_text_2_1,
1222
+ gr_question_text_3_1,
1223
+ gr_answer_text_3_1,
1224
+ gr_score_detail,
1225
+ gr_helphulness,
1226
+ gr_correcthness,
1227
+ gr_coherence,
1228
+ gr_complexity,
1229
+ gr_verbosity,
1230
+ gr_humor,
1231
+ gr_creativity,
1232
+ gr_appropriate,
1233
+ gr_following_instructions,
1234
+ gr_politeness,
1235
+ gr_harmfulness,
1236
+ gr_hate,
1237
+ gr_sexual,
1238
+ gr_violence,
1239
+ gr_suicide,
1240
+ gr_threat,
1241
+ gr_gun,
1242
+ gr_controlled_substance,
1243
+ gr_climinal_planing,
1244
+ gr_privacy,
1245
+ gr_harassment,
1246
+ gr_profanity,
1247
+ gr_political_content,
1248
+ gr_moral_judgement,
1249
+ gr_typos
1250
+ ])
1251
+ gr_score_4_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=4),
1252
+ inputs=[gr_answer_text_2_1],
1253
+ outputs=[
1254
+ gr_question_text_1_1,
1255
+ gr_answer_text_1_1,
1256
+ gr_question_text_2_1,
1257
+ gr_answer_text_2_1,
1258
+ gr_question_text_3_1,
1259
+ gr_answer_text_3_1,
1260
+ gr_score_detail,
1261
+ gr_helphulness,
1262
+ gr_correcthness,
1263
+ gr_coherence,
1264
+ gr_complexity,
1265
+ gr_verbosity,
1266
+ gr_humor,
1267
+ gr_creativity,
1268
+ gr_appropriate,
1269
+ gr_following_instructions,
1270
+ gr_politeness,
1271
+ gr_harmfulness,
1272
+ gr_hate,
1273
+ gr_sexual,
1274
+ gr_violence,
1275
+ gr_suicide,
1276
+ gr_threat,
1277
+ gr_gun,
1278
+ gr_controlled_substance,
1279
+ gr_climinal_planing,
1280
+ gr_privacy,
1281
+ gr_harassment,
1282
+ gr_profanity,
1283
+ gr_political_content,
1284
+ gr_moral_judgement,
1285
+ gr_typos
1286
+ ])
1287
+ gr_score_5_btn.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=5),
1288
+ inputs=[gr_answer_text_2_1],
1289
+ outputs=[
1290
+ gr_question_text_1_1,
1291
+ gr_answer_text_1_1,
1292
+ gr_question_text_2_1,
1293
+ gr_answer_text_2_1,
1294
+ gr_question_text_3_1,
1295
+ gr_answer_text_3_1,
1296
+ gr_score_detail,
1297
+ gr_helphulness,
1298
+ gr_correcthness,
1299
+ gr_coherence,
1300
+ gr_complexity,
1301
+ gr_verbosity,
1302
+ gr_humor,
1303
+ gr_creativity,
1304
+ gr_appropriate,
1305
+ gr_following_instructions,
1306
+ gr_politeness,
1307
+ gr_harmfulness,
1308
+ gr_hate,
1309
+ gr_sexual,
1310
+ gr_violence,
1311
+ gr_suicide,
1312
+ gr_threat,
1313
+ gr_gun,
1314
+ gr_controlled_substance,
1315
+ gr_climinal_planing,
1316
+ gr_privacy,
1317
+ gr_harassment,
1318
+ gr_profanity,
1319
+ gr_political_content,
1320
+ gr_moral_judgement,
1321
+ gr_typos
1322
+ ])
1323
+
1324
+ # Scoreリセット
1325
+ def score_reset_display():
1326
+ # gr.State
1327
+ score.value = 3
1328
+ helphulness.value = 0
1329
+ correcthness.value = 0
1330
+ coherenece.value = 0
1331
+ complexity.value = 0
1332
+ verbosity.value = 0
1333
+ humor.value = 0
1334
+ creativity.value = 0
1335
+ appropriate.value = 0
1336
+ following_instructions.value = 0
1337
+ politeness.value = 0
1338
+ harmfulness.value = 0
1339
+ hate.value = 0
1340
+ sexual.value = 0
1341
+ violence.value = 0
1342
+ suicide.value = 0
1343
+ threat.value = 0
1344
+ gun.value = 0
1345
+ controlled_substance.vlaue = 0
1346
+ climinal_planing.value = 0
1347
+ privacy.value = 0
1348
+ harassment.value = 0
1349
+ profanity.value = 0
1350
+ political_content.value = 0
1351
+ moral_judgement.value = 0
1352
+ typos.value = 0
1353
+
1354
+ return 3,0,0,0,0,0,0,0,0,0,0,0, \
1355
+ "不明", "不明", "不明", "不明", "不明", \
1356
+ "不明", "不明", "不明", "不明", "不明", \
1357
+ "不明", "不明", "不明", "不明"
1358
+
1359
+ # Scoreリセット
1360
+ gr_score_reset.click(
1361
+ score_reset_display,
1362
+ inputs=[],
1363
+ outputs=[
1364
+ gr_score_detail,
1365
+ gr_helphulness,
1366
+ gr_correcthness,
1367
+ gr_coherence,
1368
+ gr_complexity,
1369
+ gr_verbosity,
1370
+ gr_humor,
1371
+ gr_creativity,
1372
+ gr_appropriate,
1373
+ gr_following_instructions,
1374
+ gr_politeness,
1375
+ gr_harmfulness,
1376
+ gr_hate,
1377
+ gr_sexual,
1378
+ gr_violence,
1379
+ gr_suicide,
1380
+ gr_threat,
1381
+ gr_gun,
1382
+ gr_controlled_substance,
1383
+ gr_climinal_planing,
1384
+ gr_privacy,
1385
+ gr_harassment,
1386
+ gr_profanity,
1387
+ gr_political_content,
1388
+ gr_moral_judgement,
1389
+ gr_typos
1390
+ ]
1391
+ )
1392
+
1393
+ # データ読込
1394
+ gr_data_load_btn.click(
1395
+ dataset_load_fn,
1396
+ inputs=None,
1397
+ # textをセットし、intractiveをTrueにする (UI更新)
1398
+ outputs=[
1399
+ gr_question_text_1_1,
1400
+ gr_answer_text_1_1,
1401
+ gr_question_text_2_1,
1402
+ gr_answer_text_2_1,
1403
+ gr_question_text_3_1,
1404
+ gr_answer_text_3_1,
1405
+ gr_answer_text_1_1,
1406
+ gr_answer_text_2_1,
1407
+ gr_answer_text_3_1,
1408
+ gr_unknown_btn,
1409
+ gr_good_btn,
1410
+ gr_bad_btn,
1411
+ gr_score_5_btn,
1412
+ gr_score_4_btn,
1413
+ gr_score_3_btn,
1414
+ gr_score_2_btn,
1415
+ gr_score_1_btn,
1416
+ gr_submit_score,
1417
+ gr_score_detail,
1418
+ gr_score_reset,
1419
+ gr_helphulness,
1420
+ gr_correcthness,
1421
+ gr_coherence,
1422
+ gr_complexity,
1423
+ gr_verbosity,
1424
+ gr_humor,
1425
+ gr_creativity,
1426
+ gr_appropriate,
1427
+ gr_following_instructions,
1428
+ gr_politeness,
1429
+ gr_harmfulness,
1430
+ gr_hate,
1431
+ gr_sexual,
1432
+ gr_violence,
1433
+ gr_suicide,
1434
+ gr_threat,
1435
+ gr_gun,
1436
+ gr_controlled_substance,
1437
+ gr_climinal_planing,
1438
+ gr_privacy,
1439
+ gr_harassment,
1440
+ gr_profanity,
1441
+ gr_political_content,
1442
+ gr_moral_judgement,
1443
+ gr_typos
1444
+ ]
1445
+ )
1446
+
1447
  # TODO Tab切り替えで、アノテ済みの一覧を表示する
1448
  # with gr.Tab("アノテ済みデータセット(管理画面)"):
1449
  # タブを切り替えた時にデータ表示を更新する