emilylearning commited on
Commit
730b060
1 Parent(s): 22ca035

parity with emilylearning version, document fixes

Browse files
Files changed (1) hide show
  1. app.py +59 -46
app.py CHANGED
@@ -318,7 +318,7 @@ subreddit_example = [
318
  ', '.join(SUBREDDITS),
319
  'SUBREDDIT',
320
  "False",
321
- 1,
322
  'I saw in r/SUBREDDIT that she is a hacker.'
323
  ]
324
 
@@ -354,97 +354,90 @@ demo = gr.Blocks()
354
  with demo:
355
  gr.Markdown("## Spurious Correlation Evaluation for our LLMs")
356
  gr.Markdown("Although genders are relatively evenly distributed across time, place and interests, there are also known gender disparities in terms of access to resources. Here we demonstrate that this access disparity can result in dataset selection bias, causing models to learn a surprising range of spurious associations.")
357
- gr.Markdown("These spurious associations are often considered undesirable, as they do not match our intuition about the real-world domain from which we derive samples for inference-time prediction.")
358
- gr.Markdown("Selection of samples into datasets is a zero-sum-game, with even our high quality datasets forced to trade off one for another, thus inducing selection bias into the learned associations of the model.")
359
-
360
- gr.Markdown("### Data Generating Process")
361
- gr.Markdown("To pick values below that are most likely to cause spurious correlations, it helps to make some assumptions about the training datasets' likely data generating process, and where selection bias may come in.")
362
-
363
- gr.Markdown("A plausible data generating processes for both Wikipedia and Reddit sourced data is shown as a DAG below. These DAGs are prone to collider bias when conditioning on `access`. In other words, although in real life `place`, `date`, (subreddit) `interest` and gender are all unconditionally independent, when we condition on their common effect, `access`, they become unconditionally dependent. Composing a dataset often requires the dataset maintainers to condition on `access`. Thus LLMs learn these dataset induced dependencies, appearing to us as spurious correlations.")
364
- gr.Markdown("""
365
- <center>
366
- <img src="https://www.dropbox.com/s/f0numpllywdd271/combo_dag_block_party.png?raw=1"
367
- alt="DAG of possible data generating process for datasets used in training some of our LLMs.">
368
- </center>
369
- """)
370
-
371
- gr.Markdown("There may be misassumptions in our DAG above, which you can explore below.")
372
- gr.Markdown("Or you may be interested in applying this demo to your own model of interest. This demo _should_ work with any Hugging Face model that supports the [fill-mask](https://huggingface.co/models?pipeline_tag=fill-mask) task.")
373
-
374
  gr.Markdown("### Dose-response Relationship")
375
  gr.Markdown("One intuitive way to see the impact that changing one variable may have upon another is to look for a dose-response relationship, in which a larger intervention in the treatment (the value in text form injected in the otherwise unchanged text sample) produces a larger response in the output (the softmax probability of a gendered pronoun).")
 
376
 
377
- gr.Markdown("### This Demo")
378
- gr.Markdown("This type of plot requires a range of values along which we may see a spectrum of gender representation (or misrepresentation) in our datasets.")
379
- gr.Markdown("Click on one of the examples below (where we sweep through a spectrum of `places`, `date` and `subreddit` interest) to get an idea of whats intended here. Then try your own!")
 
380
 
 
381
  with gr.Row():
382
  gr.Markdown("X-axis sorted by older to more recent dates:")
383
- place_gen = gr.Button('Country example')
384
 
385
  gr.Markdown(
386
  "X-axis sorted by bottom 10 and top 10 [Global Gender Gap](https://www3.weforum.org/docs/WEF_GGGR_2021.pdf) ranked countries by World Economic Forum in 2021:")
387
- date_gen = gr.Button('Date example')
388
 
389
  gr.Markdown(
390
  "X-axis sorted in order of increasing self-identified female participation (see [bburky demo](http://bburky.com/subredditgenderratios/)): ")
