<commit_before>from yarl import URL
from typing import Text

import rasa.utils.io as io_utils

from rasa.nlu.classifiers.diet_classifier import DIETClassifier
from rasa.nlu.classifiers.embedding_intent_classifier import EmbeddingIntentClassifier
from rasa.nlu.selectors.response_selector import ResponseSelector
from rasa.utils.tensorflow.constants import EPOCHS


def latest_request(mocked, request_type, path):
    return mocked.requests.get((request_type, URL(path)))


def json_of_latest_request(r):
    return r[-1].kwargs["json"]


def update_number_of_epochs(config_path: Text, output_file: Text):
    config = io_utils.read_yaml_file(config_path)

    if "pipeline" not in config.keys():
        raise ValueError(f"Invalid config provided! File: '{config_path}'.")

    for component in config["pipeline"]:
        # do not update epochs for pipeline templates
        if not isinstance(component, dict):
            continue

        if component["name"] in [
            EmbeddingIntentClassifier.name,
            DIETClassifier.name,
            ResponseSelector.name,
        ]:
            component[EPOCHS] = 2

    io_utils.write_yaml_file(config, output_file)
<commit_msg>reduce number of train epochs<commit_after>from yarl import URL
from typing import Text

import rasa.utils.io as io_utils

from rasa.nlu.classifiers.diet_classifier import DIETClassifier
from rasa.nlu.classifiers.embedding_intent_classifier import EmbeddingIntentClassifier
from rasa.nlu.selectors.response_selector import ResponseSelector
from rasa.utils.tensorflow.constants import EPOCHS


def latest_request(mocked, request_type, path):
    return mocked.requests.get((request_type, URL(path)))


def json_of_latest_request(r):
    return r[-1].kwargs["json"]


def update_number_of_epochs(config_path: Text, output_file: Text):
    config = io_utils.read_yaml_file(config_path)

    if "pipeline" not in config.keys():
        raise ValueError(f"Invalid config provided! File: '{config_path}'.")

    for component in config["pipeline"]:
        # do not update epochs for pipeline templates
        if not isinstance(component, dict):
            continue

        if component["name"] in [
            EmbeddingIntentClassifier.name,
            DIETClassifier.name,
            ResponseSelector.name,
        ]:
            component[EPOCHS] = 1

    io_utils.write_yaml_file(config, output_file)

{'fraction_non_alphanumeric': 0.08270676691729323, 'fraction_numerical': 0.001670843776106934, 'mean_word_length': 3.761431411530815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4695821', 'n_tokens_mistral': 714, 'n_tokens_neox': 700, 'n_words': 170}