Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -272,25 +272,17 @@ def retrieveSentences(gr1, gr2, att1, att2, progress=gr.Progress()):
|
|
| 272 |
gr.update(value=', '.join(a2)) # att2_fixed
|
| 273 |
)
|
| 274 |
|
| 275 |
-
def bloombergViz(val):
|
| 276 |
percent = round(val * 100)
|
| 277 |
percentStr = f"{percent}"
|
| 278 |
-
numblocks = 10
|
| 279 |
-
# options: 4, 9, 10
|
| 280 |
-
if percentStr in ['0', '25', '26', '27', '48', '49', '50', '51', '52', '73', '74', '75']:
|
| 281 |
-
numblocks = 4
|
| 282 |
-
elif percentStr in ['11', '12', '13', '22', '23', '24', '32', '33', '34', '42', '43', '44', '45', '46', '53', '54', '55', '56', '57', '64', '65', '66', '67', '76', '77', '86', '87', '88']:
|
| 283 |
-
numblocks = 9
|
| 284 |
-
else:
|
| 285 |
-
numblocks = 10
|
| 286 |
filled = "<div style='height:20px;width:20px;background-color:#555;display:inline-block'></div> "
|
| 287 |
unfilled = "<div style='height:20px;width:20px;background-color:#999;display:inline-block'></div> "
|
| 288 |
numFilled = round((percent/100) * numblocks)
|
| 289 |
numUnFilled = numblocks - numFilled
|
| 290 |
return numFilled * filled + numUnFilled * unfilled
|
| 291 |
|
| 292 |
-
def att_bloombergViz(att, val):
|
| 293 |
-
viz = bloombergViz(val)
|
| 294 |
attHTML = f"<div style='border-style:solid;border-color:#999;border-radius:12px'>{att}: {round(val*100)}%<br>{viz}</div><br>"
|
| 295 |
return attHTML
|
| 296 |
|
|
@@ -310,6 +302,13 @@ def startBiasTest(test_sentences_df, gr1, gr2, att1, att2, model_name, progress=
|
|
| 310 |
print(f"Type: {type(test_sentences_df)}")
|
| 311 |
print(f"Data: {test_sentences_df}")
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
# 1. bias specification
|
| 314 |
bias_spec = getTermsFromGUI(gr1, gr2, att1, att2)
|
| 315 |
print(f"Bias spec dict: {bias_spec}")
|
|
@@ -353,7 +352,7 @@ def startBiasTest(test_sentences_df, gr1, gr2, att1, att2, model_name, progress=
|
|
| 353 |
num_atts = 0
|
| 354 |
for att, score in attrib_by_score.items():
|
| 355 |
if att in attributes_g1:
|
| 356 |
-
per_attrib_bias_HTML_stereo += att_bloombergViz(att, score)
|
| 357 |
num_atts += 1
|
| 358 |
if num_atts >= 8:
|
| 359 |
break
|
|
@@ -362,7 +361,7 @@ def startBiasTest(test_sentences_df, gr1, gr2, att1, att2, model_name, progress=
|
|
| 362 |
num_atts = 0
|
| 363 |
for att, score in attrib_by_score.items():
|
| 364 |
if att in attributes_g2:
|
| 365 |
-
per_attrib_bias_HTML_antistereo += att_bloombergViz(att, score)
|
| 366 |
num_atts += 1
|
| 367 |
if num_atts >= 8:
|
| 368 |
break
|
|
|
|
| 272 |
gr.update(value=', '.join(a2)) # att2_fixed
|
| 273 |
)
|
| 274 |
|
| 275 |
+
def bloombergViz(val, numblocks=10):
|
| 276 |
percent = round(val * 100)
|
| 277 |
percentStr = f"{percent}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
filled = "<div style='height:20px;width:20px;background-color:#555;display:inline-block'></div> "
|
| 279 |
unfilled = "<div style='height:20px;width:20px;background-color:#999;display:inline-block'></div> "
|
| 280 |
numFilled = round((percent/100) * numblocks)
|
| 281 |
numUnFilled = numblocks - numFilled
|
| 282 |
return numFilled * filled + numUnFilled * unfilled
|
| 283 |
|
| 284 |
+
def att_bloombergViz(att, val, numblocks):
|
| 285 |
+
viz = bloombergViz(val, numblocks)
|
| 286 |
attHTML = f"<div style='border-style:solid;border-color:#999;border-radius:12px'>{att}: {round(val*100)}%<br>{viz}</div><br>"
|
| 287 |
return attHTML
|
| 288 |
|
|
|
|
| 302 |
print(f"Type: {type(test_sentences_df)}")
|
| 303 |
print(f"Data: {test_sentences_df}")
|
| 304 |
|
| 305 |
+
att_freqs = {}
|
| 306 |
+
for att in test_sentences_df["Attribute term"].tolist():
|
| 307 |
+
if att in att_freqs:
|
| 308 |
+
att_freqs[att] = 1
|
| 309 |
+
else:
|
| 310 |
+
att_freqs[att] += 1
|
| 311 |
+
|
| 312 |
# 1. bias specification
|
| 313 |
bias_spec = getTermsFromGUI(gr1, gr2, att1, att2)
|
| 314 |
print(f"Bias spec dict: {bias_spec}")
|
|
|
|
| 352 |
num_atts = 0
|
| 353 |
for att, score in attrib_by_score.items():
|
| 354 |
if att in attributes_g1:
|
| 355 |
+
per_attrib_bias_HTML_stereo += att_bloombergViz(att, score, att_freqs[att])
|
| 356 |
num_atts += 1
|
| 357 |
if num_atts >= 8:
|
| 358 |
break
|
|
|
|
| 361 |
num_atts = 0
|
| 362 |
for att, score in attrib_by_score.items():
|
| 363 |
if att in attributes_g2:
|
| 364 |
+
per_attrib_bias_HTML_antistereo += att_bloombergViz(att, score, att_freqs[att])
|
| 365 |
num_atts += 1
|
| 366 |
if num_atts >= 8:
|
| 367 |
break
|