Spaces:
Sleeping
Sleeping
AhmedSSabir
commited on
Commit
•
0aa8ed6
1
Parent(s):
18cd94a
Update app.py
Browse files
app.py
CHANGED
@@ -115,20 +115,53 @@ def cos_sim(a, b):
|
|
115 |
|
116 |
|
117 |
#def Visual_re_ranker(caption, visual_context_label, visual_context_prob):
|
118 |
-
def Visual_re_ranker(caption_man, caption_woman, visual_context_label, visual_context_prob):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
caption_man = caption_man
|
120 |
caption_woman = caption_woman
|
121 |
-
|
122 |
-
|
123 |
caption_emb_man = model_sts.encode(caption_man, convert_to_tensor=True)
|
124 |
caption_emb_woman = model_sts.encode(caption_woman, convert_to_tensor=True)
|
125 |
-
|
126 |
|
127 |
-
sim_m = cosine_scores = util.pytorch_cos_sim(caption_emb_man,
|
128 |
sim_m = sim_m.cpu().numpy()
|
129 |
sim_m = get_sim(sim_m)
|
130 |
|
131 |
-
sim_w = cosine_scores = util.pytorch_cos_sim(caption_emb_woman,
|
132 |
sim_w = sim_w.cpu().numpy()
|
133 |
sim_w = get_sim(sim_w)
|
134 |
|
@@ -136,8 +169,8 @@ def Visual_re_ranker(caption_man, caption_woman, visual_context_label, visual_co
|
|
136 |
LM_man = cloze_prob(caption_man)
|
137 |
LM_woman = cloze_prob(caption_woman)
|
138 |
#LM = scorer.sentence_score(caption, reduce="mean")
|
139 |
-
score_man = pow(float(LM_man),pow((1-float(sim_m))/(1+ float(sim_m)),1-float(
|
140 |
-
score_woman = pow(float(LM_woman),pow((1-float(sim_w))/(1+ float(sim_w)),1-float(
|
141 |
|
142 |
|
143 |
|
@@ -150,6 +183,7 @@ def Visual_re_ranker(caption_man, caption_woman, visual_context_label, visual_co
|
|
150 |
|
151 |
|
152 |
|
|
|
153 |
demo = gr.Interface(
|
154 |
fn=Visual_re_ranker,
|
155 |
description="Demo for Women Wearing Lipstick: Measuring the Bias Between Object and Its Related Gender",
|
|
|
115 |
|
116 |
|
117 |
#def Visual_re_ranker(caption, visual_context_label, visual_context_prob):
|
118 |
+
#def Visual_re_ranker(caption_man, caption_woman, visual_context_label, visual_context_prob):
|
119 |
+
# caption_man = caption_man
|
120 |
+
# caption_woman = caption_woman
|
121 |
+
# visual_context_label= visual_context_label
|
122 |
+
# visual_context_prob = visual_context_prob
|
123 |
+
# caption_emb_man = model_sts.encode(caption_man, convert_to_tensor=True)
|
124 |
+
# caption_emb_woman = model_sts.encode(caption_woman, convert_to_tensor=True)
|
125 |
+
# visual_context_label_emb = model_sts.encode(visual_context_label, convert_to_tensor=True)
|
126 |
+
|
127 |
+
# sim_m = cosine_scores = util.pytorch_cos_sim(caption_emb_man, visual_context_label_emb)
|
128 |
+
# sim_m = sim_m.cpu().numpy()
|
129 |
+
# sim_m = get_sim(sim_m)
|
130 |
+
|
131 |
+
# sim_w = cosine_scores = util.pytorch_cos_sim(caption_emb_woman, visual_context_label_emb)
|
132 |
+
# sim_w = sim_w.cpu().numpy()
|
133 |
+
# sim_w = get_sim(sim_w)
|
134 |
+
|
135 |
+
|
136 |
+
# LM_man = cloze_prob(caption_man)
|
137 |
+
# LM_woman = cloze_prob(caption_woman)
|
138 |
+
#LM = scorer.sentence_score(caption, reduce="mean")
|
139 |
+
# score_man = pow(float(LM_man),pow((1-float(sim_m))/(1+ float(sim_m)),1-float(visual_context_prob)))
|
140 |
+
# score_woman = pow(float(LM_woman),pow((1-float(sim_w))/(1+ float(sim_w)),1-float(visual_context_prob)))
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
|
145 |
+
#return {"LM": float(LM)/1, "sim": float(sim)/1, "score": float(score)/1 }
|
146 |
+
# return {"Man": float(score_man)/1, "Woman": float(score_woman)/1}
|
147 |
+
#return LM, sim, score
|
148 |
+
|
149 |
+
|
150 |
+
|
151 |
+
def Visual_re_ranker(caption_man, caption_woman, context_label, context_prob):
|
152 |
caption_man = caption_man
|
153 |
caption_woman = caption_woman
|
154 |
+
context_label= context_label
|
155 |
+
context_prob = context_prob
|
156 |
caption_emb_man = model_sts.encode(caption_man, convert_to_tensor=True)
|
157 |
caption_emb_woman = model_sts.encode(caption_woman, convert_to_tensor=True)
|
158 |
+
context_label_emb = model_sts.encode(context_label, convert_to_tensor=True)
|
159 |
|
160 |
+
sim_m = cosine_scores = util.pytorch_cos_sim(caption_emb_man, context_label_emb)
|
161 |
sim_m = sim_m.cpu().numpy()
|
162 |
sim_m = get_sim(sim_m)
|
163 |
|
164 |
+
sim_w = cosine_scores = util.pytorch_cos_sim(caption_emb_woman, context_label_emb)
|
165 |
sim_w = sim_w.cpu().numpy()
|
166 |
sim_w = get_sim(sim_w)
|
167 |
|
|
|
169 |
LM_man = cloze_prob(caption_man)
|
170 |
LM_woman = cloze_prob(caption_woman)
|
171 |
#LM = scorer.sentence_score(caption, reduce="mean")
|
172 |
+
score_man = pow(float(LM_man),pow((1-float(sim_m))/(1+ float(sim_m)),1-float(context_prob)))
|
173 |
+
score_woman = pow(float(LM_woman),pow((1-float(sim_w))/(1+ float(sim_w)),1-float(context_prob)))
|
174 |
|
175 |
|
176 |
|
|
|
183 |
|
184 |
|
185 |
|
186 |
+
|
187 |
demo = gr.Interface(
|
188 |
fn=Visual_re_ranker,
|
189 |
description="Demo for Women Wearing Lipstick: Measuring the Bias Between Object and Its Related Gender",
|