Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bugs for data selection #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions beat/algorithms/loicbarrault/mt_lifelong_loop/1.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,13 @@ def get_sen_vecs(data_dict_train, src_vocab, word_embs):

for index_sen, sen in enumerate(data_dict_train['src']):
splitsen = sen.split()
sen_length = 0
for token in splitsen:
if token in src_vocab.keys():
sen_length += 1
index_token = int(src_vocab[token].split()[0])
sen_vecs[index_sen] = word_embs[index_token]
sen_vecs[index_sen] /= len(splitsen)
sen_vecs[index_sen] += word_embs[index_token]
sen_vecs[index_sen] /= sen_length

return sen_vecs

Expand Down Expand Up @@ -324,11 +326,13 @@ def data_selection_emb(N, data_dict_train, train_sen_vecs, doc_input, src_vocab,
for sen in doc_input:
sen_vec = torch.zeros(1, word_embs.size()[1], dtype=word_embs.dtype, device=word_embs.device)
splitsen = sen.split()
sen_length = 0
for token in splitsen:
if token in src_vocab.keys():
sen_length += 1
index = int(src_vocab[token].split()[0])
sen_vec += word_embs[index]
sen_vec /= len(splitsen)
sen_vec /= sen_length
coss = cos(sen_vec, train_sen_vecs)
coss[torch.isnan(coss)] = 0
index_topn_sens = torch.topk(coss, n, largest=True).indices
Expand Down