From 244b64c47c5b646c6c1e4628a438bf8a029e9f65 Mon Sep 17 00:00:00 2001 From: Nicolas Weber <weber@cl.uni-heidelberg.de> Date: Tue, 26 Feb 2019 20:24:28 +0100 Subject: [PATCH] finished WSD Method 2 + experiments --- WSD/embeddings/wsd_node_emb.py | 7 +++++-- WSD/method1_experiments/generate_exp_emb.py | 4 ++-- WSD/wsd2_exp.py | 10 +++++----- WSD/wsd_method2.py | 5 ++++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/WSD/embeddings/wsd_node_emb.py b/WSD/embeddings/wsd_node_emb.py index 24963df..078d321 100644 --- a/WSD/embeddings/wsd_node_emb.py +++ b/WSD/embeddings/wsd_node_emb.py @@ -27,8 +27,11 @@ if __name__ == '__main__': wsd_node_embeddings = [] - for x, y, z in zip(lemma_emb, gloss_emb, pos_emb): - wsd_node_embeddings.append(np.concatenate((x, y, z))) + #for x, y, z in zip(lemma_emb, gloss_emb, pos_emb): + # wsd_node_embeddings.append(np.concatenate((x, y, z))) + + for x, y in zip(lemma_emb, gloss_emb): + wsd_node_embeddings.append(np.concatenate((x, y))) wsd_node_embeddings = np.array(wsd_node_embeddings) diff --git a/WSD/method1_experiments/generate_exp_emb.py b/WSD/method1_experiments/generate_exp_emb.py index 2cfa6da..d04dd47 100644 --- a/WSD/method1_experiments/generate_exp_emb.py +++ b/WSD/method1_experiments/generate_exp_emb.py @@ -48,7 +48,7 @@ def concatenate_embeddings(emb_list, name_list): if __name__ == '__main__': - gloss_emb = load_pickle('node_embeddings_glossdummy') + gloss_emb = load_pickle('node_embeddings_gloss') lemma_emb = load_pickle('node_embeddings_lemma') lexfile_emb = load_pickle('node_embeddings_lex_file') pos_emb = load_pickle('node_embeddings_pos') @@ -57,4 +57,4 @@ if __name__ == '__main__': embs = [gloss_emb, lemma_emb, lexfile_emb, pos_emb, id_emb] names = ['gloss', 'lemma', 'lexfile', 'pos', 'id'] - concatenate_embeddings(embs, names) \ No newline at end of file + concatenate_embeddings(embs, names) diff --git a/WSD/wsd2_exp.py b/WSD/wsd2_exp.py index e3dfb81..297ee45 100644 --- a/WSD/wsd2_exp.py +++ b/WSD/wsd2_exp.py @@ -133,15 +133,15 @@ def run_experiment(window_size, document, output_file, mfs=False): if __name__ == '__main__': - windows = [5] - output_file = "method2_experiments/output_senseval3_context_" - ''' + windows = [5,10,15,20,25] + output_file = "method2_experiments/output_senseval3_nopost_" + for win in windows: for i in senseval_3: run_experiment(win, i, output_file) - ''' - output_file = "method2_experiments/output_senseval2_mfs" + + output_file = "method2_experiments/output_senseval2_nopos_" for win in windows: for i in senseval_2: run_experiment(win, i, output_file, mfs=True) diff --git a/WSD/wsd_method2.py b/WSD/wsd_method2.py index 127bb46..7a4c637 100644 --- a/WSD/wsd_method2.py +++ b/WSD/wsd_method2.py @@ -111,8 +111,11 @@ class WSD: return no_context # embed head POS-tag as POS + pos = self.pos_mapping[head[wn_tag]] pos_repr = self.pos_embedding[pos] + + # concatenate the above for a node representation of the contextS node_repr = np.concatenate((lemma_repr, gloss_repr, pos_repr)) @@ -121,7 +124,7 @@ class WSD: for sense_id in EP_synset_ids: ep_node = self.node_embeddings[sense_id] distances.append(np.linalg.norm(ep_node - node_repr)) - # return synset_id with nearest + # return synset_id that is nearest to node representation nearest_sense = EP_synset_ids[distances.index(min(distances))] wn_nearest = self.reverse_id_mapping[nearest_sense][::-1] pred_pos = wn_nearest[0] -- GitLab