Spaces:
Build error
Build error
The app
Browse files
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='
|
33 |
],
|
34 |
-
outputs = [gr.Textbox(label="
|
35 |
-
value="
|
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 |
-
|
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()
|