Exemplo n.º 1
0
def make_agent() -> EcommerceAgent:
    """Make an agent

    Returns:
        agent: created Ecommerce agent
    """

    config_path = find_config('tfidf_retrieve')
    skill = build_model(config_path)
    agent = EcommerceAgent(skills=[skill])
    return agent
Exemplo n.º 2
0
def make_agent() -> EcommerceAgent:
    """Make an agent

    Returns:
        agent: created Ecommerce agent
    """

    config_path = find_config('ecommerce_bot')
    skill = build_model_from_config(config_path, as_component=True)
    agent = EcommerceAgent(skills=[skill])
    return agent
Exemplo n.º 3
0
def make_agent() -> EcommerceAgent:
    """Make an agent

    Returns:
        agent: created Ecommerce agent
    """

    config_path = find_config('tfidf_retrieve')
    skill = build_model(config_path)
    agent = EcommerceAgent(skills=[skill])
    return agent
Exemplo n.º 4
0
from deeppavlov.deep import find_config
from deeppavlov.core.commands.train import train_evaluate_model_from_config
from deeppavlov.core.commands.infer import interact_model

# PIPELINE_CONFIG_PATH = 'configs/intents/intents_dstc2.json'
# PIPELINE_CONFIG_PATH = 'configs/intents/intents_snips.json'
# PIPELINE_CONFIG_PATH = 'configs/ner/ner_dstc2.json'
# PIPELINE_CONFIG_PATH = 'configs/ner/ner_rus.json'
# PIPELINE_CONFIG_PATH = 'configs/ner/slotfill_dstc2.json'
# PIPELINE_CONFIG_PATH = 'configs/error_model/brillmoore_wikitypos_en.json'
# PIPELINE_CONFIG_PATH = 'configs/error_model/brillmoore_kartaslov_ru.json'
# PIPELINE_CONFIG_PATH = 'configs/error_model/levenshtein_searcher.json'
# PIPELINE_CONFIG_PATH = 'configs/go_bot/config.json'
# PIPELINE_CONFIG_PATH = 'configs/go_bot/config_minimal.json'
# PIPELINE_CONFIG_PATH = 'configs/go_bot/config_all.json'
# PIPELINE_CONFIG_PATH = 'configs/squad/squad.json'
# PIPELINE_CONFIG_PATH = 'configs/ranking/ranking_insurance.json'
# PIPELINE_CONFIG_PATH = 'configs/seq2seq_go_bot/bot_kvret.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/en_ranker_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/ru_ranker_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/en_odqa_infer_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/ru_odqa_infer_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/ranker_test.json'
# PIPELINE_CONFIG_PATH = find_config('morpho_ru_syntagrus_train')
PIPELINE_CONFIG_PATH = find_config('morpho_ru_syntagrus_train_pymorphy')

if __name__ == '__main__':
    train_evaluate_model_from_config(PIPELINE_CONFIG_PATH)
    # interact_model(PIPELINE_CONFIG_PATH)
import argparse

from deeppavlov.models.morpho_tagger.common import predict_with_model
from deeppavlov.deep import find_config
from deeppavlov.download import deep_download

parser = argparse.ArgumentParser()
parser.add_argument("config_path", help="path to file with prediction configuration")
parser.add_argument("-d", "--download", action="store_true", help="download model components")

if __name__ == "__main__":
    args = parser.parse_args()
    config_path = find_config(args.config_path)
    if args.download:
        deep_download(['-c', config_path])
    predict_with_model(config_path)
Exemplo n.º 6
0
# PIPELINE_CONFIG_PATH = 'configs/classifiers/intents_dstc2.json'
# PIPELINE_CONFIG_PATH = 'configs/classifiers/intents_snips.json'
# PIPELINE_CONFIG_PATH = 'configs/ner/ner_dstc2.json'
# PIPELINE_CONFIG_PATH = 'configs/ner/ner_rus.json'
# PIPELINE_CONFIG_PATH = 'configs/ner/slotfill_dstc2.json'
# PIPELINE_CONFIG_PATH = 'configs/error_model/brillmoore_wikitypos_en.json'
# PIPELINE_CONFIG_PATH = 'configs/error_model/brillmoore_kartaslov_ru.json'
# PIPELINE_CONFIG_PATH = 'configs/error_model/levenshtein_searcher.json'
# PIPELINE_CONFIG_PATH = 'configs/go_bot/config.json'
# PIPELINE_CONFIG_PATH = 'configs/go_bot/config_minimal.json'
# PIPELINE_CONFIG_PATH = 'configs/go_bot/config_all.json'
# PIPELINE_CONFIG_PATH = 'configs/squad/squad.json'
# PIPELINE_CONFIG_PATH = 'configs/ranking/ranking_insurance.json'
# PIPELINE_CONFIG_PATH = 'configs/seq2seq_go_bot/bot_kvret.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/en_ranker_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/ru_ranker_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/en_odqa_infer_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/ru_odqa_infer_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/ranker_test.json'
# PIPELINE_CONFIG_PATH = find_config('morpho_ru_syntagrus_train')
# PIPELINE_CONFIG_PATH = find_config('morpho_ru_syntagrus_train_pymorphy')
# PIPELINE_CONFIG_PATH = find_config('intents_dstc2_big')

