当前位置: 首页>>代码示例>>Python>>正文


Python model.Trainer方法代码示例

本文整理汇总了Python中rasa_nlu.model.Trainer方法的典型用法代码示例。如果您正苦于以下问题:Python model.Trainer方法的具体用法?Python model.Trainer怎么用?Python model.Trainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rasa_nlu.model的用法示例。


在下文中一共展示了model.Trainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: train_model

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def train_model():
    # trains a model and times it
    t = time()
    # training_data = load_data('demo_train.md')
    training_data = load_data("data/company_train_lookup.json")
    td_load_time = time() - t
    trainer = Trainer(config.load("config.yaml"))
    t = time()
    trainer.train(training_data)
    train_time = time() - t
    clear_model_dir()
    t = time()
    model_directory = trainer.persist(
        "./tmp/models"
    )  # Returns the directory the model is stored in
    persist_time = time() - t
    return td_load_time, train_time, persist_time 
开发者ID:RasaHQ,项目名称:rasa_lookup_demo,代码行数:19,代码来源:time_train_test.py

示例2: train_models

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def train_models(component_builder, data):
    # Retrain different multitenancy models
    def train(cfg_name, project_name):
        from rasa_nlu import training_data

        cfg = config.load(cfg_name)
        trainer = Trainer(cfg, component_builder)
        training_data = training_data.load_data(data)

        trainer.train(training_data)
        trainer.persist("test_projects", project_name=project_name)

    train("sample_configs/config_pretrained_embeddings_spacy.yml",
          "test_project_spacy")
    train("sample_configs/config_pretrained_embeddings_mitie.yml",
          "test_project_mitie")
    train("sample_configs/config_pretrained_embeddings_mitie_2.yml",
          "test_project_mitie_2") 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:20,代码来源:test_multitenancy.py

示例3: zipped_nlu_model

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def zipped_nlu_model():
    spacy_config_path = "sample_configs/config_pretrained_embeddings_spacy.yml"

    cfg = config.load(spacy_config_path)
    trainer = Trainer(cfg)
    td = training_data.load_data(DEFAULT_DATA_PATH)

    trainer.train(td)
    trainer.persist("test_models",
                    project_name="test_model_pretrained_embeddings")

    model_dir_list = os.listdir(TEST_MODEL_PATH)

    # directory name of latest model
    model_dir = sorted(model_dir_list)[-1]

    # path of that directory
    model_path = os.path.join(TEST_MODEL_PATH, model_dir)

    zip_path = zip_folder(model_path)

    return zip_path 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:24,代码来源:conftest.py

示例4: train_models

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def train_models(component_builder, data):
    # Retrain different multitenancy models
    def train(cfg_name, project_name):
        from rasa_nlu.train import create_persistor
        from rasa_nlu import training_data

        cfg = config.load(cfg_name)
        trainer = Trainer(cfg, component_builder)
        training_data = training_data.load_data(data)

        trainer.train(training_data)
        trainer.persist("test_projects", project_name=project_name)

    train("sample_configs/config_spacy.yml", "test_project_spacy_sklearn")
    train("sample_configs/config_mitie.yml", "test_project_mitie")
    train("sample_configs/config_mitie_sklearn.yml", "test_project_mitie_sklearn") 
开发者ID:crownpku,项目名称:Rasa_NLU_Chi,代码行数:18,代码来源:test_multitenancy.py

示例5: train

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def train():
    training_data = load_data('../mom/data/nlu.json')
    trainer = Trainer(RasaNLUConfig("../mom/nlu_model_config.json"))
    trainer.train(training_data)
    model_directory = trainer.persist('../models')  # Returns the directory the model is stored in
    return model_directory 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:8,代码来源:train_nlu.py

示例6: train_babi_nlu

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def train_babi_nlu():
    training_data = load_data('examples/babi/data/franken_data.json')
    trainer = Trainer(RasaNLUConfig("examples/babi/data/config_nlu.json"))
    trainer.train(training_data)
    model_directory = trainer.persist('examples/babi/models/nlu/',
                                      fixed_model_name=model_name)
    return model_directory 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:9,代码来源:train_nlu.py

