emilylearning commited on
Commit
5e6d549
1 Parent(s): 2760c29

Add model dict & set up instructions

Browse files
Files changed (3) hide show
  1. .gitignore +2 -1
  2. README.md +7 -0
  3. app.py +19 -14
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  venv_sce/*
2
- .DS_Store
 
 
1
  venv_sce/*
2
+ .DS_Store
3
+ .ipynb_checkpoints/*
README.md CHANGED
@@ -12,4 +12,11 @@ pinned: false
12
  To link arXiv paper to this demo, reference below:
13
  models: https://huggingface.co/emilylearning/selection-induced-collider-bias
14
 
 
 
 
 
 
 
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
 
12
  To link arXiv paper to this demo, reference below:
13
  models: https://huggingface.co/emilylearning/selection-induced-collider-bias
14
 
15
+ # Setup env:
16
+ ```
17
+ python3 -m venv venv_sce
18
+ source venv_sce/bin/activate
19
+ pip install -r requirements.txt
20
+ ```
21
+
22
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
app.py CHANGED
@@ -8,9 +8,21 @@ import random
8
  from matplotlib.ticker import MaxNLocator
9
  from transformers import pipeline
10
 
11
- MODEL_NAMES = ["bert-base-uncased", "roberta-base", "bert-large-uncased", "roberta-large"]
12
  OWN_MODEL_NAME = 'add-a-model'
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  DECIMAL_PLACES = 1
15
  EPS = 1e-5 # to avoid /0 errors
16
 
@@ -136,10 +148,7 @@ GENDERED_LIST = [
136
 
137
  # %%
138
  # Fire up the models
139
- models = dict()
140
-
141
- for bert_like in MODEL_NAMES:
142
- models[bert_like] = pipeline("fill-mask", model=bert_like)
143
 
144
  # %%
145
 
@@ -391,12 +400,11 @@ with demo:
391
 
392
 
393
  gr.Markdown("B) Pick a pre-loaded BERT-family model of interest on the right.")
394
- gr.Markdown(f"Or C) select `{OWN_MODEL_NAME}`, then add the mame of any other Hugging Face model that supports the [fill-mask](https://huggingface.co/models?pipeline_tag=fill-mask) task on the right (note: this may take some time to load).")
395
 
396
  with gr.Row():
397
  model_name = gr.Radio(
398
- MODEL_NAMES + [OWN_MODEL_NAME],
399
- type="value",
400
  label="B) BERT-like model.",
401
  )
402
  own_model_name = gr.Textbox(
@@ -412,7 +420,6 @@ with demo:
412
  to_normalize = gr.Dropdown(
413
  ["False", "True"],
414
  label="D) Normalize model's predictions to only the gendered ones?",
415
- type="index",
416
  )
417
  place_holder = gr.Textbox(
418
  label="E) Special token place-holder",
@@ -420,7 +427,6 @@ with demo:
420
  n_fit = gr.Dropdown(
421
  list(range(1, 5)),
422
  label="F) Degree of polynomial fit",
423
- type="value",
424
  )
425
 
426
  gr.Markdown(
@@ -433,16 +439,15 @@ with demo:
433
  )
434
 
435
  gr.Markdown("## Outputs!")
436
- #gr.Markdown("Scroll down and 'Hit Submit'!")
437
  with gr.Row():
438
  btn = gr.Button("Hit submit to generate predictions!")
439
 
440
  with gr.Row():
441
  sample_text = gr.Textbox(
442
- type="auto", label="Output text: Sample of text fed to model")
443
  with gr.Row():
444
- female_fig = gr.Plot(type="auto")
445
- male_fig = gr.Plot(type="auto")
446
  with gr.Row():
447
  df = gr.Dataframe(
448
  show_label=True,
 
8
  from matplotlib.ticker import MaxNLocator
9
  from transformers import pipeline
10
 
 
11
  OWN_MODEL_NAME = 'add-a-model'
12
 
13
+ MODEL_NAME_DICT = {
14
+ "roberta-large": "RoBERTa-large",
15
+ "bert-large-uncased": "BERT-large",
16
+ "roberta-base": "RoBERTa-base",
17
+ "bert-base-uncased": "BERT-base",
18
+ "olm/olm-roberta-base-oct-2022": "OLM_RoBERTa-base",
19
+ OWN_MODEL_NAME: "Your model's"
20
+ }
21
+ MODEL_NAMES = list(MODEL_NAME_DICT.keys())
22
+
23
+ # MODEL_NAMES = ["bert-base-uncased", "roberta-base", "bert-large-uncased", "roberta-large"]
24
+ # OWN_MODEL_NAME = 'add-a-model'
25
+
26
  DECIMAL_PLACES = 1
27
  EPS = 1e-5 # to avoid /0 errors
28
 
 
148
 
149
  # %%
150
  # Fire up the models
151
+ models = {m : pipeline("fill-mask", model=m) for m in MODEL_NAMES if m != OWN_MODEL_NAME}
 
 
 
152
 
153
  # %%
154
 
 
400
 
401
 
402
  gr.Markdown("B) Pick a pre-loaded BERT-family model of interest on the right.")
403
+ gr.Markdown(f"Or C) select `{OWN_MODEL_NAME}`, then add the name of any other Hugging Face model that supports the [fill-mask](https://huggingface.co/models?pipeline_tag=fill-mask) task on the right (note: this may take some time to load).")
404
 
405
  with gr.Row():
406
  model_name = gr.Radio(
407
+ MODEL_NAMES,
 
408
  label="B) BERT-like model.",
409
  )
410
  own_model_name = gr.Textbox(
 
420
  to_normalize = gr.Dropdown(
421
  ["False", "True"],
422
  label="D) Normalize model's predictions to only the gendered ones?",
 
423
  )
424
  place_holder = gr.Textbox(
425
  label="E) Special token place-holder",
 
427
  n_fit = gr.Dropdown(
428
  list(range(1, 5)),
429
  label="F) Degree of polynomial fit",
 
430
  )
431
 
432
  gr.Markdown(
 
439
  )
440
 
441
  gr.Markdown("## Outputs!")
 
442
  with gr.Row():
443
  btn = gr.Button("Hit submit to generate predictions!")
444
 
445
  with gr.Row():
446
  sample_text = gr.Textbox(
447
+ label="Output text: Sample of text fed to model")
448
  with gr.Row():
449
+ female_fig = gr.Plot()
450
+ male_fig = gr.Plot()
451
  with gr.Row():
452
  df = gr.Dataframe(
453
  show_label=True,