391
- subreddit_gen = gr.Button('Subreddit example')
392
 
393
  gr.Markdown("Date example with your own model loaded! (We recommend you try after seeing how others work. It can take a while to load new model.)")
394
- your_gen = gr.Button('Your model example')
 
 
 
 
395
 
396
  with gr.Row():
397
  x_axis = gr.Textbox(
398
  lines=5,
399
- label="Pick a spectrum of comma separated values for text injection and x-axis",
400
  )
401
 
402
 
403
  gr.Markdown(
404
- "Pick a pre-loaded BERT-family model of interest, or add another Hugging Face model that supports the [fill-mask](https://huggingface.co/models?pipeline_tag=fill-mask) task (this may take some time to load).")
405
 
406
  with gr.Row():
407
  model_name = gr.Radio(
408
  MODEL_NAMES + [OWN_MODEL_NAME],
409
  type="value",
410
- label="Model: Pick a BERT-like model.",
411
  )
412
  own_model_name = gr.Textbox(
413
- label="If you selected an 'add-your-own' model, put your models Hugging Face pipeline name here. We think it should work with any model that supports the fill-mask task.",
414
  )
415
 
416
  gr.Markdown(
417
  "We are able to test the pre-trained LLMs without any modification to the models, as the gender-pronoun prediction task is simply a special case of the masked language modeling (MLM) task, with which all these models were pre-trained. Rather than random masking, the gender-pronoun prediction task masks only non-gender-neutral terms (listed in prior [Space](https://huggingface.co/spaces/emilylearning/causing_gender_pronouns_two)).")
418
- gr.Markdown("For the pre-trained LLMs the final prediction is a softmax over the entire tokenizer's vocabulary, from which we sum up the portion of the probability mass from the top five prediction words that are gendered terms. Pick if you want to the predictions normalied to these gendered terms only.")
419
- gr.Markdown("Also tell the demo what special token you will use in your input text, that you would like replaced with the spectrum of values you listed above, and the degree of polynomial fit used for high-lighting possible dose response trend ")
420
 
421
 
422
  with gr.Row():
423
  to_normalize = gr.Dropdown(
424
  ["False", "True"],
425
- label="Normalize model's predictions to only the gendered ones?",
426
  type="index",
427
  )
428
  place_holder = gr.Textbox(
429
- label="Special token place-holder that used in input text that will be replaced with the above spectrum of values.",
430
  )
431
  n_fit = gr.Dropdown(
432
  list(range(1, 5)),
433
- label="Degree of polynomial fit for high-lighting possible dose response trend",
434
  type="value",
435
  )
436
 
437
  gr.Markdown(
438
- "Finally, add input text that includes at least one gendered pronouns and one place-holder token specified above.")
439
 
440
  with gr.Row():
441
  input_text = gr.Textbox(
442
  lines=3,
443
- label="Input Text: Sentence that includes gendered pronouns and your place-holder token specified above.",
444
  )
445
 
446
  gr.Markdown("### Outputs!")
447
- gr.Markdown("Scroll down and 'Hit Submit'!")
 
 
448
 
449
  with gr.Row():
450
  sample_text = gr.Textbox(
@@ -470,12 +463,32 @@ with demo:
470
  your_gen.click(your_fn, inputs=[], outputs=[
471
  model_name, own_model_name, x_axis, place_holder, to_normalize, n_fit, input_text])
472
 
473
- with gr.Row():
474
- btn = gr.Button("Hit submit")
475
- btn.click(
476
- predict_gender_pronouns,
477
- inputs=[model_name, own_model_name, x_axis, place_holder,
478
- to_normalize, n_fit, input_text],
479
- outputs=[sample_text, female_fig, male_fig, df])
480
-
481
- demo.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  ', '.join(SUBREDDITS),
319
  'SUBREDDIT',
320
  "False",
321
+ 3,
322
  'I saw in r/SUBREDDIT that she is a hacker.'
323
  ]