PIPELINE_CONFIG_PATH = find_config('ecommerce_bot')

if __name__ == '__main__':
    # train_evaluate_model_from_config(PIPELINE_CONFIG_PATH)
    # start_model_server(PIPELINE_CONFIG_PATH)
    interact_model(PIPELINE_CONFIG_PATH)
Exemplo n.º 7
0
def main():
    params_helper = ParamsSearch()

    args = parser.parse_args()
    is_loo = False
    n_folds = None
    if args.folds == 'loo':
        is_loo = True
    elif args.folds is None:
        n_folds = None
    elif args.folds.isdigit():
        n_folds = int(args.folds)
    else:
        raise NotImplementedError('Not implemented this type of CV')

    # read config
    pipeline_config_path = find_config(args.config_path)
    config_init = read_json(pipeline_config_path)
    config = config_init.copy()
    data = read_data_by_config(config)
    target_metric = config_init['train']['metrics'][0]

    # get all params for search
    param_paths = list(params_helper.find_model_path(config, 'search_choice'))
    param_values = []
    param_names = []
    for path in param_paths:
        value = params_helper.get_value_from_config(config, path)
        param_name = path[-1]
        param_value_search = value['search_choice']
        param_names.append(param_name)
        param_values.append(param_value_search)

    # find optimal params
    if args.search_type == 'grid':
        # generate params combnations for grid search
        combinations = list(product(*param_values))

        # calculate cv scores
        scores = []
        for comb in combinations:
            config = config_init.copy()
            for i, param_value in enumerate(comb):
                config = params_helper.insert_value_or_dict_into_config(config, param_paths[i], param_value)

            if (n_folds is not None) | is_loo:
                # CV for model evaluation
                score_dict = calc_cv_score(config=config, data=data, n_folds=n_folds, is_loo=is_loo)
                score = score_dict[next(iter(score_dict))]
            else:
                # train/valid for model evaluation
                data_to_evaluate = data.copy()
                if len(data_to_evaluate['valid']) == 0:
                    data_to_evaluate['train'], data_to_evaluate['valid'] = train_test_split(data_to_evaluate['train'], test_size=0.2)
                iterator = get_iterator_from_config(config, data_to_evaluate)
                score = train_evaluate_model_from_config(config, iterator=iterator)['valid'][target_metric]

            scores.append(score)

        # get model with best score
        best_params_dict = get_best_params(combinations, scores, param_names, target_metric)
        log.info('Best model params: {}'.format(best_params_dict))
    else:
        raise NotImplementedError('Not implemented this type of search')

    # save config
    best_config = config_init.copy()
    for i, param_name in enumerate(best_params_dict.keys()):
        if param_name != target_metric:
            best_config = params_helper.insert_value_or_dict_into_config(best_config, param_paths[i], best_params_dict[param_name])

    best_model_filename = pipeline_config_path.replace('.json', '_cvbest.json')
    save_json(best_config, best_model_filename)
    log.info('Best model saved in json-file: {}'.format(best_model_filename))
Exemplo n.º 8
0
from deeppavlov.core.commands.infer import interact_model
from utils.server_utils.server import start_model_server

# PIPELINE_CONFIG_PATH = 'configs/classifiers/intents_dstc2.json'
# PIPELINE_CONFIG_PATH = 'configs/classifiers/intents_snips.json'
# PIPELINE_CONFIG_PATH = 'configs/ner/ner_dstc2.json'
# PIPELINE_CONFIG_PATH = 'configs/ner/ner_rus.json'
# PIPELINE_CONFIG_PATH = 'configs/ner/slotfill_dstc2.json'
# PIPELINE_CONFIG_PATH = 'configs/error_model/brillmoore_wikitypos_en.json'
# PIPELINE_CONFIG_PATH = 'configs/error_model/brillmoore_kartaslov_ru.json'
# PIPELINE_CONFIG_PATH = 'configs/error_model/levenshtein_searcher.json'
# PIPELINE_CONFIG_PATH = 'configs/go_bot/config.json'
# PIPELINE_CONFIG_PATH = 'configs/go_bot/config_minimal.json'
# PIPELINE_CONFIG_PATH = 'configs/go_bot/config_all.json'
# PIPELINE_CONFIG_PATH = 'configs/squad/squad.json'
# PIPELINE_CONFIG_PATH = 'configs/ranking/ranking_insurance.json'
# PIPELINE_CONFIG_PATH = 'configs/seq2seq_go_bot/bot_kvret.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/en_ranker_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/ru_ranker_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/en_odqa_infer_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/ru_odqa_infer_prod.json'
# PIPELINE_CONFIG_PATH = 'configs/odqa/ranker_test.json'
# PIPELINE_CONFIG_PATH = find_config('morpho_ru_syntagrus_train')
# PIPELINE_CONFIG_PATH = find_config('morpho_ru_syntagrus_train_pymorphy')
PIPELINE_CONFIG_PATH = find_config('intents_dstc2_big')

if __name__ == '__main__':
    train_evaluate_model_from_config(PIPELINE_CONFIG_PATH)
    # start_model_server(PIPELINE_CONFIG_PATH)
    # interact_model(PIPELINE_CONFIG_PATH)