Skip to content

Commit

Permalink
Merge 505829d into 0452099
Browse files Browse the repository at this point in the history
  • Loading branch information
erohmensing committed Nov 27, 2019
2 parents 0452099 + 505829d commit ba9af79
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 66 deletions.
57 changes: 28 additions & 29 deletions rasa/core/domain.py
Expand Up @@ -251,17 +251,17 @@ def collect_templates(
# templates should be a dict with options
if isinstance(t, str):
warnings.warn(
"Deprecated: Templates should not be strings anymore. "
f"Templates should not be strings anymore. "
f"Utterance template '{template_key}' should contain either '- text: ' or "
"'- custom: ' attribute to be a proper template.",
DeprecationWarning,
f"'- custom: ' attribute to be a proper template.",
FutureWarning,
)
validated_variations.append({"text": t})
elif "text" not in t and "custom" not in t:
raise InvalidDomain(
"Utter template '{}' needs to contain either "
"'- text: ' or '- custom: ' attribute to be a proper "
"template.".format(template_key)
f"Utter template '{template_key}' needs to contain either "
f"'- text: ' or '- custom: ' attribute to be a proper "
f"template."
)
else:
validated_variations.append(t)
Expand Down Expand Up @@ -405,11 +405,10 @@ def index_for_action(self, action_name: Text) -> Optional[int]:
def _raise_action_not_found_exception(self, action_name):
action_names = "\n".join([f"\t - {a}" for a in self.action_names])
raise NameError(
"Cannot access action '{}', "
"as that name is not a registered "
"action for this domain. "
"Available actions are: \n{}"
"".format(action_name, action_names)
f"Cannot access action '{action_name}', "
f"as that name is not a registered "
f"action for this domain. "
f"Available actions are: \n{action_names}"
)

def random_template_for(self, utter_action):
Expand Down Expand Up @@ -539,8 +538,8 @@ def _get_featurized_entities(self, latest_message: UserUttered) -> Set[Text]:
warnings.warn(
f"Entities: '{ambiguous_entities}' are explicitly included and"
f" excluded for intent '{intent_name}'."
"Excluding takes precedence in this case. "
"Please resolve that ambiguity."
f"Excluding takes precedence in this case. "
f"Please resolve that ambiguity."
)

return entity_names.intersection(wanted_entities)
Expand All @@ -558,10 +557,10 @@ def get_prev_action_states(
else:
warnings.warn(
f"Failed to use action '{latest_action}' in history. "
"Please make sure all actions are listed in the "
"domains action list. If you recently removed an "
"action, don't worry about this warning. It "
"should stop appearing after a while. "
f"Please make sure all actions are listed in the "
f"domains action list. If you recently removed an "
f"action, don't worry about this warning. It "
f"should stop appearing after a while."
)
return {}
else:
Expand Down Expand Up @@ -638,12 +637,12 @@ def compare_with_specification(self, path: Text) -> bool:
missing = ",".join(set(states) - set(self.input_states))
additional = ",".join(set(self.input_states) - set(states))
raise InvalidDomain(
"Domain specification has changed. "
"You MUST retrain the policy. "
+ "Detected mismatch in domain specification. "
+ "The following states have been \n"
"\t - removed: {} \n"
"\t - added: {} ".format(missing, additional)
f"Domain specification has changed. "
f"You MUST retrain the policy. "
f"Detected mismatch in domain specification. "
f"The following states have been \n"
f"\t - removed: {missing} \n"
f"\t - added: {additional} "
)
else:
return True
Expand Down Expand Up @@ -867,9 +866,9 @@ def get_duplicate_exception_message(
if message:
message += "\n"
message += (
"Duplicate {0} in domain. "
"These {0} occur more than once in "
"the domain: '{1}'".format(name, "', '".join(d))
f"Duplicate {name} in domain. "
f"These {name} occur more than once in "
f"the domain: '{', '.join(d)}'."
)
return message

Expand Down Expand Up @@ -910,9 +909,9 @@ def check_missing_templates(self) -> None:
for template in missing_templates:
warnings.warn(
f"Utterance '{template}' is listed as an "
"action in the domain file, but there is "
"no matching utterance template. Please "
"check your domain."
f"action in the domain file, but there is "
f"no matching utterance template. Please "
f"check your domain."
)

def is_empty(self) -> bool:
Expand Down
25 changes: 13 additions & 12 deletions rasa/nlu/classifiers/embedding_intent_classifier.py
Expand Up @@ -163,10 +163,12 @@ def _check_old_config_variables(self, config: Dict[Text, Any]) -> None:
if removed_param in config:
warnings.warn(
f"Intent tokenization has been moved to Tokenizer components. "
f"Your config still mentions '{removed_param}'. Tokenization may fail if you specify the parameter here. "
f"Please specify the parameter 'intent_tokenization_flag' and 'intent_split_symbol' in the "
f"Your config still mentions '{removed_param}'. "
f"Tokenization may fail if you specify the parameter here. "
f"Please specify the parameter 'intent_tokenization_flag' "
f"and 'intent_split_symbol' in the "
f"tokenizer of your NLU pipeline",
DeprecationWarning,
FutureWarning,
)

# init helpers
Expand All @@ -182,7 +184,7 @@ def _load_nn_architecture_params(self, config: Dict[Text, Any]) -> None:
):
raise ValueError(
"If hidden layer weights are shared,"
"hidden_layer_sizes for a and b must coincide"
"hidden_layer_sizes for a and b must coincide."
)

self.batch_size = config["batch_size"]
Expand Down Expand Up @@ -459,7 +461,7 @@ def check_input_dimension_consistency(self, session_data):
if self.share_hidden_layers:
if session_data.X[0].shape[-1] != session_data.Y[0].shape[-1]:
raise ValueError(
"If embeddings are shared "
"If embeddings are shared, "
"text features and label features "
"must coincide. Check the output dimensions of previous components."
)
Expand All @@ -483,10 +485,9 @@ def preprocess_train_data(self, training_data):

# check if number of negatives is less than number of label_ids
logger.debug(
"Check if num_neg {} is smaller than "
"number of label_ids {}, "
"else set num_neg to the number of label_ids - 1"
"".format(self.num_neg, self._encoded_all_label_ids.shape[0])
f"Check if num_neg {self.num_neg} is smaller than "
f"number of label_ids {self._encoded_all_label_ids.shape[0]}, "
f"else set num_neg to the number of label_ids - 1."
)
# noinspection PyAttributeOutsideInit
self.num_neg = min(self.num_neg, self._encoded_all_label_ids.shape[0] - 1)
Expand Down Expand Up @@ -601,7 +602,7 @@ def predict_label(self, message):
logger.error(
"There is no trained tf.session: "
"component is either not trained or "
"didn't receive enough training data"
"didn't receive enough training data."
)

else:
Expand Down Expand Up @@ -742,7 +743,7 @@ def load(

else:
warnings.warn(
f"Failed to load nlu model. Maybe path '{os.path.abspath(model_dir)}' "
"doesn't exist."
f"Failed to load nlu model. "
f"Maybe path '{os.path.abspath(model_dir)}' doesn't exist."
)
return cls(component_config=meta)
21 changes: 10 additions & 11 deletions rasa/nlu/config.py
Expand Up @@ -69,9 +69,9 @@ def component_config_from_pipeline(
return override_defaults(defaults, c)
except IndexError:
warnings.warn(
"Tried to get configuration value for component "
f"Tried to get configuration value for component "
f"number {index} which is not part of the pipeline. "
"Returning `defaults`."
f"Returning `defaults`."
)
return override_defaults(defaults, {})

Expand Down Expand Up @@ -106,10 +106,10 @@ def __init__(self, configuration_values=None):
f"You have specified the pipeline template "
f"'{template_name}' which has been renamed to "
f"'{new_names[template_name]}'. "
"Please update your code as it will no "
"longer work with future versions of "
"Rasa",
DeprecationWarning,
f"Please update your code as it will no "
f"longer work with future versions of "
f"Rasa.",
FutureWarning,
)
template_name = new_names[template_name]

Expand All @@ -124,10 +124,9 @@ def __init__(self, configuration_values=None):
)

raise InvalidConfigError(
"No pipeline specified and unknown "
"pipeline template '{}' passed. Known "
"pipeline templates: {}"
"".format(template_name, known_templates)
f"No pipeline specified and unknown "
f"pipeline template '{template_name}' passed. Known "
f"pipeline templates: {known_templates}"
)

for key, value in self.items():
Expand Down Expand Up @@ -181,7 +180,7 @@ def set_component_attr(self, index, **kwargs):
self.pipeline[index].update(kwargs)
except IndexError:
warnings.warn(
"Tried to set configuration value for component "
f"Tried to set configuration value for component "
f"number {index} which is not part of the pipeline."
)

Expand Down
17 changes: 7 additions & 10 deletions rasa/nlu/registry.py
Expand Up @@ -158,8 +158,7 @@ def get_component_class(component_name: Text) -> Type["Component"]:
# that class
module_name, _, class_name = component_name.rpartition(".")
raise Exception(
"Failed to find class '{}' in module '{}'.\n"
"".format(component_name, class_name, module_name)
f"Failed to find class '{class_name}' in module '{module_name}'.\n"
)
except ImportError as e:
# when component_name is a path to a class but that path is invalid or
Expand All @@ -169,15 +168,13 @@ def get_component_class(component_name: Text) -> Type["Component"]:

if is_path:
module_name, _, _ = component_name.rpartition(".")
exception_message = "Failed to find module '{}'. \n{}".format(
module_name, e
)
exception_message = f"Failed to find module '{module_name}'. \n{e}"
else:
exception_message = (
"Cannot find class '{}' from global namespace. "
"Please check that there is no typo in the class "
"name and that you have imported the class into the global "
"namespace.".format(component_name)
f"Cannot find class '{component_name}' from global namespace. "
f"Please check that there is no typo in the class "
f"name and that you have imported the class into the global "
f"namespace."
)

raise ModuleNotFoundError(exception_message)
Expand All @@ -188,7 +185,7 @@ def get_component_class(component_name: Text) -> Type["Component"]:
f"contains old style component name `{component_name}`, "
f"you should change it to its class name: "
f"`{old_style_names[component_name]}`.",
DeprecationWarning,
FutureWarning,
)
component_name = old_style_names[component_name]

Expand Down
8 changes: 4 additions & 4 deletions rasa/nlu/training_data/formats/rasa.py
Expand Up @@ -50,7 +50,7 @@ def read_from_json(self, js, **kwargs):
"removed in the future. Consider "
"putting all your examples "
"into the 'common_examples' section.",
DeprecationWarning,
FutureWarning,
)

all_examples = common_examples + intent_examples + entity_examples
Expand Down Expand Up @@ -106,9 +106,9 @@ def validate_rasa_nlu_data(data: Dict[Text, Any]) -> None:
validate(data, _rasa_nlu_data_schema())
except ValidationError as e:
e.message += (
". Failed to validate training data, make sure your data "
"is valid. For more information about the format visit "
"{}/nlu/training-data-format/".format(DOCS_BASE_URL)
f". Failed to validate training data, make sure your data "
f"is valid. For more information about the format visit "
f"{DOCS_BASE_URL}/nlu/training-data-format/"
)
raise e

Expand Down

0 comments on commit ba9af79

Please sign in to comment.