324
 
 
354
  with demo:
355
  gr.Markdown("## Spurious Correlation Evaluation for our LLMs")
356
  gr.Markdown("Although genders are relatively evenly distributed across time, place and interests, there are also known gender disparities in terms of access to resources. Here we demonstrate that this access disparity can result in dataset selection bias, causing models to learn a surprising range of spurious associations.")
357
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  gr.Markdown("### Dose-response Relationship")
359
  gr.Markdown("One intuitive way to see the impact that changing one variable may have upon another is to look for a dose-response relationship, in which a larger intervention in the treatment (the value in text form injected in the otherwise unchanged text sample) produces a larger response in the output (the softmax probability of a gendered pronoun).")
360
+ gr.Markdown("This dose-response plot requires a range of values along which we may see a spectrum of gender representation (or misrepresentation) in our datasets.")
361
 
362
+ gr.Markdown("## This Demo")
363
+ gr.Markdown("1) Click on one of the examples below (where we sweep through a spectrum of `places`, `date` and `subreddit` interest) to pre-populate the input fields.")
364
+ gr.Markdown("2) Check out the pre-populated fields as you scroll down to the ['Hit Submit...'] button!")
365
+ gr.Markdown("3) Repeat steps (1) and (2) with more pre-populated inputs or with your own values in the input fields!")
366
 
367
+ gr.Markdown("### Example inputs")
368
  with gr.Row():
369
  gr.Markdown("X-axis sorted by older to more recent dates:")
370
+ place_gen = gr.Button('Click for country example inputs')
371
 
372
  gr.Markdown(
373
  "X-axis sorted by bottom 10 and top 10 [Global Gender Gap](https://www3.weforum.org/docs/WEF_GGGR_2021.pdf) ranked countries by World Economic Forum in 2021:")
374
+ date_gen = gr.Button('Click for date example inputs')
375
 
376
  gr.Markdown(
377
  "X-axis sorted in order of increasing self-identified female participation (see [bburky demo](http://bburky.com/subredditgenderratios/)): ")
378
+ subreddit_gen = gr.Button('Click for Subreddit example inputs')
379
 
380
  gr.Markdown("Date example with your own model loaded! (We recommend you try after seeing how others work. It can take a while to load new model.)")
381
+ your_gen = gr.Button('Click for your model example inputs')
382
+
383
+ gr.Markdown("### Input fields")
384
+ gr.Markdown(
385
+ f"A) Pick a spectrum of comma separated values for text injection and x-axis, described above in the Dose-response Relationship section.")
386
 
387
  with gr.Row():
388
  x_axis = gr.Textbox(
389
  lines=5,
390
+ label="A) Pick a spectrum of comma separated values for text injection and x-axis",
391
  )
392
 
393
 
394
  gr.Markdown(
395
+ f"B) Pick a pre-loaded BERT-family model of interest on the right. C) Or 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).")
396
 
397
  with gr.Row():
398
  model_name = gr.Radio(
399
  MODEL_NAMES + [OWN_MODEL_NAME],
400
  type="value",
401
+ label="B) Pick a BERT-like model.",
402
  )
403
  own_model_name = gr.Textbox(
404
+ label="C) If you selected an 'add-your-own' model, put your models Hugging Face pipeline name here. We think it should work with any model that supports the fill-mask task.",
405
  )
406
 
407
  gr.Markdown(
408
  "We are able to test the pre-trained LLMs without any modification to the models, as the gender-pronoun prediction task is simply a special case of the masked language modeling (MLM) task, with which all these models were pre-trained. Rather than random masking, the gender-pronoun prediction task masks only non-gender-neutral terms (listed in prior [Space](https://huggingface.co/spaces/emilylearning/causing_gender_pronouns_two)).")
