Hey mate, thanks so much for the solution. With your code, I am able to load models in Rasa 3.3.0 (with Py 3.7.10), which aren’t trained with LanguageModelFeaturizers. The class is shown as below:
import rasa
from rasa.core.agent import Agent
from rasa.shared.utils.io import json_to_string #only for testing with example
class Load_Rasa_NLU:
def __init__(self, model_path:str) -> None:
self.agent = Agent.load(model_path)
print("NLU model loaded")
def nlu_processing(self, message: str) -> str:
message = message.strip()
results = asyncio.run(self.agent.parse_message(message))
return json_to_string(results)
For loading models:
nlu_model_path = "what_ever_a_path"
nlu_model = Load_Rasa_NLU(nlu_model_path)
But once I try to load a model, which is trained with, such as BERT, I receive such an error:
---------------------------------------------------------------------------
HFValidationError Traceback (most recent call last)
~/anaconda3/envs/rasa3.2/lib/python3.7/site-packages/rasa/engine/graph.py in _load_component(self, **kwargs)
394 execution_context=self._execution_context,
--> 395 **kwargs,
396 )
~/anaconda3/envs/rasa3.2/lib/python3.7/site-packages/rasa/engine/graph.py in load(cls, config, model_storage, resource, execution_context, **kwargs)
216 """
--> 217 return cls.create(config, model_storage, resource, execution_context)
218
~/anaconda3/envs/rasa3.2/lib/python3.7/site-packages/rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py in create(cls, config, model_storage, resource, execution_context)
97 """
---> 98 return cls(config, execution_context)
99
~/anaconda3/envs/rasa3.2/lib/python3.7/site-packages/rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py in __init__(self, config, execution_context)
64 self._load_model_metadata()
---> 65 self._load_model_instance()
66
~/anaconda3/envs/rasa3.2/lib/python3.7/site-packages/rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py in _load_model_instance(self)
150 self.tokenizer = model_tokenizer_dict[self.model_name].from_pretrained(
--> 151 self.model_weights, cache_dir=self.cache_dir
...
--> 405 ) from e
406 else:
407 logger.error(
GraphComponentException: Error initializing graph component for node run_LanguageModelFeaturizer5.
The language model is directly cloned from from its huggingface repo, and stored in the root directory of the rasa project. (parallel to ./data
or ./models
).
Can you please help me to confirm this problem in Rasa 3 or update the API for evaluation of nlu models in jupyter notebook?
Cheers :)))