emilylearning commited on
Commit
f93dd76
·
1 Parent(s): d906d0f

Adding no_job example and spaces to improve markdown rendering

Browse files
Files changed (1) hide show
  1. app.py +27 -2
app.py CHANGED
@@ -263,17 +263,24 @@ def predict_gender_pronouns(
263
  title = "Changing Gender Pronouns"
264
  description = """
265
  <h2> Intro </h2>
 
266
  This is a demo for a project exploring possible spurious correlations that have been learned by our models. We first examined the training datasets and learning tasks to hypothesize what spurious correlations may exist. Below we can condition on these variables to determine what effect they may have on the prediction outcomes.
 
267
  Specially in this demo: In a user provided sentence, with at least one reference to a `DATE` and one gender pronoun, we will see how sweeping through a range of `DATE` values can change the predicted pronouns. This effect can be observed in BERT base models and in our fine-tuned models (with a specific pronoun predicting task on the [wiki-bio](https://huggingface.co/datasets/wiki_bio) dataset).
 
268
  One way to explain this phenomenon is by looking at a likely data generating process for biographical-like data in both the main BERT training dataset as well as the `wiki_bio` dataset, in the form of a causal DAG.
269
 
270
  <h2> Causal DAG </h2>
 
271
  In the DAG, we can see that `birth_place`, `birth_date` and `gender` are all independent elements that have no common cause with the other covariates in the DAG. However `birth_place`, `birth_date` and `gender` may all have a role in causing one's `access_to_resources`, with the general trend that `access_to_resources` has become less gender-dependent over time, but not in every `birth_place`, with recent events in Afghanistan providing a stark counterexample to this trend.
 
272
  Importantly, `access_to_resources` determines how, **if at all**, you may appear in the dataset's `context_words`.
 
273
  We argue that although there are complex causal interactions between each word in any given sentence, the `context_words` are more likely to cause the `gender_pronouns`, rather than vice versa. For example, if the subject is a famous doctor and the object is her wealthy father, these context words will determine which person is being referred to, and thus which gendered-pronoun to use.
274
 
275
 
276
  In this graph, arrow heads are intended to show the assumed direction of causation. E.g. as described above, we are claiming `context_words` cause the `gender_pronouns`. While causation follow direction of the arrows, statistical correlation can flow in any direction (it is cause-agnostic).
 
277
  In the case of this graph, any pink path between `context_words` and `gender_pronouns` will allow the flow of statistical correlation, inviting confounding and thus spurious correlations into the trained model.
278
 
279
  <center>
@@ -284,7 +291,9 @@ In the case of this graph, any pink path between `context_words` and `gender_pro
284
  Those familiar with causal DAGs may note when can simply condition on `gender` to block any confounding between the `context_words` and the `gender_pronouns`. However, this is not always possible, particularly in generative or mask-filling tasks where gender may be unknown, common in language modeling and in the demo below.
285
 
286
  <h2> How to use this demo </h2>
 
287
  In this demo, a user can add any sentence that contains at least one gender pronoun and the capitalized word `DATE`. We then sweep through a range of `date` values in the place of `DATE`, while masking (for prediction) the gender pronouns (included in the list below).
 
288
  ```
289
  gendered_lists = [
290
  ['he', 'she'],
@@ -296,9 +305,11 @@ gendered_lists = [
296
  ["husband", "wife"],
297
  ]
298
  ```
 
299
  In addition to choosing the test sentence, we ask that you pick how the fine-tuned model was trained:
300
  - conditioning variable: which, if any, conditioning variable from the three noted above in the DAG, was included in the text at train time.
301
  - loss function weight: weight assigned to the minority class (female pronouns in this fine-tuning dataset) that was included in the text at train time.
 
302
  You can also optionally pick a bert-like model for comparison.
303
 
304
 
@@ -308,15 +319,18 @@ Some notes:
308
 
309
 
310
  <h2> What are the results</h2>
 
311
  In the resulting plots, we can look for a dose-response relationship between:
312
  - our treatment: the sample text,
313
  - and our outcome: the predicted gender of pronouns in the text.
314
 
315
  Specifically, we are seeing if 1) making larger magnitude intervention: an older `DATE` in the text will, 2) result in a larger magnitude effect in the outcome: higher percentage of predicted female pronouns.
 
316
  Some trends that appear in the test sentences I have tried:
317
  - Conditioning on `birth_date` metadata in both training and inference text has the largest dose-response relationship. This seems reasonable, as the fine-tuned model is able to 'stratify' a learned relationship between gender pronouns and dates, when both are present in the text.
318
  - While conditioning on either no metadata or `birth_place` data training, have similar middle-ground effects for this inference task.
319
  - Finally, conditioning on `name` metadata in training, (while again conditioning on `date` in inference) has almost no dose-response relationship. It appears the learning of a `name —> gender pronouns` relationship was sufficiently successful to overwhelm any potential more nuanced learning, such as that driven by `birth_date` or `place`.
 
320
  Please feel free to ping me on the Hugging Face discord (I'm 'emily_learner' there), with any feedback/comments/concerns or interesting findings!
321
  """
322
 
@@ -337,7 +351,16 @@ death_date_example = [
337
  ['birth_date'],
338
  [1.5],
339
  BERT_LIKE_MODELS,
340
- 'Died in DATE, she was reconigized for her great accomplishments to the field of teaching.'
 
 
 
 
 
 
 
 
 
341
  ]
342
 
343
  building_date_example = [
@@ -348,6 +371,8 @@ building_date_example = [
348
  'Built in DATE, her building provided the perfect environment for her job as a teacher.'
349
  ]
350
 
 
 
351
  gr.Interface(
352
  fn=predict_gender_pronouns,
353
  inputs=[
@@ -402,5 +427,5 @@ gr.Interface(
402
  title=title,
403
  description=description,
404
  article=article,
405
- examples=[ceo_example, death_date_example, building_date_example]
406
  ).launch()
 
263
  title = "Changing Gender Pronouns"
264
  description = """
265
  <h2> Intro </h2>
266
+
267
  This is a demo for a project exploring possible spurious correlations that have been learned by our models. We first examined the training datasets and learning tasks to hypothesize what spurious correlations may exist. Below we can condition on these variables to determine what effect they may have on the prediction outcomes.
268
+
269
  Specially in this demo: In a user provided sentence, with at least one reference to a `DATE` and one gender pronoun, we will see how sweeping through a range of `DATE` values can change the predicted pronouns. This effect can be observed in BERT base models and in our fine-tuned models (with a specific pronoun predicting task on the [wiki-bio](https://huggingface.co/datasets/wiki_bio) dataset).
270
+
271
  One way to explain this phenomenon is by looking at a likely data generating process for biographical-like data in both the main BERT training dataset as well as the `wiki_bio` dataset, in the form of a causal DAG.
272
 
273
  <h2> Causal DAG </h2>
274
+
275
  In the DAG, we can see that `birth_place`, `birth_date` and `gender` are all independent elements that have no common cause with the other covariates in the DAG. However `birth_place`, `birth_date` and `gender` may all have a role in causing one's `access_to_resources`, with the general trend that `access_to_resources` has become less gender-dependent over time, but not in every `birth_place`, with recent events in Afghanistan providing a stark counterexample to this trend.
276
+
277
  Importantly, `access_to_resources` determines how, **if at all**, you may appear in the dataset's `context_words`.
278
+
279
  We argue that although there are complex causal interactions between each word in any given sentence, the `context_words` are more likely to cause the `gender_pronouns`, rather than vice versa. For example, if the subject is a famous doctor and the object is her wealthy father, these context words will determine which person is being referred to, and thus which gendered-pronoun to use.
280
 
281
 
282
  In this graph, arrow heads are intended to show the assumed direction of causation. E.g. as described above, we are claiming `context_words` cause the `gender_pronouns`. While causation follow direction of the arrows, statistical correlation can flow in any direction (it is cause-agnostic).
283
+
284
  In the case of this graph, any pink path between `context_words` and `gender_pronouns` will allow the flow of statistical correlation, inviting confounding and thus spurious correlations into the trained model.
285
 
286
  <center>
 
291
  Those familiar with causal DAGs may note when can simply condition on `gender` to block any confounding between the `context_words` and the `gender_pronouns`. However, this is not always possible, particularly in generative or mask-filling tasks where gender may be unknown, common in language modeling and in the demo below.
292
 
293
  <h2> How to use this demo </h2>
294
+
295
  In this demo, a user can add any sentence that contains at least one gender pronoun and the capitalized word `DATE`. We then sweep through a range of `date` values in the place of `DATE`, while masking (for prediction) the gender pronouns (included in the list below).
296
+
297
  ```
298
  gendered_lists = [
299
  ['he', 'she'],
 
305
  ["husband", "wife"],
306
  ]
307
  ```
308
+
309
  In addition to choosing the test sentence, we ask that you pick how the fine-tuned model was trained:
310
  - conditioning variable: which, if any, conditioning variable from the three noted above in the DAG, was included in the text at train time.
311
  - loss function weight: weight assigned to the minority class (female pronouns in this fine-tuning dataset) that was included in the text at train time.
312
+
313
  You can also optionally pick a bert-like model for comparison.
314
 
315
 
 
319
 
320
 
321
  <h2> What are the results</h2>
322
+
323
  In the resulting plots, we can look for a dose-response relationship between:
324
  - our treatment: the sample text,
325
  - and our outcome: the predicted gender of pronouns in the text.
326
 
327
  Specifically, we are seeing if 1) making larger magnitude intervention: an older `DATE` in the text will, 2) result in a larger magnitude effect in the outcome: higher percentage of predicted female pronouns.
328
+
329
  Some trends that appear in the test sentences I have tried:
330
  - Conditioning on `birth_date` metadata in both training and inference text has the largest dose-response relationship. This seems reasonable, as the fine-tuned model is able to 'stratify' a learned relationship between gender pronouns and dates, when both are present in the text.
331
  - While conditioning on either no metadata or `birth_place` data training, have similar middle-ground effects for this inference task.
332
  - Finally, conditioning on `name` metadata in training, (while again conditioning on `date` in inference) has almost no dose-response relationship. It appears the learning of a `name —> gender pronouns` relationship was sufficiently successful to overwhelm any potential more nuanced learning, such as that driven by `birth_date` or `place`.
333
+
334
  Please feel free to ping me on the Hugging Face discord (I'm 'emily_learner' there), with any feedback/comments/concerns or interesting findings!
335
  """
336
 
 
351
  ['birth_date'],
352
  [1.5],
353
  BERT_LIKE_MODELS,
354
+ 'Died in DATE, she was recognized for her great accomplishments to the field of teaching.'
355
+ ]
356
+
357
+
358
+ no_job_example = [
359
+ 20,
360
+ CONDITIONING_VARIABLES,
361
+ [1.5],
362
+ BERT_LIKE_MODELS,
363
+ 'Born in DATE, she was a happy child. Her family raised her in a loving environment where she thrived.',
364
  ]
365
 
366
  building_date_example = [
 
371
  'Built in DATE, her building provided the perfect environment for her job as a teacher.'
372
  ]
373
 
374
+
375
+
376
  gr.Interface(
377
  fn=predict_gender_pronouns,
378
  inputs=[
 
427
  title=title,
428
  description=description,
429
  article=article,
430
+ examples=[ceo_example, death_date_example, no_job_example, building_date_example]
431
  ).launch()