From ba0ab0db36bb935362bf0528f2a140dca0085425 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Sat, 14 Dec 2019 16:56:26 +0530 Subject: [PATCH] fix hidden state bug --- inltk/inltk.py | 7 +++++-- setup.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/inltk/inltk.py b/inltk/inltk.py index a0a8022..13da8df 100644 --- a/inltk/inltk.py +++ b/inltk/inltk.py @@ -89,6 +89,7 @@ def get_embedding_vectors(input: str, language_code: str): path = Path(__file__).parent learn = load_learner(path / 'models' / f'{language_code}') encoder = get_model(learn.model)[0] + encoder.reset() embeddings = encoder.state_dict()['encoder.weight'] embeddings = np.array(embeddings) embedding_vectors = [] @@ -105,8 +106,9 @@ def get_sentence_encoding(input: str, language_code: str): defaults.device = torch.device('cpu') path = Path(__file__).parent learn = load_learner(path / 'models' / f'{language_code}') - m = learn.model - kk0 = m[0](Tensor([token_ids]).to(torch.int64)) + encoder = learn.model[0] + encoder.reset() + kk0 = encoder(Tensor([token_ids]).to(torch.int64)) return np.array(kk0[0][-1][0][-1]) @@ -128,6 +130,7 @@ def get_similar_sentences(sen: str, no_of_variations: int, language_code: str): path = Path(__file__).parent learn = load_learner(path / 'models' / f'{language_code}') encoder = get_model(learn.model)[0] + encoder.reset() embeddings = encoder.state_dict()['encoder.weight'] embeddings = np.array(embeddings) # cos similarity of vectors diff --git a/setup.py b/setup.py index 63179e8..d6719bd 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="inltk", - version="0.7.1", + version="0.7.2", author="Gaurav", author_email="contactgauravforwork@gmail.com", description="Natural Language Toolkit for Indian Languages (iNLTK)",