Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. from rasa_core.agent import Agent
  2. from rasa_core.policies import KerasPolicy
  3. from rasa_nlu.training_data import load_data
  4. from rasa_nlu import config
  5. from rasa_nlu.model import Trainer
  6. import datetime
  7.  
  8. def _archive_name (type, environment):
  9. t = datetime.datetime.now()
  10. timestring = t.strftime('%Y%m%d-%H%M%S')
  11. return '%s__model_%s' % (prefix, timestring)
  12.  
  13. def train_core (params):
  14.  
  15. domain = params.get('domain') if 'domain' in params else ''
  16. stories = params.get('stories') if 'stories' in params else ''
  17. environment = params.get('environment') if 'environment' in params else None
  18. model_name = _archive_name('core', environment)
  19.  
  20. additional_arguments = {
  21. "epochs": 100,
  22. "batch_size": 20,
  23. "validation_split": 0.1,
  24. "augmentation_factor": 50,
  25. "debug_plots": True,
  26. "max_history": 5
  27. }
  28. agent = Agent(domain_path,
  29. policies=[KerasPolicy(**additional_arguments)])
  30.  
  31. training_data = agent.load_data(md_stories_file_path if stories_in_json else stories_path)
  32. agent.train(training_data)
  33. # persist
  34. agent.persist(model_dir)
  35.  
  36. def train_nlu (params):
  37. intents_file = params.get('intents') if 'intents' in params else ''
  38. config_file = params.get('config') if 'config' in params else {}
  39. environment = params.get('environment') if 'environment' in params else None
  40. model_name = _archive_name('nlu', environment)
  41. model_dir = '%s/%s' % (BASE_DIR, model_name)
  42.  
  43. nlu_config = config.load(intents_file)
  44. data = load_data(intents_file)
  45. trainer = Trainer(nlu_config)
  46.  
  47. trainer.train(data)
  48. trainer.persist(BASE_DIR, project_name= '', fixed_model_name = model_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement