def continue_training(self, trackers: List[DialogueStateTracker], **kwargs: Any) -> None: if not self.is_ready(): raise AgentNotReady("Can't continue training without a policy " "ensemble.") self.policy_ensemble.continue_training(trackers, self.domain, **kwargs) self._set_fingerprint()
def _ensure_agent_is_ready(self) -> None: """Checks that an interpreter and a tracker store are set. Necessary before a processor can be instantiated from this agent. Raises an exception if any argument is missing.""" if not self.is_ready(): raise AgentNotReady("Agent needs to be prepared before usage. " "You need to set an interpreter, a policy " "ensemble as well as a tracker store.")
def persist(self, model_path, dump_flattened_stories=False): # type: (Text, bool) -> None """Persists this agent into a directory for later loading and usage.""" if not self.is_ready(): raise AgentNotReady("Can't persist without a policy ensemble.") self._clear_model_directory(model_path) self.policy_ensemble.persist(model_path, dump_flattened_stories) self.domain.persist(os.path.join(model_path, "domain.yml")) self.domain.persist_specification(model_path) logger.info("Persisted model to '{}'" "".format(os.path.abspath(model_path)))
def train(self, training_trackers: List[DialogueStateTracker], **kwargs: Any ) -> None: """Train the policies / policy ensemble using dialogue data from file. Args: training_trackers: trackers to train on **kwargs: additional arguments passed to the underlying ML trainer (e.g. keras parameters) """ if not self.is_ready(): raise AgentNotReady("Can't train without a policy ensemble.") # deprecation tests if kwargs.get('featurizer'): raise Exception("Passing `featurizer` " "to `agent.train(...)` is not supported anymore. " "Pass appropriate featurizer directly " "to the policy configuration instead. More info " "https://rasa.com/docs/core/migrations.html") if kwargs.get('epochs') or kwargs.get('max_history') or kwargs.get( 'batch_size'): raise Exception("Passing policy configuration parameters " "to `agent.train(...)` is not supported " "anymore. Specify parameters directly in the " "policy configuration instead. More info " "https://rasa.com/docs/core/migrations.html") if isinstance(training_trackers, str): # the user most likely passed in a file name to load training # data from raise Exception("Passing a file name to `agent.train(...)` is " "not supported anymore. Rather load the data with " "`data = agent.load_data(file_name)` and pass it " "to `agent.train(data)`.") logger.debug("Agent trainer got kwargs: {}".format(kwargs)) check_domain_sanity(self.domain) self.policy_ensemble.train(training_trackers, self.domain, **kwargs) self._set_fingerprint()
logger.info("Model directory {} exists and contains old " "model files. All files will be overwritten." "".format(model_path)) shutil.rmtree(model_path) else: logger.debug("Model directory {} exists, but does not contain " "all old model files. Some files might be " "overwritten.".format(model_path)) def persist(self, model_path: Text, dump_flattened_stories: bool = False) -> None: """Persists this agent into a directory for later loading and usage.""" if not self.is_ready(): raise AgentNotReady("Can't persist without a policy ensemble.") self._clear_model_directory(model_path) self.policy_ensemble.persist(model_path, dump_flattened_stories) self.domain.persist(os.path.join(model_path, "domain.yml")) self.domain.persist_specification(model_path) logger.info("Persisted model to '{}'" "".format(os.path.abspath(model_path))) def visualize(self, resource_name: Text, output_file: Text, max_history: Optional[int] = None, nlu_training_data: Optional[Text] = None,