Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions moverscore_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def word_mover_score(refs, hyps, idf_dict_ref, idf_dict_hyp, stop_words=[], n_gr
distance_matrix = batched_cdist_l2(raw, raw).double().cpu().numpy()

for i in range(batch_size):
c1 = np.zeros(raw.shape[1], dtype=np.float)
c2 = np.zeros(raw.shape[1], dtype=np.float)
c1 = np.zeros(raw.shape[1], dtype=float)
c2 = np.zeros(raw.shape[1], dtype=float)
c1[:len(ref_idf[i])] = ref_idf[i]
c2[len(ref_idf[i]):] = hyp_idf[i]

Expand All @@ -169,7 +169,7 @@ def word_mover_score(refs, hyps, idf_dict_ref, idf_dict_hyp, stop_words=[], n_gr

dst = distance_matrix[i]
_, flow = emd_with_flow(c1, c2, dst)
flow = np.array(flow, dtype=np.float32)
flow = np.array(flow, dtype=float)
score = 1./(1. + np.sum(flow * dst))#1 - np.sum(flow * dst)
preds.append(score)

Expand Down Expand Up @@ -198,8 +198,8 @@ def plot_example(is_flow, reference, translation, device='cuda:0'):


i = 0
c1 = np.zeros(raw.shape[1], dtype=np.float)
c2 = np.zeros(raw.shape[1], dtype=np.float)
c1 = np.zeros(raw.shape[1], dtype=float)
c2 = np.zeros(raw.shape[1], dtype=float)
c1[:len(ref_idf[i])] = ref_idf[i]
c2[len(ref_idf[i]):] = hyp_idf[i]

Expand All @@ -210,7 +210,7 @@ def plot_example(is_flow, reference, translation, device='cuda:0'):

if is_flow:
_, flow = emd_with_flow(c1, c2, dst)
new_flow = np.array(flow, dtype=np.float32)
new_flow = np.array(flow, dtype=float)
res = new_flow[:len(ref_tokens[i]), len(ref_idf[i]): (len(ref_idf[i])+len(hyp_tokens[i]))]
else:
res = 1./(1. + dst[:len(ref_tokens[i]), len(ref_idf[i]): (len(ref_idf[i])+len(hyp_tokens[i]))])
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
torch>=1.0.0
pyemd==0.5.1
pytorch-transformers>=1.1.0
numpy>=1.24