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


Python Interpreter.load方法代码示例

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


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

示例1: test_random_seed

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def test_random_seed(component_builder, tmpdir):
    """test if train result is the same for two runs of tf embedding"""

    _config = utilities.base_test_conf("supervised_embeddings")
    # set fixed random seed to 1
    _config.set_component_attr(5, random_seed=1)
    # first run
    (trained_a, _, persisted_path_a) = train(
        _config,
        path=tmpdir.strpath + "_a",
        data=DEFAULT_DATA_PATH,
        component_builder=component_builder)
    # second run
    (trained_b, _, persisted_path_b) = train(
        _config,
        path=tmpdir.strpath + "_b",
        data=DEFAULT_DATA_PATH,
        component_builder=component_builder)
    loaded_a = Interpreter.load(persisted_path_a, component_builder)
    loaded_b = Interpreter.load(persisted_path_b, component_builder)
    result_a = loaded_a.parse("hello")["intent"]["confidence"]
    result_b = loaded_b.parse("hello")["intent"]["confidence"]
    assert result_a == result_b 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:25,代码来源:test_train.py

示例2: update_conversation

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def update_conversation(click, text):
    global conv_hist

    # dont update on app load
    if click > 0:
        # call bot with user inputted text
        response, generic_response = utils.bot.respond(
            text,
            interpreter,
            app_data_path
        )
        # user message aligned left
        rcvd = [html.H5(text, style={'text-align': 'left'})]
        # bot response aligned right and italics
        rspd = [html.H5(html.I(r), style={'text-align': 'right'}) for r in response]
        if generic_response:
            generic_msg = 'i couldn\'t find any specifics in your message, here are some popular apps:'
            rspd = [html.H6(html.I(generic_msg))] + rspd
        # append interaction to conversation history
        conv_hist = rcvd + rspd + [html.Hr()] + conv_hist

        return conv_hist
    else:
        return '' 
开发者ID:AdamSpannbauer,项目名称:app_rasa_chat_bot,代码行数:26,代码来源:dash_demo_app.py

示例3: parse

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def parse(self, message):
        interpreter = Interpreter.load(nlu_model_path, RasaNLUConfig("../mom/nlu_model_config.json"))
        intent = interpreter.parse(message)
        return intent
        # return {
        #     "text": message,
        #     "intent": {"name": intent, "confidence": 1.0},
        #     "entities": []
        # } 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:11,代码来源:train_online.py

示例4: run_hello_world

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def run_hello_world(max_training_samples=10,serve_forever=True):
    training_data = '../mom/data/stories.md'

    default_domain = TemplateDomain.load("../mom/domain.yml")
    agent = Agent(default_domain,
                  # policies=[SimplePolicy()],
                  policies=[MemoizationPolicy(), KerasPolicy()],
                  interpreter=HelloInterpreter(),
                  tracker_store=InMemoryTrackerStore(default_domain)
                  )
    logger.info("Starting to train policy")
    # agent = Agent(default_domain,
    #               policies=[SimplePolicy()],
    #               interpreter=HelloInterpreter(),
    #               tracker_store=InMemoryTrackerStore(default_domain))

    # if serve_forever:
    #     # Attach the commandline input to the controller to handle all
    #     # incoming messages from that channel
    #     agent.handle_channel(ConsoleInputChannel())

    agent.train_online(training_data,
                       input_channel=ConsoleInputChannel(),
                       epochs=1,
                       max_training_samples=max_training_samples)


    return agent 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:30,代码来源:train_online.py

示例5: predict

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def predict(model_directory):
    from rasa_nlu.model import Metadata, Interpreter
    # where `model_directory points to the folder the model is persisted in
    interpreter = Interpreter.load(model_directory, RasaNLUConfig("../mom/nlu_model_config.json"))
    print (interpreter.parse("salad"))

# model_directory = train()
# print (model_directory) 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:10,代码来源:train_nlu.py

示例6: parse

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def parse(self, message):
        interpreter = Interpreter.load(nlu_model_path, RasaNLUConfig("../mom/nlu_model_config.json"))
        intent = interpreter.parse(message)
        return intent 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:6,代码来源:test.py

示例7: complex

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def complex():
    agent = Agent.load("../models/policy/mom", interpreter=HelloInterpreter())
    return agent 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:5,代码来源:test.py

