def train(self, training_data, mitie_file, num_threads): # type: (TrainingData, Text, Optional[int]) -> None import mitie trainer = mitie.text_categorizer_trainer(mitie_file) trainer.num_threads = num_threads for example in training_data.intent_examples: tokens = mitie.tokenize(example["text"]) trainer.add_labeled_text(tokens, example["intent"]) if training_data.intent_examples: # we can not call train if there are no examples! self.clf = trainer.train()
def train(self, training_data, config, **kwargs): # type: (TrainingData, RasaNLUConfig, **Any) -> None import mitie trainer = mitie.text_categorizer_trainer(config["mitie_file"]) trainer.num_threads = config["num_threads"] for example in training_data.intent_examples: tokens = self._tokens_of_message(example) trainer.add_labeled_text(tokens, example.get("intent")) if training_data.intent_examples: # we can not call train if there are no examples! self.clf = trainer.train()
def train(self, training_data, cfg, **kwargs): # type: (TrainingData, RasaNLUModelConfig, **Any) -> None import mitie model_file = kwargs.get("mitie_file") if not model_file: raise Exception("Can not run MITIE entity extractor without a " "language model. Make sure this component is " "preceeded by the 'nlp_mitie' component.") trainer = mitie.text_categorizer_trainer(model_file) trainer.num_threads = kwargs.get("num_threads", 1) for example in training_data.intent_examples: tokens = self._tokens_of_message(example) trainer.add_labeled_text(tokens, example.get("intent")) if training_data.intent_examples: # we can not call train if there are no examples! self.clf = trainer.train()
def train(self, training_data: TrainingData, cfg: RasaNLUModelConfig, **kwargs: Any) -> None: import mitie model_file = kwargs.get("mitie_file") if not model_file: raise Exception("Can not run MITIE entity extractor without a " "language model. Make sure this component is " "preceeded by the 'MitieNLP' component.") trainer = mitie.text_categorizer_trainer(model_file) trainer.num_threads = kwargs.get("num_threads", 1) for example in training_data.intent_examples: tokens = self._tokens_of_message(example) trainer.add_labeled_text(tokens, example.get("intent")) if training_data.intent_examples: # we can not call train if there are no examples! self.clf = trainer.train()