Skip to content

Commit

Permalink
Merge branch 'master' into url
Browse files Browse the repository at this point in the history
  • Loading branch information
ricwo committed Apr 25, 2018
2 parents 52916db + 9d8f555 commit 15959d8
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 14 deletions.
4 changes: 3 additions & 1 deletion docs/community.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Below is a list of tools and applications written around or for Rasa NLU using a

- A tool for generating training examples from a list of entities
- `Chatito <https://github.com/rodrigopivi/Chatito>`_


- A custom API and UI on top of Rasa NLU for ease of use
- `Articulate <https://github.com/samtecspg/articulate>`_

Video Tutorials
^^^^^^^^^^^^^^^
Expand Down
7 changes: 6 additions & 1 deletion rasa_nlu/data_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def __init__(self,
emulation_mode=None,
remote_storage=None,
component_builder=None):

self._training_processes = max(max_training_processes, 1)
self.responses = self._create_query_logger(response_log)
self.project_dir = config.make_path_absolute(project_dir)
Expand Down Expand Up @@ -170,6 +169,12 @@ def _create_project_store(self, project_dir):
remote_storage=self.remote_storage)
return project_store

def _pre_load(self, projects):
logger.debug("loading %s", projects)
for project in self.project_store:
if project in projects:
self.project_store[project].load_model()

def _list_projects_in_cloud(self):
try:
from rasa_nlu.persistor import get_persistor
Expand Down
16 changes: 8 additions & 8 deletions rasa_nlu/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __str__(self):
return self.message


class UnsuportedModelError(Exception):
class UnsupportedModelError(Exception):
"""Raised when a model is to old to be loaded.
Attributes:
Expand Down Expand Up @@ -255,13 +255,13 @@ def ensure_model_compatibility(metadata):

model_version = metadata.get("rasa_nlu_version", "0.0.0")
if version.parse(model_version) < version.parse("0.12.0a2"):
raise UnsuportedModelError("The model version is to old to be "
"loaded by this Rasa NLU instance. "
"Either retrain the model, or run with"
"an older version. "
"Model version: {} Instance version: {}"
"".format(model_version,
rasa_nlu.__version__))
raise UnsupportedModelError(
"The model version is to old to be "
"loaded by this Rasa NLU instance. "
"Either retrain the model, or run with"
"an older version. "
"Model version: {} Instance version: {}"
"".format(model_version, rasa_nlu.__version__))

@staticmethod
def load(model_dir, component_builder=None, skip_valdation=False):
Expand Down
19 changes: 19 additions & 0 deletions rasa_nlu/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ def parse(self, text, time=None, requested_model_name=None):

return response, model_name

def load_model(self):
self._begin_read()
status = False
model_name = self._dynamic_load_model()
logger.debug('Loading model %s', model_name)

self._loader_lock.acquire()
try:
if not self._models.get(model_name):
interpreter = self._interpreter_for_model(model_name)
self._models[model_name] = interpreter
status = True
finally:
self._loader_lock.release()

self._end_read()

return status

def update(self, model_name):
self._writer_lock.acquire()
self._models[model_name] = None
Expand Down
19 changes: 17 additions & 2 deletions rasa_nlu/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ def create_argument_parser():

parser.add_argument('-e', '--emulate',
choices=['wit', 'luis', 'dialogflow'],
help='which service to emulate (default: None i.e. use '
'simple built in format)')
help='which service to emulate (default: None i.e. use'
' simple built in format)')
parser.add_argument('-P', '--port',
type=int,
default=5000,
help='port on which to run server')
parser.add_argument('--pre_load',
nargs='+',
default=[],
help='Preload models into memory before starting the '
'server. \nIf given `all` as input all the models'
' will be loaded.\nElse you can specify a list of'
' specific project names.\n Eg: python -m rasa_'
'nlu.server -p project1 project2 --path projects')
parser.add_argument('-t', '--token',
help="auth token. If set, reject requests which don't "
"provide this token as a query parameter")
Expand Down Expand Up @@ -360,12 +368,19 @@ def unload_model(self, request):
cmdline_args = create_argument_parser().parse_args()

utils.configure_colored_logging(cmdline_args.loglevel)
pre_load = cmdline_args.pre_load

router = DataRouter(cmdline_args.path,
cmdline_args.max_training_processes,
cmdline_args.response_log,
cmdline_args.emulate,
cmdline_args.storage)
if pre_load:
logger.debug('Preloading....')
if 'all' in pre_load:
pre_load = router.project_store.keys()
router._pre_load(pre_load)

rasa = RasaNLU(
router,
cmdline_args.loglevel,
Expand Down
2 changes: 1 addition & 1 deletion sample_configs/config_jieba_mitie_sklearn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: "zh"

pipeline:
- name: "nlp_mitie"
model: "data/total_word_feature_extractor_zh.dat"
- name: "tokenizer_jieba"
- name: "ner_mitie"
model: "data/total_word_feature_extractor_zh.dat"
- name: "ner_synonyms"
- name: "intent_entity_featurizer_regex"
- name: "intent_featurizer_mitie"
Expand Down
2 changes: 1 addition & 1 deletion tests/base/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_interpreter(pipeline_template, component_builder, tmpdir):
{"rasa_nlu_version": "0.10.2"},
{"rasa_nlu_version": "0.12.0a1"}])
def test_model_not_compatible(metadata):
with pytest.raises(rasa_nlu.model.UnsuportedModelError):
with pytest.raises(rasa_nlu.model.UnsupportedModelError):
Interpreter.ensure_model_compatibility(metadata)


Expand Down

0 comments on commit 15959d8

Please sign in to comment.