Spaces:
Running
Running
Emily McMilin
commited on
Commit
·
55392f1
1
Parent(s):
06b45ef
Avg 2 rather than 4 pts for speed. Fix plot layout
Browse files
app.py
CHANGED
@@ -9,15 +9,21 @@ from matplotlib.ticker import MaxNLocator
|
|
9 |
from transformers import pipeline
|
10 |
from winogender_sentences import get_sentences
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
OWN_MODEL_NAME = 'add-a-model'
|
16 |
PICK_YOUR_OWN_LABEL = 'pick-your-own'
|
17 |
|
18 |
DECIMAL_PLACES = 1
|
19 |
EPS = 1e-5 # to avoid /0 errors
|
20 |
-
NUM_PTS_TO_AVERAGE =
|
21 |
|
22 |
# Example date conts
|
23 |
DATE_SPLIT_KEY = "DATE"
|
@@ -102,16 +108,12 @@ def get_figure(df, model_name, occ):
|
|
102 |
ys = df[df.columns[1]]
|
103 |
|
104 |
fig, ax = plt.subplots()
|
105 |
-
# Trying small fig due to rendering issues on HF, not on VS Code
|
106 |
-
fig.set_figheight(3)
|
107 |
-
fig.set_figwidth(9)
|
108 |
ax.bar(xs, ys)
|
109 |
-
|
110 |
ax.axis('tight')
|
111 |
ax.set_xlabel("Sentence number")
|
112 |
ax.set_ylabel("Uncertainty metric")
|
113 |
ax.set_title(
|
114 |
-
f"
|
115 |
return fig
|
116 |
|
117 |
|
@@ -131,8 +133,10 @@ def predict_gender_pronouns(
|
|
131 |
|
132 |
# For debugging
|
133 |
print('input_texts', texts)
|
|
|
134 |
if model_name is None or model_name == '':
|
135 |
-
|
|
|
136 |
elif model_name not in MODEL_NAMES:
|
137 |
model = pipeline("fill-mask", model=own_model_name)
|
138 |
else:
|
@@ -208,7 +212,7 @@ with demo:
|
|
208 |
input_texts = gr.Variable([])
|
209 |
gr.Markdown("## Are you certain?")
|
210 |
gr.Markdown(
|
211 |
-
"LLMs are pretty good at reporting their uncertainty. We just need to ask the right way.")
|
212 |
gr.Markdown("Using our uncertainty metric informed by applying causal inference techniques in \
|
213 |
[Selection Collider Bias in Large Language Models](https://arxiv.org/abs/2208.10063), \
|
214 |
we are able to identify likely spurious correlations and exploit them in \
|
|
|
9 |
from transformers import pipeline
|
10 |
from winogender_sentences import get_sentences
|
11 |
|
12 |
+
MODEL_NAME_DICT = {
|
13 |
+
"roberta-large": "RoBERTa-large",
|
14 |
+
"bert-large-uncased": "BERT-large",
|
15 |
+
"roberta-base": "RoBERTa-base",
|
16 |
+
"bert-base-uncased": "BERT-base",
|
17 |
+
}
|
18 |
+
MODEL_NAMES = list(MODEL_NAME_DICT.keys())
|
19 |
+
|
20 |
|
21 |
OWN_MODEL_NAME = 'add-a-model'
|
22 |
PICK_YOUR_OWN_LABEL = 'pick-your-own'
|
23 |
|
24 |
DECIMAL_PLACES = 1
|
25 |
EPS = 1e-5 # to avoid /0 errors
|
26 |
+
NUM_PTS_TO_AVERAGE = 2
|
27 |
|
28 |
# Example date conts
|
29 |
DATE_SPLIT_KEY = "DATE"
|
|
|
108 |
ys = df[df.columns[1]]
|
109 |
|
110 |
fig, ax = plt.subplots()
|
|
|
|
|
|
|
111 |
ax.bar(xs, ys)
|
|
|
112 |
ax.axis('tight')
|
113 |
ax.set_xlabel("Sentence number")
|
114 |
ax.set_ylabel("Uncertainty metric")
|
115 |
ax.set_title(
|
116 |
+
f"{MODEL_NAME_DICT[model_name]} gender pronoun uncertainty in '{occ}' sentences")
|
117 |
return fig
|
118 |
|
119 |
|
|
|
133 |
|
134 |
# For debugging
|
135 |
print('input_texts', texts)
|
136 |
+
|
137 |
if model_name is None or model_name == '':
|
138 |
+
model_name = MODEL_NAMES[0]
|
139 |
+
model = models[model_name]
|
140 |
elif model_name not in MODEL_NAMES:
|
141 |
model = pipeline("fill-mask", model=own_model_name)
|
142 |
else:
|
|
|
212 |
input_texts = gr.Variable([])
|
213 |
gr.Markdown("## Are you certain?")
|
214 |
gr.Markdown(
|
215 |
+
"#### LLMs are pretty good at reporting their uncertainty. We just need to ask the right way.")
|
216 |
gr.Markdown("Using our uncertainty metric informed by applying causal inference techniques in \
|
217 |
[Selection Collider Bias in Large Language Models](https://arxiv.org/abs/2208.10063), \
|
218 |
we are able to identify likely spurious correlations and exploit them in \
|