Skip to content

Commit

Permalink
Merge pull request #4251 from RasaHQ/granular-fingerprint
Browse files Browse the repository at this point in the history
Avoid retraining Core model if only templates section is changed
  • Loading branch information
wochinge authored Nov 5, 2019
2 parents 7fcfdd9 + 422e08f commit ff08484
Show file tree
Hide file tree
Showing 20 changed files with 362 additions and 173 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Added

Changed
-------
- Do not retrain the entire Core model if only the ``templates`` section of the domain is changed.

Removed
-------
Expand Down Expand Up @@ -228,7 +229,6 @@ Changed
-------
- Pin gast to == 0.2.2


[1.3.0] - 2019-09-05
^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion rasa/cli/x.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def run_in_production(args: argparse.Namespace):


def _get_credentials_and_endpoints_paths(
args: argparse.Namespace
args: argparse.Namespace,
) -> Tuple[Optional[Text], Optional[Text]]:
config_endpoint = args.config_endpoint
if config_endpoint:
Expand Down
1 change: 1 addition & 0 deletions rasa/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
DEFAULT_DATA_PATH = "data"
DEFAULT_RESULTS_PATH = "results"
DEFAULT_NLU_RESULTS_PATH = "nlu_comparison_results"
DEFAULT_CORE_SUBDIRECTORY_NAME = "core"
DEFAULT_REQUEST_TIMEOUT = 60 * 5 # 5 minutes

TEST_DATA_FILE = "test.md"
Expand Down
11 changes: 8 additions & 3 deletions rasa/core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
import rasa
import rasa.utils.io
import rasa.core.utils
from rasa.constants import DEFAULT_DOMAIN_PATH, LEGACY_DOCS_BASE_URL, ENV_SANIC_BACKLOG
from rasa.constants import (
DEFAULT_DOMAIN_PATH,
LEGACY_DOCS_BASE_URL,
ENV_SANIC_BACKLOG,
DEFAULT_CORE_SUBDIRECTORY_NAME,
)
from rasa.core import constants, jobs, training
from rasa.core.channels.channel import InputChannel, OutputChannel, UserMessage
from rasa.core.constants import DEFAULT_REQUEST_TIMEOUT
Expand Down Expand Up @@ -764,8 +769,8 @@ def persist(self, model_path: Text, dump_flattened_stories: bool = False) -> Non
if not self.is_core_ready():
raise AgentNotReady("Can't persist without a policy ensemble.")

if not model_path.endswith("core"):
model_path = os.path.join(model_path, "core")
if not model_path.endswith(DEFAULT_CORE_SUBDIRECTORY_NAME):
model_path = os.path.join(model_path, DEFAULT_CORE_SUBDIRECTORY_NAME)

self._clear_model_directory(model_path)

Expand Down
6 changes: 3 additions & 3 deletions rasa/core/brokers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def from_endpoint_config(
broker_config: Optional[EndpointConfig]
broker_config: Optional[EndpointConfig],
) -> Optional["EventChannel"]:
"""Instantiate an event channel based on its configuration."""

Expand All @@ -41,7 +41,7 @@ def from_endpoint_config(


def load_event_channel_from_module_string(
broker_config: EndpointConfig
broker_config: EndpointConfig,
) -> Optional["EventChannel"]:
"""Instantiate an event channel based on its class name."""

Expand All @@ -57,7 +57,7 @@ def load_event_channel_from_module_string(


def create_rabbitmq_ssl_options(
rabbitmq_host: Optional[Text] = None
rabbitmq_host: Optional[Text] = None,
) -> Optional["pika.SSLOptions"]:
"""Create RabbitMQ SSL options.
Expand Down
3 changes: 2 additions & 1 deletion rasa/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import typing
from pathlib import Path
from typing import Any, Dict, List, Optional, Text, Tuple, Union, Set

import rasa.core.constants
Expand Down Expand Up @@ -664,7 +665,7 @@ def as_dict(self) -> Dict[Text, Any]:
"forms": self.form_names,
}

def persist(self, filename: Text) -> None:
def persist(self, filename: Union[Text, Path]) -> None:
"""Write domain to a file."""

domain_data = self.as_dict()
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _starts_with_intent_prefix(self, text: Text) -> bool:

@staticmethod
def extract_intent_and_entities(
user_input: Text
user_input: Text,
) -> Tuple[Optional[Text], float, List[Dict[Text, Any]]]:
"""Parse the user input using regexes to extract intent & entities."""

Expand Down
7 changes: 4 additions & 3 deletions rasa/core/policies/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,10 @@ def from_dict(cls, policy_configuration: Dict[Text, Any]) -> List[Policy]:
)

if featurizer_config.get("state_featurizer"):
state_featurizer_func, state_featurizer_config = cls.get_state_featurizer_from_dict(
featurizer_config
)
(
state_featurizer_func,
state_featurizer_config,
) = cls.get_state_featurizer_from_dict(featurizer_config)

# override featurizer's state_featurizer
# with real state_featurizer class
Expand Down
6 changes: 5 additions & 1 deletion rasa/core/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ def _predict_tracker_actions(

for event in events[1:]:
if isinstance(event, ActionExecuted):
action_executed_result, policy, confidence = _collect_action_executed_predictions(
(
action_executed_result,
policy,
confidence,
) = _collect_action_executed_predictions(
processor, partial_tracker, event, fail_on_prediction_errors
)
tracker_eval_store.merge_store(action_executed_result)
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def init_copy(self) -> "DialogueStateTracker":
)

def generate_all_prior_trackers(
self
self,
) -> Generator["DialogueStateTracker", None, None]:
"""Returns a generator of the previous trackers of this tracker.
Expand Down
1 change: 0 additions & 1 deletion rasa/core/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ async def train(
"debug_plots",
},
)

training_data = await agent.load_data(
training_resource, exclusion_percentage=exclusion_percentage, **data_load_args
)
Expand Down
4 changes: 2 additions & 2 deletions rasa/core/training/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def as_story_string(self) -> Text:

@staticmethod
def order_steps(
story_steps: List[StoryStep]
story_steps: List[StoryStep],
) -> Tuple[deque, List[Tuple[Text, Text]]]:
"""Topological sort of the steps returning the ids of the steps."""

Expand All @@ -668,7 +668,7 @@ def order_steps(

@staticmethod
def _group_by_start_checkpoint(
story_steps: List[StoryStep]
story_steps: List[StoryStep],
) -> Dict[Text, List[StoryStep]]:
"""Returns all the start checkpoint of the steps"""

Expand Down
2 changes: 1 addition & 1 deletion rasa/core/training/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, nlu_training_data):

@staticmethod
def _create_reverse_mapping(
data: "TrainingData"
data: "TrainingData",
) -> Dict[Dict[Text, Any], List["Message"]]:
"""Create a mapping from intent to messages
Expand Down
Loading

0 comments on commit ff08484

Please sign in to comment.