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


Python training_data.load_data方法代码示例

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


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

示例1: train_model

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [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_dialogue

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def train_dialogue(domain_file="domain.yml",
                         model_path="models/dialogue",
                         training_data_file="data/stories.md"):
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(max_history=3),
                            MappingPolicy(),
                            RestaurantPolicy(batch_size=100, epochs=400,
                                             validation_split=0.2)])

    training_data = await agent.load_data(training_data_file)
    agent.train(
        training_data
    )

    agent.persist(model_path)
    return agent 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:18,代码来源:bot.py

示例3: test_interpreter

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def test_interpreter(pipeline_template, component_builder, tmpdir):
    test_data = "data/examples/rasa/demo-rasa.json"
    _conf = utilities.base_test_conf(pipeline_template)
    _conf["data"] = test_data
    td = training_data.load_data(test_data)
    interpreter = utilities.interpreter_for(component_builder,
                                            "data/examples/rasa/demo-rasa.json",
                                            tmpdir.strpath,
                                            _conf)

    texts = ["good bye", "i am looking for an indian spot"]

    for text in texts:
        result = interpreter.parse(text, time=None)
        assert result['text'] == text
        assert (not result['intent']['name'] or
                result['intent']['name'] in td.intents)
        assert result['intent']['confidence'] >= 0
        # Ensure the model doesn't detect entity types that are not present
        # Models on our test data set are not stable enough to
        # require the exact entities to be found
        for entity in result['entities']:
            assert entity['entity'] in td.entities 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:25,代码来源:test_interpreter.py

示例4: test_dialogflow_data

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def test_dialogflow_data():
    td = training_data.load_data('data/examples/dialogflow/')
    assert len(td.entity_examples) == 5
    assert len(td.intent_examples) == 24
    assert len(td.training_examples) == 24
    assert len(td.lookup_tables) == 2
    assert td.intents == {"affirm", "goodbye", "hi", "inform"}
    assert td.entities == {"cuisine", "location"}
    non_trivial_synonyms = {k: v
                            for k, v in td.entity_synonyms.items() if k != v}
    assert non_trivial_synonyms == {"mexico": "mexican",
                                    "china": "chinese",
                                    "india": "indian"}
    # The order changes based on different computers hence the grouping
    assert {td.lookup_tables[0]['name'],
            td.lookup_tables[1]['name']} == {'location', 'cuisine'}
    assert {len(td.lookup_tables[0]['elements']),
            len(td.lookup_tables[1]['elements'])} == {4, 6} 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:20,代码来源:test_training_data.py

示例5: test_spacy_featurizer_casing

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def test_spacy_featurizer_casing(spacy_nlp):
    from rasa_nlu.featurizers import spacy_featurizer

    # if this starts failing for the default model, we should think about
    # removing the lower casing the spacy nlp component does when it
    # retrieves vectors. For compressed spacy models (e.g. models
    # ending in _sm) this test will most likely fail.

    td = training_data.load_data('data/examples/rasa/demo-rasa.json')
    for e in td.intent_examples:
        doc = spacy_nlp(e.text)
        doc_capitalized = spacy_nlp(e.text.capitalize())

        vecs = spacy_featurizer.features_for_doc(doc)
        vecs_capitalized = spacy_featurizer.features_for_doc(doc_capitalized)

        assert np.allclose(vecs, vecs_capitalized, atol=1e-5), \
            "Vectors are unequal for texts '{}' and '{}'".format(
                e.text, e.text.capitalize()) 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:21,代码来源:test_featurizers.py

示例6: test_interpreter

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def test_interpreter(pipeline_template, component_builder, tmpdir):
    test_data = "data/examples/rasa/demo-rasa.json"
    _conf = utilities.base_test_conf(pipeline_template)
    _conf["data"] = test_data
    td = training_data.load_data(test_data)
    interpreter = utilities.interpreter_for(component_builder,
                                            "data/examples/rasa/demo-rasa.json",
                                            tmpdir.strpath,
                                            _conf)

    texts = ["good bye", "i am looking for an indian spot"]

    for text in texts:
        result = interpreter.parse(text, time=None)
        assert result['text'] == text
        assert (not result['intent']['name']
                or result['intent']['name'] in td.intents)
        assert result['intent']['confidence'] >= 0
        # Ensure the model doesn't detect entity types that are not present
        # Models on our test data set are not stable enough to
        # require the exact entities to be found
        for entity in result['entities']:
            assert entity['entity'] in td.entities 
开发者ID:crownpku,项目名称:Rasa_NLU_Chi,代码行数:25,代码来源:test_interpreter.py