示例8: __init__

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def __init__(self, model_directory, config_file=None, lazy_init=False):
        from rasa_nlu.model import Interpreter
        from rasa_nlu.model import Metadata
        from rasa_nlu.config import RasaNLUConfig
        self.metadata = Metadata.load(model_directory)
        self.lazy_init = lazy_init
        self.config_file = config_file

        if not lazy_init:
            self.interpreter = Interpreter.load(self.metadata,
                                                RasaNLUConfig(config_file,
                                                              os.environ))
            # self.interpreter = Interpreter.load(model_directory, RasaNLUConfig(config_file,os.environ))
        else:
            self.interpreter = None 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:17,代码来源:interpreter.py

示例9: parse

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def parse(self, text):
        """Parses a text message.

        Returns a nlu value if the parsing of the text failed."""

        if self.lazy_init and self.interpreter is None:
            from rasa_nlu.model import Interpreter
            from rasa_nlu.config import RasaNLUConfig
            self.interpreter = Interpreter.load(self.metadata,
                                                RasaNLUConfig(self.config_file,
                                                              os.environ))
        return self.interpreter.parse(text) 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:14,代码来源:interpreter.py

示例10: _load_interpreter

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def _load_interpreter(self):
        from rasa_nlu.model import Interpreter

        self.interpreter = Interpreter.load(self.model_directory) 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:6,代码来源:interpreter.py

示例11: run_cmdline

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def run_cmdline(model_path, component_builder=None):
    interpreter = Interpreter.load(model_path, component_builder)

    logger.info("NLU model loaded. Type a message and "
                "press enter to parse it.")
    while True:
        text = input().strip()
        r = interpreter.parse(text)
        print(json.dumps(r, indent=2))
        logger.info("Next message:") 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:12,代码来源:run.py

示例12: pipelines_for_tests

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def pipelines_for_tests():
    # these templates really are just for testing
    # every component should be in here so train-persist-load-use cycle can be
    # tested they still need to be in a useful order - hence we can not simply
    # generate this automatically.

    # first is language followed by list of components
    return [("en", as_pipeline("SpacyNLP",
                               "MitieNLP",
                               "WhitespaceTokenizer",
                               "MitieTokenizer",
                               "SpacyTokenizer",
                               "MitieFeaturizer",
                               "SpacyFeaturizer",
                               "NGramFeaturizer",
                               "RegexFeaturizer",
                               "CountVectorsFeaturizer",
                               "MitieEntityExtractor",
                               "CRFEntityExtractor",
                               "SpacyEntityExtractor",
                               "DucklingHTTPExtractor",
                               "EntitySynonymMapper",
                               "KeywordIntentClassifier",
                               "SklearnIntentClassifier",
                               "MitieIntentClassifier",
                               "EmbeddingIntentClassifier"
                               )),
            ("zh", as_pipeline("MitieNLP",
                               "JiebaTokenizer",
                               "MitieFeaturizer",
                               "MitieEntityExtractor",
                               "SklearnIntentClassifier",
                               )),
            ] 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:36,代码来源:test_train.py

示例13: test_train_model

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def test_train_model(pipeline_template, component_builder, tmpdir):
    _config = utilities.base_test_conf(pipeline_template)
    (trained, _, persisted_path) = train(
        _config,
        path=tmpdir.strpath,
        data=DEFAULT_DATA_PATH,
        component_builder=component_builder)
    assert trained.pipeline
    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,代码行数:14,代码来源:test_train.py

示例14: test_train_model_on_test_pipelines

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def test_train_model_on_test_pipelines(language, pipeline,
                                       component_builder, tmpdir):
    _config = RasaNLUModelConfig({"pipeline": pipeline, "language": language})
    (trained, _, persisted_path) = train(
        _config,
        path=tmpdir.strpath,
        data=DEFAULT_DATA_PATH,
        component_builder=component_builder)
    assert trained.pipeline
    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,代码行数:15,代码来源:test_train.py

示例15: test_train_model_noents

# 需要导入模块: from rasa_nlu.model import Interpreter [as 别名]
# 或者: from rasa_nlu.model.Interpreter import load [as 别名]
def test_train_model_noents(language, pipeline, component_builder, tmpdir):
    _config = RasaNLUModelConfig({"pipeline": pipeline, "language": language})
    (trained, _, persisted_path) = train(
        _config,
        path=tmpdir.strpath,
        data="./data/test/demo-rasa-noents.json",
        component_builder=component_builder)
    assert trained.pipeline
    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,代码行数:14,代码来源:test_train.py


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