AhmedSSabir commited on
Commit
5b61e93
1 Parent(s): a34fc5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
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(caption_man, caption_woman, visual_context_label, visual_context_prob):
159
- caption_man = caption_man
160
- caption_woman = caption_woman
161
- visual_context_label= visual_context_label
162
- visual_context_prob = visual_context_prob
163
- caption_emb_man = model_sbert.encode(caption_man, convert_to_tensor=True)
164
- caption_emb_woman = model_sbert.encode(caption_woman, convert_to_tensor=True)
165
- visual_context_label_emb = model_sbert.encode(visual_context_label, convert_to_tensor=True)
166
-
167
- sim_m = cosine_scores = util.pytorch_cos_sim(caption_emb_man, visual_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(caption_emb_woman, visual_context_label_emb)
172
  sim_w = sim_w.cpu().numpy()
173
  sim_w = get_sim(sim_w)
174
 
175
 
176
- LM_man = cloze_prob(caption_man)
177
- LM_woman = cloze_prob(caption_woman)
178
- score_man = pow(float(LM_man),pow((1-float(sim_m))/(1+ float(sim_m)),1-float(visual_context_prob)))
179
- score_woman = pow(float(LM_woman),pow((1-float(sim_w))/(1+ float(sim_w)),1-float(visual_context_prob)))
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