本文整理汇总了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
示例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 ''
示例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": []
# }
示例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
示例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)
示例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
示例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
示例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
示例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)
示例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)
示例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:")
示例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",
)),
]
示例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
示例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
示例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