Hi @Tobias_Wochinger
rasa.__version__
'1.4.5'
this is my script for sentiment.py
from rasa.nlu.components import Component
from rasa.nlu import utils
from rasa.nlu.model import Metadata
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
import os
class SentimentAnalyzer(Component):
"""A pre-trained sentiment component"""
name = "sentiment"
provides = ["entities"]
requires = []
defaults = {}
language_list = ["en"]
def __init__(self, component_config=None):
super(SentimentAnalyzer, self).__init__(component_config)
def train(self, training_data, cfg, **kwargs):
"""Not needed, because the the model is pretrained"""
pass
def convert_to_rasa(self, value, confidence):
"""Convert model output into the Rasa NLU compatible output format."""
entity = {"value": value,
"confidence": confidence,
"entity": "sentiment",
"extractor": "sentiment_extractor"}
return entity
def process(self, message, **kwargs):
"""Retrieve the text message, pass it to the classifier
and append the prediction results to the message class."""
sid = SentimentIntensityAnalyzer()
print(message.text)
res = sid.polarity_scores(message.text)
key, value = max(res.items(), key=lambda x: x[1])
# convert to output of rasa
entity = self.convert_to_rasa(key, value)
#output of the rasa model
message.set("entities", [entity], add_to_output=True)
def persist(self, model_dir):
"""Pass because a pre-trained model is already persisted"""
pass
and for run the nlu_model.py for rasa i have made this script:
from rasa_nlu.training_data import load_data
from rasa_nlu.model import Trainer
from rasa_nlu import config
# from rasa.nlu.config import RasaNLUModelConfig
# from rasa.nlu.model import Trainer
from rasa_nlu.model import Interpreter,Metadata
# from sentiment_pretrained_model import SentimentAnalyzer
def run_nlu():
interpreter = Interpreter.load('config.yml')
print(interpreter.parse("It's a wonderful application which i am using"))
if __name__ == '__main__':
#train_nlu('./data/data.json', 'config_spacy.json', './models/nlu')
run_nlu()
I think the problem is initiate the class of interpret without a specified model in spacy pipeline
with only the script of sentiment based and it’s only my pipeline.
when i run the above nlu_model.py i get this error
File “/home/ai/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/nlu/model.py”, line 73, in load
f"Failed to load model metadata from ‘{abspath}’. {e}"
rasa_nlu.model.InvalidModelError: Failed to load model metadata from ‘/home/ai/nlp/chatbots/rasa/using_models/version1.0/config.yml/metadata.json’. [Errno 20] Not a directory: ‘config.yml/metadata.json’