示例7: train_models

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [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

示例8: test_demo_data

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def test_demo_data(filename):
    td = training_data.load_data(filename)
    assert td.intents == {"affirm", "greet", "restaurant_search", "goodbye"}
    assert td.entities == {"location", "cuisine"}
    assert len(td.training_examples) == 42
    assert len(td.intent_examples) == 42
    assert len(td.entity_examples) == 11

    assert td.entity_synonyms == {'Chines': 'chinese',
                                  'Chinese': 'chinese',
                                  'chines': 'chinese',
                                  'vegg': 'vegetarian',
                                  'veggie': 'vegetarian'}

    assert td.regex_features == [{"name": "greet", "pattern": "hey[^\s]*"},
                                 {"name": "zipcode", "pattern": "[0-9]{5}"}] 
开发者ID:crownpku,项目名称:Rasa_NLU_Chi,代码行数:18,代码来源:test_training_data.py

示例9: test_spacy_featurizer_casing

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def test_spacy_featurizer_casing(spacy_nlp):
    from rasa_nlu.featurizers import spacy_featurizer

    # if this starts failing for the default model, we should think about
    # removing the lower casing the spacy nlp component does when it
    # retrieves vectors. For compressed spacy models (e.g. models
    # ending in _sm) this test will most likely fail.

    td = training_data.load_data('data/examples/rasa/demo-rasa.json')
    for e in td.intent_examples:
        doc = spacy_nlp(e.text)
        doc_capitalized = spacy_nlp(e.text.capitalize())

        vecs = spacy_featurizer.features_for_doc(doc)
        vecs_capitalized = spacy_featurizer.features_for_doc(doc_capitalized)

        assert np.allclose(vecs, vecs_capitalized, atol=1e-5), \
            "Vectors are unequal for texts '{}' and '{}'".format(
                    e.text, e.text.capitalize()) 
开发者ID:crownpku,项目名称:Rasa_NLU_Chi,代码行数:21,代码来源:test_featurizers.py

示例10: train_dialogue

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def train_dialogue(
        domain_file="domain.yml",
        model_path="models/dialogue",
        training_data_file="data/stories.md"
        ):
    agent = Agent(
        domain_file,
        policies=[MemoizationPolicy(max_history=3), KerasPolicy()]
        )
    training_data = agent.load_data(training_data_file)
    agent.train(
        training_data,
        epochs=400,
        batch_size=100,
        validation_split=0.2
        )
    agent.persist(model_path)
    return agent 
开发者ID:MartinGentleman,项目名称:weather-bot,代码行数:20,代码来源:trainer.py

示例11: train_nlu

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [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

示例12: visualize

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def visualize(config_path: Text, domain_path: Text, stories_path: Text,
                    nlu_data_path: Text, output_path: Text, max_history: int):
    from rasa.core.agent import Agent
    from rasa.core import config

    policies = config.load(config_path)

    agent = Agent(domain_path, policies=policies)

    # this is optional, only needed if the `/greet` type of
    # messages in the stories should be replaced with actual
    # messages (e.g. `hello`)
    if nlu_data_path is not None:
        from rasa_nlu.training_data import load_data

        nlu_data_path = load_data(nlu_data_path)
    else:
        nlu_data_path = None

    logger.info("Starting to visualize stories...")
    await agent.visualize(stories_path, output_path,
                          max_history,
                          nlu_training_data=nlu_data_path)

    full_output_path = "file://{}".format(os.path.abspath(output_path))
    logger.info("Finished graph creation. Saved into {}".format(
        full_output_path))

    import webbrowser
    webbrowser.open(full_output_path) 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:32,代码来源:visualize.py

示例13: convert_training_data

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def convert_training_data(data_file, out_file, output_format, language):
    td = training_data.load_data(data_file, language)

    if output_format == 'md':
        output = td.as_markdown()
    else:
        output = td.as_json(indent=2)

    write_to_file(out_file, output) 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:11,代码来源:convert.py

示例14: train

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [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

示例15: test_luis_data

# 需要导入模块: from rasa_nlu import training_data [as 别名]
# 或者: from rasa_nlu.training_data import load_data [as 别名]
def test_luis_data():
    td = training_data.load_data('data/examples/luis/demo-restaurants.json')
    assert len(td.entity_examples) == 8
    assert len(td.intent_examples) == 28
    assert len(td.training_examples) == 28
    assert td.entity_synonyms == {}
    assert td.intents == {"affirm", "goodbye", "greet", "inform"}
    assert td.entities == {"location", "cuisine"} 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:10,代码来源:test_training_data.py


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