AttributeError: 'LSTM' object has no attribute '_flat_weights'

username: Prakash48
cooked: <p>I am getting the error while executing the below code<br>
Code:<br>
from inltk.inltk import get_similar_sentences<br>
get_similar_sentences(‘मैं आज बहुत खुश हूं’, 3, ‘hi’, degree_of_aug = 0.1)<br>
Error:<br>
AttributeError                            Traceback (most recent call last)<br>
Cell In[11], line 1<br>
----&gt; 1 get_similar_sentences(‘मैं आज बहुत खुश हूं’, 3, ‘hi’, degree_of_aug = 0.1)</p>
<p>File ~\anaconda3\envs\env-1\lib\site-packages\inltk\inltk.py:137, in get_similar_sentences(sen, no_of_variations, language_code, degree_of_aug)<br>
135 tok = LanguageTokenizer(language_code)<br>
136 token_ids = tok.numericalize(sen)<br>
 → 137 embedding_vectors = get_embedding_vectors(sen, language_code)<br>
138 # get learner<br>
139 defaults.device = torch.device(‘cpu’)</p>
<p>File ~\anaconda3\envs\env-1\lib\site-packages\inltk\inltk.py:100, in get_embedding_vectors(input, language_code)<br>
98 defaults.device = torch.device(‘cpu’)<br>
99 path = Path(<strong>file</strong>).parent<br>
 → 100 learn = load_learner(path / ‘models’ / f’{language_code}')<br>
101 encoder = get_model(learn.model)[0]<br>
102 encoder.reset()</p>
<p>File ~\anaconda3\envs\env-1\lib\site-packages\fastai\basic_train.py:619, in load_learner(path, file, test, **db_kwargs)<br>
617 “Load a <code>Learner</code> object saved with <code>export_state</code> in <code>path/file</code> with empty data, optionally add <code>test</code> and load on <code>cpu</code>. <code>file</code> can be file-like (file or buffer)”<br>
618 source = Path(path)/file if is_pathlike(file) else file<br>
 → 619 state = torch.load(source, map_location=‘cpu’) if defaults.device == torch.device(‘cpu’) else torch.load(source)<br>
620 model = state.pop(‘model’)<br>
621 src = LabelLists.load_state(path, state.pop(‘data’))</p>
<p>File ~\anaconda3\envs\env-1\lib\site-packages\torch\serialization.py:815, in load(f, map_location, pickle_module, weights_only, **pickle_load_args)<br>
813     except RuntimeError as e:<br>
814         raise pickle.UnpicklingError(UNSAFE_MESSAGE + str(e)) from None<br>
 → 815 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)</p>
<p>File ~\anaconda3\envs\env-1\lib\site-packages\torch\serialization.py:1043, in _legacy_load(f, map_location, pickle_module, **pickle_load_args)<br>
1041 unpickler = UnpicklerWrapper(f, **pickle_load_args)<br>
1042 unpickler.persistent_load = persistent_load<br>
 → 1043 result = unpickler.load()<br>
1045 deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)<br>
1047 offset = f.tell() if f_should_read_directly else None</p>
<p>File ~\anaconda3\envs\env-1\lib\site-packages\torch\nn\modules\rnn.py:325, in RNNBase.<strong>setstate</strong>(self, d)<br>
320                     self._flat_weights_names.extend(weights[:2])<br>
321     self._flat_weights = [getattr(self, wn) if hasattr(self, wn) else None<br>
322                           for wn in self._flat_weights_names]<br>
324 self._flat_weight_refs = [weakref.ref(w) if w is not None else None<br>
 → 325                           for w in self._flat_weights]</p>
<p>File ~\anaconda3\envs\env-1\lib\site-packages\torch\nn\modules\module.py:1614, in Module.<strong>getattr</strong>(self, name)<br>
1612     if name in modules:<br>
1613         return modules[name]<br>
 → 1614 raise AttributeError(“‘{}’ object has no attribute ‘{}’”.format(<br>
1615     type(self).<strong>name</strong>, name))</p>
<p>AttributeError: ‘LSTM’ object has no attribute ‘_flat_weights’</p>