AhmedSSabir
commited on
Commit
•
5b61e93
1
Parent(s):
a34fc5d
Update app.py
Browse files
app.py
CHANGED
@@ -155,28 +155,28 @@ def get_sim(x):
|
|
155 |
|
156 |
|
157 |
#def Visual_re_ranker(caption, visual_context_label, visual_context_prob):
|
158 |
-
def Visual_re_ranker(
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
visual_context_label_emb = model_sbert.encode(
|
166 |
-
|
167 |
-
sim_m = cosine_scores = util.pytorch_cos_sim(
|
168 |
sim_m = sim_m.cpu().numpy()
|
169 |
sim_m = get_sim(sim_m)
|
170 |
|
171 |
-
sim_w = cosine_scores = util.pytorch_cos_sim(
|
172 |
sim_w = sim_w.cpu().numpy()
|
173 |
sim_w = get_sim(sim_w)
|
174 |
|
175 |
|
176 |
-
LM_man = cloze_prob(
|
177 |
-
LM_woman = cloze_prob(
|
178 |
-
score_man = pow(float(LM_man),pow((1-float(sim_m))/(1+ float(sim_m)),1-float(
|
179 |
-
score_woman = pow(float(LM_woman),pow((1-float(sim_w))/(1+ float(sim_w)),1-float(
|
180 |
|
181 |
|
182 |
|
|
|
155 |
|
156 |
|
157 |
#def Visual_re_ranker(caption, visual_context_label, visual_context_prob):
|
158 |
+
def Visual_re_ranker(sentence_man, sentence_woman, context_label, context_prob):
|
159 |
+
sentence_man = sentence_man
|
160 |
+
sentence_woman = sentence_woman
|
161 |
+
context_label= context_label
|
162 |
+
context_prob = context_prob
|
163 |
+
sentence_emb_man = model_sbert.encode(sentence_man, convert_to_tensor=True)
|
164 |
+
sentence_emb_woman = model_sbert.encode(sentence_woman, convert_to_tensor=True)
|
165 |
+
visual_context_label_emb = model_sbert.encode(context_label, convert_to_tensor=True)
|
166 |
+
|
167 |
+
sim_m = cosine_scores = util.pytorch_cos_sim(sentence_emb_man, context_label_emb)
|
168 |
sim_m = sim_m.cpu().numpy()
|
169 |
sim_m = get_sim(sim_m)
|
170 |
|
171 |
+
sim_w = cosine_scores = util.pytorch_cos_sim(sentence_emb_woman, context_label_emb)
|
172 |
sim_w = sim_w.cpu().numpy()
|
173 |
sim_w = get_sim(sim_w)
|
174 |
|
175 |
|
176 |
+
LM_man = cloze_prob(sentence_man)
|
177 |
+
LM_woman = cloze_prob(sentence_woman)
|
178 |
+
score_man = pow(float(LM_man),pow((1-float(sim_m))/(1+ float(sim_m)),1-float(context_prob)))
|
179 |
+
score_woman = pow(float(LM_woman),pow((1-float(sim_w))/(1+ float(sim_w)),1-float(context_prob)))
|
180 |
|
181 |
|
182 |
|