示例7: train_nlu

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def train_nlu():
    from rasa_nlu.training_data import load_data
    from rasa_nlu import config
    from rasa_nlu.model import Trainer

    training_data = load_data('data/nlu.md')
    trainer = Trainer(config.load("config.yml"))
    trainer.train(training_data)
    model_directory = trainer.persist('models/nlu/',
                                      fixed_model_name="current")

    return model_directory 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:14,代码来源:bot.py

示例8: train

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def train(nlu_config: Union[Text, RasaNLUModelConfig],
          data: Text,
          path: Optional[Text] = None,
          project: Optional[Text] = None,
          fixed_model_name: Optional[Text] = None,
          storage: Optional[Text] = None,
          component_builder: Optional[ComponentBuilder] = None,
          training_data_endpoint: Optional[EndpointConfig] = None,
          **kwargs: Any
          ) -> Tuple[Trainer, Interpreter, Text]:
    """Loads the trainer and the data and runs the training of the model."""

    if isinstance(nlu_config, str):
        nlu_config = config.load(nlu_config)

    # Ensure we are training a model that we can save in the end
    # WARN: there is still a race condition if a model with the same name is
    # trained in another subprocess
    trainer = Trainer(nlu_config, component_builder)
    persistor = create_persistor(storage)
    if training_data_endpoint is not None:
        training_data = load_data_from_endpoint(training_data_endpoint,
                                                nlu_config.language)
    else:
        training_data = load_data(data, nlu_config.language)
    interpreter = trainer.train(training_data, **kwargs)

    if path:
        persisted_path = trainer.persist(path,
                                         persistor,
                                         project,
                                         fixed_model_name)
    else:
        persisted_path = None

    return trainer, interpreter, persisted_path 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:38,代码来源:train.py

示例9: test_load_and_persist_without_train

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def test_load_and_persist_without_train(language, pipeline,
                                        component_builder, tmpdir):
    _config = RasaNLUModelConfig({"pipeline": pipeline, "language": language})
    trainer = Trainer(_config, component_builder)
    persistor = create_persistor(_config)
    persisted_path = trainer.persist(tmpdir.strpath, persistor,
                                     project_name="my_project")
    loaded = Interpreter.load(persisted_path, component_builder)
    assert loaded.pipeline
    assert loaded.parse("hello") is not None
    assert loaded.parse("Hello today is Monday, again!") is not None 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:13,代码来源:test_train.py

示例10: train_nlu

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def train_nlu():
    from rasa_nlu.training_data import load_data
    from rasa_nlu.config import RasaNLUModelConfig
    from rasa_nlu.model import Trainer
    from rasa_nlu import config

    training_data = load_data("data/nlu.json")
    trainer = Trainer(config.load("data/nlu_model_config.json"))
    trainer.train(training_data)
    model_directory = trainer.persist("models/", project_name="ivr", fixed_model_name="demo")

    return model_directory 
开发者ID:Ma-Dan,项目名称:rasa_bot,代码行数:14,代码来源:bot.py

示例11: __init__

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def __init__(self, training_data_file = "training_data.json",
                 config_file = "training_config.json"):
        training_data = load_data(training_data_file)        
        trainer = Trainer(config.load(config_file))
        self.interpreter = trainer.train(training_data)
        self.confidence_threshold = 0.7

        # Create supported intents
        context = { 'confidence_threshold': self.confidence_threshold }
        self.intents = {
                "greet"     : intent.HelloIntent(self, context),
                "get_time"  : intent.GetTimeIntent(self, context),
                "ask_joke"  : intent.JokeIntent(self, context),
                "unknown"   : intent.UnKnownIntent(self, context)
            } 
开发者ID:Azure-Samples,项目名称:azure-iot-starter-kits,代码行数:17,代码来源:classification.py

