Rafal commited on
Commit
86f7404
1 Parent(s): 6b3a2d6

Linked to AnimaLab biases repo

Browse files
Files changed (3) hide show
  1. app.py +37 -2
  2. mgr_biases.py +1 -1
  3. mgr_sentences.py +1 -1
app.py CHANGED
@@ -581,6 +581,8 @@ def startBiasTest(test_sentences_df, gr1, gr2, att1, att2, model_name, progress=
581
  model_name, bias_stats_dict, per_attrib_bias,
582
  score_templates_df
583
  )
 
 
584
 
585
  return (err_update, # error message
586
  gr.Markdown.update(visible=True), # bar progress
@@ -687,6 +689,41 @@ def changeTerm(evt: gr.EventData):
687
 
688
  return gr.update(interactive=False, visible=False)
689
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
690
  theme = gr.themes.Soft().set(
691
  button_small_radius='*radius_xxs',
692
  background_fill_primary='*neutral_50',
@@ -784,8 +821,6 @@ with gr.Blocks(theme=soft, title="Social Bias Testing in Language Models",
784
  "Mental/Physical Disease <> Temporary/Permanent",
785
  ], label="Example Biases", #info="Select a predefied bias specification to fill-out the terms below."
786
  )
787
- #bias_img = gr.HTML(value="<img src='https://docs.streamlit.io/logo.svg'>Bias test result saved! </img>",
788
- # visible=True)
789
  with gr.Row(elem_id="group_row"):
790
  group1 = gr.Textbox(label="Social Group 1", max_lines=1, elem_id="group1_words", elem_classes="input_words", placeholder="brother, father")
791
  group2 = gr.Textbox(label='Social Group 2', max_lines=1, elem_id="group2_words", elem_classes="input_words", placeholder="sister, mother")
 
581
  model_name, bias_stats_dict, per_attrib_bias,
582
  score_templates_df
583
  )
584
+
585
+ saveBiasTestResult(test_sentences_df, gr1, gr2, att1, att2, model_name)
586
 
587
  return (err_update, # error message
588
  gr.Markdown.update(visible=True), # bar progress
 
689
 
690
  return gr.update(interactive=False, visible=False)
691
 
692
+ def saveBiasTestResult(test_sentences_df, group1, group2, att1, att2, model_name):
693
+ print(f"Saving bias test result...")
694
+
695
+ #print(f"Group_1: {group1}")
696
+ #print(f"Group_2: {group2}")
697
+
698
+ #print(f"Attribute_1: {att1}")
699
+ #print(f"Attribute_2: {att2}")
700
+
701
+ print(f"Tested model: {model_name}")
702
+ terms = getTermsFromGUI(group1, group2, att1, att2)
703
+ group1, group2 = bmgr.getSocialGroupTerms(terms)
704
+ att1, att2 = bmgr.getAttributeTerms(terms)
705
+
706
+ bias_name = bmgr.getBiasName(group1, group2, att1, att2)
707
+
708
+ print(f"bias_name: {bias_name}")
709
+ print(f"Terms: {terms}")
710
+
711
+ bias_spec_json = {
712
+ "name": bias_name,
713
+ "source": "bias-test-gpt-tool",
714
+ "social_groups": terms['social_groups'],
715
+ "attributes": terms['attributes'],
716
+ "tested_results": {
717
+ "tested_model": model_name
718
+ },
719
+ "templates": [],
720
+ "sentences": []
721
+ }
722
+
723
+ bmgr.save_custom_bias(f"{bias_name}.json", bias_spec_json)
724
+
725
+ #return gr.update(value="Bias test result saved!", visible=True)
726
+
727
  theme = gr.themes.Soft().set(
728
  button_small_radius='*radius_xxs',
729
  background_fill_primary='*neutral_50',
 
821
  "Mental/Physical Disease <> Temporary/Permanent",
822
  ], label="Example Biases", #info="Select a predefied bias specification to fill-out the terms below."
823
  )
 
 
824
  with gr.Row(elem_id="group_row"):
825
  group1 = gr.Textbox(label="Social Group 1", max_lines=1, elem_id="group1_words", elem_classes="input_words", placeholder="brother, father")
826
  group2 = gr.Textbox(label='Social Group 2', max_lines=1, elem_id="group2_words", elem_classes="input_words", placeholder="sister, mother")
mgr_biases.py CHANGED
@@ -10,7 +10,7 @@ import huggingface_hub
10
  print("hfh", huggingface_hub.__version__)
11
  from huggingface_hub import hf_hub_download, upload_file, delete_file, snapshot_download, list_repo_files, dataset_info
12
 
13
- DATASET_REPO_ID = "RKocielnik/bias_test_gpt_biases"
14
  DATASET_REPO_URL = f"https://huggingface.co/{DATASET_REPO_ID}"
15
  HF_DATA_DIRNAME = "."
16
 
 
10
  print("hfh", huggingface_hub.__version__)
11
  from huggingface_hub import hf_hub_download, upload_file, delete_file, snapshot_download, list_repo_files, dataset_info
12
 
13
+ DATASET_REPO_ID = "AnimaLab/bias-test-gpt-biases"
14
  DATASET_REPO_URL = f"https://huggingface.co/{DATASET_REPO_ID}"
15
  HF_DATA_DIRNAME = "."
16
 
mgr_sentences.py CHANGED
@@ -8,7 +8,7 @@ import huggingface_hub
8
  print("hfh", huggingface_hub.__version__)
9
  from huggingface_hub import hf_hub_download, upload_file, delete_file, snapshot_download, list_repo_files, dataset_info
10
 
11
- DATASET_REPO_ID = "AnimaLab/bias-test-gpt-sentences" #"RKocielnik/bias-test-gpt-sentences4"
12
  DATASET_REPO_URL = f"https://huggingface.co/{DATASET_REPO_ID}"
13
  HF_DATA_DIRNAME = "data"
14
  LOCAL_DATA_DIRNAME = "data"
 
8
  print("hfh", huggingface_hub.__version__)
9
  from huggingface_hub import hf_hub_download, upload_file, delete_file, snapshot_download, list_repo_files, dataset_info
10
 
11
+ DATASET_REPO_ID = "AnimaLab/bias-test-gpt-sentences"
12
  DATASET_REPO_URL = f"https://huggingface.co/{DATASET_REPO_ID}"
13
  HF_DATA_DIRNAME = "data"
14
  LOCAL_DATA_DIRNAME = "data"