def test_train_with_empty_data(component_builder): _config = utilities.base_test_conf("all_components") trainer = Trainer(_config, component_builder) trainer.train(TrainingData()) persistor = create_persistor(_config) persisted_path = trainer.persist(_config['path'], persistor, model_name=_config['name']) loaded = utilities.load_interpreter_for_model(_config, persisted_path, component_builder) assert loaded.pipeline assert loaded.parse("hello", time=None) is not None
def train(cfg_name, project_name): from rasa_nlu import training_data cfg = config.load(cfg_name) trainer = Trainer(cfg, component_builder) training_data = training_data.load_data(data) trainer.train(training_data) trainer.persist("test_projects", project_name=project_name)
def train_nlu(): from rasa_nlu.training_data import load_data from rasa_nlu import config from rasa_nlu.model import Trainer training_data = load_data('data/nlu_data/') trainer = Trainer(config.load("nlu_model_config.yml")) trainer.train(training_data) model_directory = trainer.persist('models/nlu', fixed_model_name="current") return model_directory
def test_train_with_empty_data(language, pipeline, component_builder, tmpdir): _config = RasaNLUModelConfig({"pipeline": pipeline, "language": language}) trainer = Trainer(_config, component_builder) trainer.train(TrainingData()) persistor = create_persistor(_config) persisted_path = trainer.persist(tmpdir.strpath, persistor, project_name="my_project") loaded = Interpreter.load(persisted_path, component_builder) assert loaded.pipeline assert loaded.parse("hello") is not None assert loaded.parse("Hello today is Monday, again!") is not None
def train_nlu(): from rasa_nlu.converters import load_data from rasa_nlu.config import RasaNLUConfig from rasa_nlu.model import Trainer training_data = load_data("data/mobile_nlu_data.json") trainer = Trainer(RasaNLUConfig("mobile_nlu_model_config.json")) trainer.train(training_data) model_directory = trainer.persist("models/", project_name="ivr", fixed_model_name="demo") return model_directory
def train(cfg_name, model_name): from rasa_nlu.train import create_persistor from rasa_nlu.converters import load_data config = RasaNLUConfig(cfg_name) trainer = Trainer(config) training_data = load_data(config['data']) trainer.train(training_data) persistor = create_persistor(config) trainer.persist("test_models", persistor, model_name=model_name)
def run_cv_evaluation(data, n_folds, nlu_config): from sklearn import metrics from sklearn.model_selection import StratifiedKFold from collections import defaultdict # type: (List[rasa_nlu.training_data.Message], int, RasaNLUConfig) -> Dict[Text, List[float]] """Stratified cross validation on data :param data: list of rasa_nlu.training_data.Message objects :param n_folds: integer, number of cv folds :param nlu_config: nlu config file :return: dictionary with key, list structure, where each entry in list corresponds to the relevant result for one fold """ trainer = Trainer(nlu_config) results = defaultdict(list) y_true = [e.get("intent") for e in data] skf = StratifiedKFold(n_splits=n_folds, random_state=11, shuffle=True) counter = 1 logger.info("Evaluation started") for train_index, test_index in skf.split(data, y_true): train = [data[i] for i in train_index] test = [data[i] for i in test_index] logger.debug("Fold: {}".format(counter)) logger.debug("Training ...") trainer.train(TrainingData(training_examples=train)) model_directory = trainer.persist("projects/") # Returns the directory the model is stored in logger.debug("Evaluation ...") interpreter = Interpreter.load(model_directory, nlu_config) test_y = [e.get("intent") for e in test] preds = [] for e in test: res = interpreter.parse(e.text) if res.get('intent'): preds.append(res['intent'].get('name')) else: preds.append(None) # compute fold metrics results["Accuracy"].append(metrics.accuracy_score(test_y, preds)) results["F1-score"].append(metrics.f1_score(test_y, preds, average='weighted')) results["Precision"] = metrics.precision_score(test_y, preds, average='weighted') # increase fold counter counter += 1 return dict(results)
def train_nlu_gao(): from rasa_nlu_gao.training_data import load_data from rasa_nlu_gao import config from rasa_nlu_gao.model import Trainer training_data = load_data('data/rasa_dataset_training.json') trainer = Trainer(config.load("config_embedding_bilstm.yml")) trainer.train(training_data) model_directory = trainer.persist('models/nlu_gao/', fixed_model_name="current") return model_directory
def train_models(languages): """Generate your trained model.""" utils.check_languages(languages) config = utils.load_config() for language in languages: click.echo(_("================== Processing {lang} ==================").format(lang=language)) training_data = load_data(utils.get_training_data_path(language, config)) trainer = Trainer(RasaNLUConfig(cmdline_args=config)) click.echo(_("Training data for language {lang}.").format(lang=language)) trainer.train(training_data) click.echo(_("Persisting trained data for {lang}.").format(lang=language)) model_dir = trainer.persist(utils.get_model_base_dir(language)) click.echo(_("Stored data for {lang} in {path}.").format(lang=language, path=model_dir)) click.echo(_("================ Finished Training ================"))
def do_train(cfg, # type: RasaNLUModelConfig data, # type: Text path=None, # type: Text project=None, # type: Optional[Text] fixed_model_name=None, # type: Optional[Text] storage=None, # type: Text component_builder=None, # type: Optional[ComponentBuilder] **kwargs # type: Any ): # type: (...) -> Tuple[Trainer, Interpreter, Text] """Loads the trainer and the data and runs the training of the model.""" # Ensure we are training a model that we can save in the end # WARN: there is still a race condition if a model with the same name is # trained in another subprocess trainer = Trainer(cfg, component_builder) persistor = create_persistor(storage) training_data = load_data(data, cfg.language) interpreter = trainer.train(training_data, **kwargs) if path: persisted_path = trainer.persist(path, persistor, project, fixed_model_name) else: persisted_path = None return trainer, interpreter, persisted_path
def do_train(config, component_builder=None): # type: (RasaNLUConfig, Optional[ComponentBuilder]) -> Tuple[Trainer, Interpreter, Text] """Loads the trainer and the data and runs the training of the specified model.""" # Ensure we are training a model that we can save in the end # WARN: there is still a race condition if a model with the same name is trained in another subprocess trainer = Trainer(config, component_builder) persistor = create_persistor(config) training_data = load_data(config['data']) interpreter = trainer.train(training_data) persisted_path = trainer.persist(config['path'], persistor, model_name=config['name']) return trainer, interpreter, persisted_path
def zipped_nlu_model(): spacy_config_path = "sample_configs/config_pretrained_embeddings_spacy.yml" cfg = config.load(spacy_config_path) trainer = Trainer(cfg) td = training_data.load_data(DEFAULT_DATA_PATH) trainer.train(td) trainer.persist("test_models", project_name="test_model_pretrained_embeddings") model_dir_list = os.listdir(TEST_MODEL_PATH) # directory name of latest model model_dir = sorted(model_dir_list)[-1] # path of that directory model_path = os.path.join(TEST_MODEL_PATH, model_dir) zip_path = zip_folder(model_path) return zip_path
def cross_validate(data: TrainingData, n_folds: int, nlu_config: Union[RasaNLUModelConfig, Text] ) -> CVEvaluationResult: """Stratified cross validation on data. Args: data: Training Data n_folds: integer, number of cv folds nlu_config: nlu config file Returns: dictionary with key, list structure, where each entry in list corresponds to the relevant result for one fold """ from collections import defaultdict import tempfile if isinstance(nlu_config, str): nlu_config = config.load(nlu_config) trainer = Trainer(nlu_config) train_results = defaultdict(list) test_results = defaultdict(list) entity_train_results = defaultdict(lambda: defaultdict(list)) entity_test_results = defaultdict(lambda: defaultdict(list)) tmp_dir = tempfile.mkdtemp() for train, test in generate_folds(n_folds, data): interpreter = trainer.train(train) # calculate train accuracy train_results = combine_intent_result(train_results, interpreter, train) test_results = combine_intent_result(test_results, interpreter, test) # calculate test accuracy entity_train_results = combine_entity_result(entity_train_results, interpreter, train) entity_test_results = combine_entity_result(entity_test_results, interpreter, test) shutil.rmtree(tmp_dir, ignore_errors=True) return (CVEvaluationResult(dict(train_results), dict(test_results)), CVEvaluationResult(dict(entity_train_results), dict(entity_test_results)))
def run_cv_evaluation(data, n_folds, nlu_config): # type: (TrainingData, int, RasaNLUModelConfig) -> CVEvaluationResult """Stratified cross validation on data :param data: Training Data :param n_folds: integer, number of cv folds :param nlu_config: nlu config file :return: dictionary with key, list structure, where each entry in list corresponds to the relevant result for one fold """ from collections import defaultdict import tempfile trainer = Trainer(nlu_config) train_results = defaultdict(list) test_results = defaultdict(list) entity_train_results = defaultdict(lambda: defaultdict(list)) entity_test_results = defaultdict(lambda: defaultdict(list)) tmp_dir = tempfile.mkdtemp() for train, test in generate_folds(n_folds, data): interpreter = trainer.train(train) # calculate train accuracy train_results = combine_intent_result(train_results, interpreter, train) test_results = combine_intent_result(test_results, interpreter, test) # calculate test accuracy entity_train_results = combine_entity_result(entity_train_results, interpreter, train) entity_test_results = combine_entity_result(entity_test_results, interpreter, test) shutil.rmtree(tmp_dir, ignore_errors=True) return (CVEvaluationResult(dict(train_results), dict(test_results)), CVEvaluationResult(dict(entity_train_results), dict(entity_test_results)))
def train(nlu_config: Union[Text, RasaNLUModelConfig], data: Text, path: Optional[Text] = None, project: Optional[Text] = None, fixed_model_name: Optional[Text] = None, storage: Optional[Text] = None, component_builder: Optional[ComponentBuilder] = None, training_data_endpoint: Optional[EndpointConfig] = None, **kwargs: Any ) -> Tuple[Trainer, Interpreter, Text]: """Loads the trainer and the data and runs the training of the model.""" if isinstance(nlu_config, str): nlu_config = config.load(nlu_config) # Ensure we are training a model that we can save in the end # WARN: there is still a race condition if a model with the same name is # trained in another subprocess trainer = Trainer(nlu_config, component_builder) persistor = create_persistor(storage) if training_data_endpoint is not None: training_data = load_data_from_endpoint(training_data_endpoint, nlu_config.language) else: training_data = load_data(data, nlu_config.language) interpreter = trainer.train(training_data, **kwargs) if path: persisted_path = trainer.persist(path, persistor, project, fixed_model_name) else: persisted_path = None return trainer, interpreter, persisted_path
from rasa_nlu.training_data import load_data from rasa_nlu.config import RasaNLUModelConfig from rasa_nlu.model import Trainer from rasa_nlu import config # Loading DataSet print("\nLoading the training tagged json data..") input_path = path + "/dataset/demo-rasa.json" train_data = load_data(input_path) # Config Backend using Sklearn and Spacy trainer = Trainer(config.load("config_spacy.yml")) # Training Data print("\nStarting the training phase..") trainer.train(train_data) # Returns the directory the model is stored in (Creat a folder to store model in) model_directory = trainer.persist(path + '/projects') import spacy nlp = spacy.load('en') from rasa_nlu.model import Metadata, Interpreter # where `model_directory points to the folder the model is persisted in interpreter = Interpreter.load(model_directory) print("\nThe trained models saved in the projects directory !") end = time.time() print("\nTotal time in sec taken for training ", end - start)
def train_nlu(): training_data = load_data(NLU_DATA) trainer = Trainer(RasaNLUConfig(CONFIG_PATH)) trainer.train(training_data) model_directory = trainer.persist('../models/nlu', fixed_model_name="current")
def train_nlu(data, configs, model_dir): training_data = load_data(data) trainer = Trainer(RasaNLUConfig(configs)) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name='machinenlu')
def train(self): train_data = load_data(self.data_file) trainer = Trainer(self.rasa_config) trainer.train(train_data) self.interpreter = Interpreter.load(trainer.persist(self.model_dir)) print('trained successfully')
def train_nlu(data, configs, model_dir): training_data = load_data(data) trainer = Trainer(config.load(configs)) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name='roomnlu')
def learn(arguments): path = os.path.join(os.getcwd(), 'train') if (os.path.isdir(path)): ac_path = os.path.join(os.getcwd(),'actions') files = os.listdir(ac_path) imps = [] for i in range(len(files)): name = files[i].split('.') if len(name) > 1: if name[1] == 'py' and name[0] != '__init__': name = name[0] imps.append(name) init_path = os.path.join(ac_path,'__init__.py') file = open(init_path,'w') toWrite = '__all__ = ' + str(imps) file.write(toWrite) file.close() files = os.listdir(path) common_examples = [] none_example_1 = {'text':'jshfjdhsfj','intent':'None','entities':[]} none_example_2 = {'text':'dfjkhjkfds','intent':'None','entities':[]} common_examples.append(none_example_1) common_examples.append(none_example_2) for file in files: file_data = file.split('.') intent_name = file_data[0] file_type = file_data[1] if file_type != 'txt': continue else: with open(path + '/' + file,'r') as intentFile: responses = [] examples = intentFile.readlines() examples = [*map(lambda s: s.strip(), examples)] if "<-responses->" in examples: pos = examples.index("<-responses->") responses = examples[pos+1:] examples = examples[:pos] for sample in examples: example = {} sample_split = sample.split('<=>') sample_text = sample_split[0] if len(sample_split) == 1: example['text'] = sample example['intent'] = intent_name example['entities'] = [] else: #get list of entities in the sample sample_entities = sample_split[1:] #check if paranthesis match open_paran_count = sample_text.count('(') close_paran_count = sample_text.count(')') if open_paran_count != close_paran_count: raise ValueError("Paranthesis don't match for " + sample_text) #check if paranthesis and provided entites match if open_paran_count != len(sample_entities): raise ValueError("The entities provided and words marked in entities don't match for " + sample_text) start_pos = 0 entities_count = 0 no_of_entities = len(sample_entities) entities = [] while entities_count < no_of_entities: start_pos = sample_text.find('(', start_pos, len(sample_text)) + 1 end_pos = sample_text.find(')', start_pos, len(sample_text)) entityLabel = {} entityLabel['start'] = start_pos - 1 entityLabel['end'] = end_pos - 1 entityLabel['value'] = sample_text[start_pos:end_pos] entityLabel['entity'] = sample_entities[entities_count].strip() entities.append(entityLabel) entities_count += 1 example['text'] = sample_text.replace('(','').replace(')','') example['intent'] = intent_name example['entities'] = entities common_examples.append(example) if len(responses) > 0: with open(os.path.join(os.getcwd(),"actions.json"),"r+") as jsonFile: data = json.load(jsonFile) data[intent_name] = responses jsonFile.seek(0) jsonFile.truncate() json.dump(data, jsonFile) nlp_json = {"rasa_nlu_data":{"common_examples":common_examples}} with open(os.path.join(path, 'train.json'),"w") as trainFile: json.dump(nlp_json, trainFile) with open(os.path.join(os.getcwd(), 'config.json'),"r") as jsonFile: data = json.load(jsonFile) jsonFile.close() training_data = load_data(os.path.join(path, 'train.json')) trainer = Trainer(RasaNLUConfig(os.path.join(os.getcwd(), 'config.json'))) trainer.train(training_data) model_directory = trainer.persist('models') print(model_directory) data["active_model"] = str(model_directory) with open(os.path.join(os.getcwd(), 'config.json'),"w") as jsonFile: json.dump(data, jsonFile) else: raise FileNotFoundError("No train folder found. Please setup a wizard bot first by running wiz create <bot_name>")
item = find_parent_item(word) print("item: {0} has color : {1}".format(item, word)) # Assign the colors assign_colors(doc) # Import necessary modules from rasa_nlu.training_data import load_data from rasa_nlu.config import RasaNLUModelConfig from rasa_nlu.model import Trainer from rasa_nlu import config # Create a trainer trainer = Trainer(config.load("___")) # Load the training data training_data = load_data('___') # Create an interpreter by training the model interpreter = trainer.train(___) # Try it out print( interpreter.parse( "I'm looking for a Mexican restaurant in the North of town")) print(interpreter.parse("show me Chinese food in the centre of town")) print(interpreter.parse("I want an Indian restaurant in the west")) print(interpreter.parse("are there any good pizza places in the center?"))
def create_rasa_nlu_model(): training_data = load_data('data/trainingDataRaw.json') trainer = Trainer(RasaNLUConfig("config/nlu_model_config.json")) trainer.train(training_data) model_directory = trainer.persist('models/', fixed_model_name="poc") return (model_directory)
def train(): training_data = load_data("./data/training_data.json") trainer = Trainer(config.load("config.yml")) trainer.train(training_data) model_directory = trainer.persist('./models/nlu') return model_directory
from rasa_core.policies.form_policy import FormPolicy import warnings import ruamel.yaml as yaml warnings.simplefilter('ignore', yaml.error.UnsafeLoaderWarning) logging.basicConfig(level='INFO') ''' training the nlu ''' args1 = {"pipeline": "tensorflow_embedding"} conf1 = RasaNLUModelConfig(args1) trainer1 = Trainer(conf1) #nlu for agent 1 training_data1 = load_data("./data2/nlu.md") Interpreter1 = trainer1.train(training_data1) model_directory1 = trainer1.persist('./models', fixed_model_name="ner_a2") #core for agent1 domain_file = "domain2.yml" training_data_file = './data2/stories.md' model_path = './models/dialogue_agent_2' agent = Agent(domain_file, policies=[ MemoizationPolicy(max_history=3), KerasPolicy(max_history=3, epochs=500, batch_size=10), FormPolicy() ]) data = agent.load_data(training_data_file) agent.train(data) agent.persist(model_path)
def train_nlu(data, config1, model_dir): training_data = load_data(data) trainer = Trainer(config.load(config1)) trainer.train(training_data) model_directory = trainer.persist(model_dir)
def train_nlu(data, args, model_dir): training_data = load_data(data) trainer = Trainer(config.RasaNLUModelConfig(args)) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name='weathernlu')
def train_nlu(data, configs, model_dir): training_data = load_data(data) trainer = Trainer( config.load("C:/Users/heman/Desktop/myproject/config.yml")) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name='weathernlu')
def learn(): path = os.path.join(os.getcwd(), 'train') files = os.listdir(path) common_examples = [] none_example_1 = {'text':'jshfjdhsfj','intent':'None','entities':[]} none_example_2 = {'text':'dfjkhjkfds','intent':'None','entities':[]} common_examples.append(none_example_1) common_examples.append(none_example_2) for file in files: file_data = file.split('.') intent_name = file_data[0] file_type = file_data[1] if file_type != 'txt': continue else: with open(path + '/' + file,'r') as intentFile: examples = intentFile.readlines() examples = map(lambda s: s.strip(), examples) for sample in examples: example = {} sample_split = sample.split('<=>') sample_text = sample_split[0] if len(sample_split) == 1: example['text'] = sample example['intent'] = intent_name example['entities'] = [] else: #get list of entities in the sample sample_entities = sample_split[1:] #check if paranthesis match open_paran_count = sample_text.count('(') close_paran_count = sample_text.count(')') if open_paran_count != close_paran_count: raise ValueError("Paranthesis don't match for " + sample_text) #check if paranthesis and provided entites match if open_paran_count != len(sample_entities): raise ValueError("The entities provided and words marked in entities don't match for " + sample_text) start_pos = 0 entities_count = 0 no_of_entities = len(sample_entities) entities = [] while entities_count < no_of_entities: start_pos = sample_text.find('(', start_pos, len(sample_text)) + 1 end_pos = sample_text.find(')', start_pos, len(sample_text)) entityLabel = {} entityLabel['start'] = start_pos - 1 entityLabel['end'] = end_pos - 1 entityLabel['value'] = sample_text[start_pos:end_pos] entityLabel['entity'] = sample_entities[entities_count].strip() entities.append(entityLabel) entities_count += 1 example['text'] = sample_text.replace('(','').replace(')','') example['intent'] = intent_name example['entities'] = entities common_examples.append(example) nlp_json = {"rasa_nlu_data":{"common_examples":common_examples}} with open(os.path.join(path, 'train.json'),"w") as trainFile: json.dump(nlp_json, trainFile) with open(os.path.join(os.getcwd(), 'config.json'),"r") as jsonFile: data = json.load(jsonFile) jsonFile.close() training_data = load_data(os.path.join(path, 'train.json')) trainer = Trainer(RasaNLUConfig(os.path.join(os.getcwd(), 'config.json'))) trainer.train(training_data) model_directory = trainer.persist('models') print(model_directory) data["active_model"] = str(model_directory) with open(os.path.join(os.getcwd(), 'config.json'),"w") as jsonFile: json.dump(data, jsonFile)
def train(data, config, model_dir): training_data = load_data(data) configuration = RasaNLUConfig(config) trainer = Trainer(configuration) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name='chat')
def train_model(data_path, config_path, model_path): training_data = load_data(data_path) trainer = Trainer(config.load(config_path)) trainer.train(training_data) model_directory = trainer.persist(model_path) return model_directory
'thank': ['You are welcome', 'My pleasure'], 'default': 'Sorry, I cannot understand' } state = 0 #global variables intent = None company = None info = None pending = 0 #if a pending exists nlp = spacy.load("en_core_web_md") trainer = Trainer( config.load("config_spacy.yml")) # Create a trainer that uses this config training_data = load_data('train_data.json') # Load the training data interpreter = trainer.train( training_data) # Create an interpreter by training the model def interpret(m): #intent recognition m1 = m.lower() if 'price' in m1 or 'Price' in m1: #check key words return 'latestPrice' if 'marketcap' in m1 or 'market cap' in m1: return 'marketCap' if 'volume' in m1 or 'Volume' in m1: return 'volume' if 'histor' in m1 or 'Histor' in m1: return 'history' return None
def train_bot(data_json, config_file, model_dir): training_data = load_data(data_json) trainer = Trainer(config.load(config_file)) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name='ChatTest')
def train_nlu(self, data, config, model_dir): training_data = load_data(data) trainer = Trainer(RasaNLUConfig(config)) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name='AIchatbotnlu')
def train (data, config_file, model_dir): training_data = load_data(data) trainer = Trainer(config.load(config_file)) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name = 'chat')
class RasaClassifier: # Directories & Files config_file = "rasa/config/rasa_config.json" model_dir = "rasa/projects/justiceai/" fact_data_dir = "rasa/data/fact/" category_data_dir = "rasa/data/category/" acknowledgement_data_dir = "rasa/data/acknowledgement/" # Dicts category_interpreters = {} fact_interpreters = {} acknowledgement_interpreters = {} # RASA Caching builder = ComponentBuilder(use_cache=True) def __init__(self): self.rasa_config = RasaNLUConfig(self.config_file) self.trainer = Trainer(self.rasa_config, self.builder) def train(self, force_train=False, initialize_interpreters=True): """ Trains the data sets from facts and problem categories separately :param force_train: If False will use saved models :param initialize_interpreters: If True the interpreters get initialized with models already present """ # Train fact classifier self.__train_interpreter(self.fact_data_dir, self.fact_interpreters, force_train=force_train, initialize_interpreters=initialize_interpreters) # Train problem category classifier self.__train_interpreter(self.category_data_dir, self.category_interpreters, force_train=force_train, initialize_interpreters=initialize_interpreters) # Train acknowledgement classifier self.__train_interpreter(self.acknowledgement_data_dir, self.acknowledgement_interpreters, force_train=force_train, initialize_interpreters=initialize_interpreters) def classify_problem_category(self, message, person_type): """ Classifies a claim category based on a message and person type :param message: Message received from user :param person_type: The person type of the user AS A STRING, ie: "TENANT". If passing PersonType, use .value - Ex: PersonType.TENANT.value :return: The classified claim category dict from RASA """ if person_type.lower() == "tenant": return self.category_interpreters['category_tenant'].parse(message.lower()) elif person_type.lower() == "landlord": return self.category_interpreters['category_landlord'].parse(message.lower()) def classify_fact(self, fact_name, message): """ Classifies a fact based on a message :param fact_name: Name of the fact being classified i.e. tenant_owes_rent :param message: Message received from user :return: The classified fact dict from RASA """ if fact_name in self.fact_interpreters: return self.fact_interpreters[fact_name].parse(message.lower()) return None def classify_acknowledgement(self, message): """ Classifies a true/false acknowledgement based on a message. Ie: "sure thing", "yeah ok", "nah" :param message: Message received from use :return: The classified fact dict from RASA """ return self.acknowledgement_interpreters['additional_fact_acknowledgement'].parse(message.lower()) def __train_interpreter(self, training_data_dir, interpreter_dict, force_train, initialize_interpreters): """ Trains the interpreters for fact and claim category classification :param training_data_dir: Directory where data is stores :param interpreter_dict: Dictionary will contain the interpreters :param force_train: If True will retrain model data :param initialize_interpreters: If True will initialize the interpreters """ print("~~Starting training with data directory {}~~".format(training_data_dir)) if force_train is False: print("->No force train, using saved models.".format(training_data_dir)) if initialize_interpreters is False: print("->No interpreter initialization. Will only create model data.".format(training_data_dir)) training_start = timeit.default_timer() fact_files = os.listdir(training_data_dir) for filename in fact_files: fact_key = os.path.splitext(filename)[0] if force_train: training_data = load_data(training_data_dir + filename) self.trainer.train(training_data) model_directory = self.trainer.persist(path=self.model_dir, fixed_model_name=fact_key) else: model_directory = self.model_dir + "default/" + fact_key print("Model data directory for fact {}: {}".format(fact_key, model_directory)) if initialize_interpreters: interpreter_dict[fact_key] = Interpreter.load(model_directory, self.rasa_config, self.builder) training_end = timeit.default_timer() total_training_time = round(training_end - training_start, 2) print("~~Training Finished. Took {}s for {} facts ~".format(total_training_time, len(fact_files)))
from rasa_nlu.converters import load_data from rasa_nlu.config import RasaNLUConfig from rasa_nlu.model import Trainer # create args dictionary args = {"pipeline": "spacy_sklearn"} # create a configuration and trainer config = RasaNLUConfig(cmdline_args=args) trainer = Trainer(config) # Load the training data training_data = load_data("./training_data.json") # create an interpreter by training the model interpreter = trainer.train(training_data) # Test the interpreter print( interpreter.parse( "I'm looking for a Mexican restaurant in the North of town"))
def train_nlu(): training_data = load_data(directory + "/data/train.md") trainer = Trainer(rasa_nlu.config.load(directory + "/nlu_config.yml")) trainer.train(training_data) trainer.persist(directory, project_name="models", fixed_model_name="nlu")
def train_nlu(data, config_file, model_dir): training_data = load_data(data) trainer = Trainer(config.load(config_file), builder) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name = 'restaurantnlu')
def train_nlu(data, configs, domain_dir): train_data = load_data(data) trainer = Trainer(config.load(configs)) trainer.train(train_data) model_directory = trainer.persist(domain_dir, fixed_model_name='pokedex')
def train_nlu(data, config, model_dir): training_data = load_data(data) trainer = Trainer(RasaNLUConfig(config)) trainer.train(training_data) trainer.persist(model_dir, fixed_model_name='insurancenlu')
# -*- coding: utf-8 -*- """ Created on Wed Nov 29 18:22:35 2017 @author: avhadsa """ #01 Train the Model : NRE - intent and Entities from rasa_nlu.converters import load_data from rasa_nlu.config import RasaNLUConfig from rasa_nlu.model import Trainer import simplejson training_data = load_data('./../data/Transaction_RevereseHugeData1.json') trainer = Trainer(RasaNLUConfig("./../config_spacy.json")) trainer.train(training_data) model_directory = trainer.persist('./') # Returns the directory the model is stored in #02 Test the model from rasa_nlu.model import Metadata, Interpreter from pprint import pprint # where `model_directory points to the folder the model is persisted in interpreter = Interpreter.load(model_directory, RasaNLUConfig("./../config_spacy.json")) Output = interpreter.parse(u"reverse buy transaction with activity id 6784") #reverse buy transaction with activity id 6784 simplejson.dumps(Output) pprint(Output)
def train_nlu(config_data): training_data = load_data(config_data["data"]) trainer = Trainer(config.load('./config_spacy.json'), builder) trainer.train(training_data) model_directory = trainer.persist(config_data["path"], fixed_model_name='restaurantnlu')
def train_nlu(data, configuration, model_dir): training_data = load_data(data) trainer = Trainer(config.load(configuration)) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name='chatbotnlu')
def train_nlu(data, config_file, model_dir): training_data = load_data(data) configuration = config.load(config_file) trainer = Trainer(configuration) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name="chat")
def train_nlu(data, config, model_dir): spacy.load('fr_core_news_md') training_data = load_data(data) trainer = Trainer(RasaNLUConfig(config)) trainer.train(training_data) model_directory = trainer.persist(model_dir, fixed_model_name='chatbot2')