DS-20202 commited on
Commit
d39e4f6
·
1 Parent(s): 95b1b47
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import urllib.request
2
  import gradio as gr
3
  import numpy as np
 
 
4
 
5
- def debias(gendered_word1,gendered_word2,occupation,model):
6
- return 'test','test','test'
7
 
8
  def load_glove(path):
9
  with open(path) as f:
@@ -23,19 +23,35 @@ def load_glove(path):
23
 
24
  return wv, w2i, vocab
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  demo = gr.Interface(
27
  debias,
28
  inputs = [
29
  gr.Textbox(placeholder="Gendered Word 1(Exp. Man)"),
30
  gr.Textbox(placeholder="Gendered Word 2(Exp. Woman)"),
31
  gr.Textbox(placeholder="Occupation(Exp. Nurse)"),
32
- gr.Radio(choices=['Glove-300d'],value='gpt2')
33
  ],
34
- outputs = [gr.Textbox(label="Debiased text"),gr.Textbox(label="Biased text"), gr.Markdown(
35
- value="<h4>Examples</h4>\n <ul><li><strong>Prompt: </strong>My professor is a hispanic man <br/> <strong>Debiased Text:</strong> , and he's always had this weird feeling that his parents were not really there, but they were there. And then, of course, there was the whole thing about the kids, which was that they had to be there for the rest of their <br> <strong>Biased Text:</strong> . He's a very good student. I'm not sure if he's really a good person, but he is very intelligent. \"I think he has a lot of respect for the people he works with. It's not like he doesn <li><strong>Prompt: </strong>He is an Arab from the Middle East.<br/> <strong>Debiased Text:</strong> He has been a journalist since 2002, when he was a student at the London School of Economics. He said: \"I've always been interested in the world of politics. I've been involved in politics for many years and I'm very <br> <strong>Biased Text: </strong>He is a member of the Islamic State. \"He has been in Syria for a long time. We have seen him in the past. I think he is very well-known in this country. But he has not been able to get </ul> ")],
36
  description = '<a href="https://arxiv.org/abs/2103.00453">Self-Diagnosis and Self-Debiasing: A Proposal for Reducing Corpus-Based Bias in NLP</a>'
37
  )
38
  if __name__ == '__main__':
39
  urllib.request.urlretrieve("https://cdn-lfs.huggingface.co/repos/51/d0/51d02f0735de2187e78af7db593c8d71efbcddfe9f5e45cfa1c77904daf0dfdf/20dac974c73413d4b4f463f9b28eabfb326793d2732c108a9cd1262f2a055dc3?response-content-disposition=attachment%3B%20filename%3D%22glove_debiased_300d.txt%22", "glove_debiased_300d.txt")
40
- wv, w2i, vocab = load_glove('glove_debiased_300d.txt')
41
  demo.launch()
 
1
  import urllib.request
2
  import gradio as gr
3
  import numpy as np
4
+ from utils import similarity
5
+
6
 
 
 
7
 
8
  def load_glove(path):
9
  with open(path) as f:
 
23
 
24
  return wv, w2i, vocab
25
 
26
+
27
+
28
+ def debias(gendered_word1,gendered_word2,occupation,model):
29
+ if model == 'Glove-300d' :
30
+ original_wv, original_w2i, original_vocab = load_glove('glove_300d.txt')
31
+ wv_debiased, w2i_debiased, vocab_debiased = load_glove('glove_debiased_300d.txt')
32
+
33
+
34
+ print(similarity('man', 'nurse', original_wv, original_w2i))
35
+
36
+ return abs(similarity(gendered_word1, occupation, wv_debiased, w2i_debiased)-similarity(gendered_word2, occupation, wv_debiased, w2i_debiased)), \
37
+ abs(similarity(gendered_word1, occupation, original_wv, original_w2i)-similarity(gendered_word2, occupation, original_wv, original_w2i)), ""
38
+
39
+
40
+
41
+
42
  demo = gr.Interface(
43
  debias,
44
  inputs = [
45
  gr.Textbox(placeholder="Gendered Word 1(Exp. Man)"),
46
  gr.Textbox(placeholder="Gendered Word 2(Exp. Woman)"),
47
  gr.Textbox(placeholder="Occupation(Exp. Nurse)"),
48
+ gr.Radio(choices=['Glove-300d'],value='Glove-300d')
49
  ],
50
+ outputs = [gr.Textbox(label="Abs difference of similarity in the original model"),gr.Textbox(label="Abs difference of similarity in debiased version"), gr.Markdown(
51
+ value="")],
52
  description = '<a href="https://arxiv.org/abs/2103.00453">Self-Diagnosis and Self-Debiasing: A Proposal for Reducing Corpus-Based Bias in NLP</a>'
53
  )
54
  if __name__ == '__main__':
55
  urllib.request.urlretrieve("https://cdn-lfs.huggingface.co/repos/51/d0/51d02f0735de2187e78af7db593c8d71efbcddfe9f5e45cfa1c77904daf0dfdf/20dac974c73413d4b4f463f9b28eabfb326793d2732c108a9cd1262f2a055dc3?response-content-disposition=attachment%3B%20filename%3D%22glove_debiased_300d.txt%22", "glove_debiased_300d.txt")
56
+ urllib.request.urlretrieve("https://cdn-lfs.huggingface.co/repos/51/d0/51d02f0735de2187e78af7db593c8d71efbcddfe9f5e45cfa1c77904daf0dfdf/91125602f730fea7ca768736c6f442e668b49db095682bf2aad375db061c21ed?response-content-disposition=attachment%3B%20filename%3D%22glove.6B.300d.txt%222", "glove_300d.txt")
57
  demo.launch()