409
+ gr.Markdown("For the pre-trained LLMs the final prediction is a softmax over the entire tokenizer's vocabulary, from which we sum up the portion of the probability mass from the top five prediction words that are gendered terms. D) Pick if you want to the predictions normalied to these gendered terms only.")
410
+ gr.Markdown("E) Also tell the demo what special token you will use in your input text, that you would like replaced with the spectrum of values you listed above, and F) the degree of polynomial fit used for high-lighting possible dose response trend ")
411
 
412
 
413
  with gr.Row():
414
  to_normalize = gr.Dropdown(
415
  ["False", "True"],
416
+ label="D) Normalize model's predictions to only the gendered ones?",
417
  type="index",
418
  )
419
  place_holder = gr.Textbox(
420
+ label="E) Special token place-holder that used in input text that will be replaced with the above spectrum of values.",
421
  )
422
  n_fit = gr.Dropdown(
423
  list(range(1, 5)),
424
+ label="F) Degree of polynomial fit for high-lighting possible dose response trend",
425
  type="value",
426
  )
427
 
428
  gr.Markdown(
429
+ "G) Finally, add input text that includes at least one gendered pronouns and one place-holder token specified above.")
430
 
431
  with gr.Row():
432
  input_text = gr.Textbox(
433
  lines=3,
434
+ label="G) Input text that includes gendered pronouns and your place-holder token specified above.",
435
  )
436
 
437
  gr.Markdown("### Outputs!")
438
+ #gr.Markdown("Scroll down and 'Hit Submit'!")
439
+ with gr.Row():
440
+ btn = gr.Button("Hit submit to generate predictions!")
441
 
442
  with gr.Row():
443
  sample_text = gr.Textbox(
 
463
  your_gen.click(your_fn, inputs=[], outputs=[
464
  model_name, own_model_name, x_axis, place_holder, to_normalize, n_fit, input_text])
465
 
466
+ btn.click(
467
+ predict_gender_pronouns,
468
+ inputs=[model_name, own_model_name, x_axis, place_holder,
469
+ to_normalize, n_fit, input_text],
470
+ outputs=[sample_text, female_fig, male_fig, df])
471
+
472
+
473
+ gr.Markdown("### What is Causing these Spurious Correlations?")
474
+
475
+ gr.Markdown("Spurious correlations are often considered undesirable, as they do not match our intuition about the real-world domain from which we derive samples for inference-time prediction.")
476
+ gr.Markdown("Selection of samples into datasets is a zero-sum-game, with even our high quality datasets forced to trade off one for another, thus inducing selection bias into the learned associations of the model.")
477
+
478
+ gr.Markdown("### Data Generating Process")
479
+ gr.Markdown("To pick values below that are most likely to cause spurious correlations, it helps to make some assumptions about the training datasets' likely data generating process, and where selection bias may come in.")
480
+
481
+ gr.Markdown("A plausible data generating processes for both Wikipedia and Reddit sourced data is shown as a DAG below. These DAGs are prone to collider bias when conditioning on `access`. In other words, although in real life `place`, `date`, (subreddit) `interest` and gender are all unconditionally independent, when we condition on their common effect, `access`, they become unconditionally dependent. Composing a dataset often requires the dataset maintainers to condition on `access`. Thus LLMs learn these dataset induced dependencies, appearing to us as spurious correlations.")
482
+ gr.Markdown("""
483
+ <center>
484
+ <img src="https://www.dropbox.com/s/f0numpllywdd271/combo_dag_block_party.png?raw=1"
485
+ alt="DAG of possible data generating process for datasets used in training some of our LLMs.">
486
+ </center>
487
+ """)
488
+
489
+ gr.Markdown("There may be misassumptions in our DAG above, which you can explore below.")
490
+ gr.Markdown("Or you may be interested in applying this demo to your own model of interest. This demo _should_ work with any Hugging Face model that supports the [fill-mask](https://huggingface.co/models?pipeline_tag=fill-mask) task.")
491
+
492
+ demo.launch(debug=True)
493
+
494
+ # %%