示例12: run_cv_evaluation

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def run_cv_evaluation(data, n_folds, nlu_config):
    # type: (TrainingData, int, RasaNLUModelConfig) -> CVEvaluationResult
    """Stratified cross validation on data

    :param data: Training Data
    :param n_folds: integer, number of cv folds
    :param nlu_config: nlu config file
    :return: dictionary with key, list structure, where each entry in list
              corresponds to the relevant result for one fold
    """
    from collections import defaultdict
    import tempfile

    trainer = Trainer(nlu_config)
    train_results = defaultdict(list)
    test_results = defaultdict(list)
    entity_train_results = defaultdict(lambda: defaultdict(list))
    entity_test_results = defaultdict(lambda: defaultdict(list))
    tmp_dir = tempfile.mkdtemp()

    for train, test in generate_folds(n_folds, data):
        interpreter = trainer.train(train)

        # calculate train accuracy
        train_results = combine_intent_result(train_results, interpreter, train)
        test_results = combine_intent_result(test_results, interpreter, test)
        # calculate test accuracy
        entity_train_results = combine_entity_result(entity_train_results,
                                                     interpreter, train)
        entity_test_results = combine_entity_result(entity_test_results,
                                                    interpreter, test)

    shutil.rmtree(tmp_dir, ignore_errors=True)

    return (CVEvaluationResult(dict(train_results), dict(test_results)),
            CVEvaluationResult(dict(entity_train_results),
                               dict(entity_test_results))) 
开发者ID:crownpku,项目名称:Rasa_NLU_Chi,代码行数:39,代码来源:evaluate.py

示例13: do_train

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def do_train(cfg,  # type: RasaNLUModelConfig
             data,  # type: Text
             path=None,  # type: Optional[Text]
             project=None,  # type: Optional[Text]
             fixed_model_name=None,  # type: Optional[Text]
             storage=None,  # type: Optional[Text]
             component_builder=None,  # type: Optional[ComponentBuilder]
             url=None,  # type: Optional[Text]
             **kwargs  # type: Any
             ):
    # type: (...) -> Tuple[Trainer, Interpreter, Text]
    """Loads the trainer and the data and runs the training of the model."""

    # Ensure we are training a model that we can save in the end
    # WARN: there is still a race condition if a model with the same name is
    # trained in another subprocess
    trainer = Trainer(cfg, component_builder)
    persistor = create_persistor(storage)
    if url is not None:
        training_data = load_data_from_url(url, cfg.language)
    else:
        training_data = load_data(data, cfg.language)
    interpreter = trainer.train(training_data, **kwargs)

    if path:
        persisted_path = trainer.persist(path,
                                         persistor,
                                         project,
                                         fixed_model_name)
    else:
        persisted_path = None

    return trainer, interpreter, persisted_path 
开发者ID:crownpku,项目名称:Rasa_NLU_Chi,代码行数:35,代码来源:train.py

示例14: test_train_with_empty_data

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def test_train_with_empty_data(language, pipeline, component_builder, tmpdir):
    _config = RasaNLUModelConfig({"pipeline": pipeline, "language": language})
    trainer = Trainer(_config, component_builder)
    trainer.train(TrainingData())
    persistor = create_persistor(_config)
    persisted_path = trainer.persist(tmpdir.strpath, persistor,
                                     project_name="my_project")
    loaded = Interpreter.load(persisted_path, component_builder)
    assert loaded.pipeline
    assert loaded.parse("hello") is not None
    assert loaded.parse("Hello today is Monday, again!") is not None 
开发者ID:crownpku,项目名称:Rasa_NLU_Chi,代码行数:13,代码来源:test_train.py

示例15: __init__

# 需要导入模块: from rasa_nlu import model [as 别名]
# 或者: from rasa_nlu.model import Trainer [as 别名]
def __init__(self):
        self.rasa_config = RasaNLUConfig(self.config_file)
        self.trainer = Trainer(self.rasa_config, self.builder) 
开发者ID:Cyberjusticelab,项目名称:JusticeAI,代码行数:5,代码来源:rasa_classifier.py


注:本文中的rasa_nlu.model.Trainer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。