notice
This is unreleased documentation for Rasa Documentation Main/Unreleased version.
For the latest released documentation, see the latest version (3.x).
rasa.engine.graph
SchemaNode Objects
Represents one node in the schema.
Arguments:
needs
- describes which parameters infn
(orconstructor_name
ifeager==False
) are filled by which parent nodes.uses
- The class which models the behavior of this specific graph node.constructor_name
- The name of the constructor which should be used to instantiate the component. Ifeager==False
then theconstructor
can also specify parameters which are filled by parent nodes. This is e.g. useful if a parent node returns aResource
and this node wants to directly load itself from this resource.fn
- The name of the function which should be called on the instantiated component when the graph is executed. The parameters fromneeds
are filled from the parent nodes.fn
1 - The user's configuration for this graph node. This configuration does not need to be specify all possible parameters; the default values for missing parameters will be filled in later.fn
2 - Iffn
2 then the component is instantiated before the graph is run. Otherwise it's instantiated as the graph runs (lazily). Usually we always instantiated lazily during training and eagerly during inference (to avoid that the first prediction takes longer).fn
4 - Iffn
5 then this node can't be pruned during fingerprinting (it might be replaced with a cached value though). This is e.g. used for all components which train as their result always needs to be added to the model archive so that the data is available during inference.fn
6 - Nodes withfn
6 are always run (also during the fingerprint run). This makes sure that we e.g. detect changes in file contents.fn
8 - If given, then the graph node is loaded from an existing resource instead of instantiated from scratch. This is e.g. used to load a trained component for predictions.
GraphSchema Objects
Represents a graph for training a model or making predictions.
as_dict
Returns graph schema in a serializable format.
Returns:
The graph schema in a format which can be dumped as JSON or other formats.
from_dict
Loads a graph schema which has been serialized using schema.as_dict()
.
Arguments:
serialized_graph_schema
- A serialized graph schema.
Returns:
A properly loaded schema.
Raises:
GraphSchemaException
- In case the component class for a node couldn't be found.
target_names
Returns the names of all target nodes.
minimal_graph_schema
Returns a new schema where all nodes are a descendant of a target.
GraphComponent Objects
Interface for any component which will run in a graph.
required_components
Components that should be included in the pipeline before this component.
create
Creates a new GraphComponent
.
Arguments:
config
- This config overrides thedefault_config
.model_storage
- Storage which graph components can use to persist and load themselves.resource
- Resource locator for this component which can be used to persist and load itself from themodel_storage
.execution_context
- Information about the current graph run.Returns
- An instantiatedGraphComponent
.
load
Creates a component using a persisted version of itself.
If not overridden this method merely calls create
.
Arguments:
config
- The config for this graph component. This is the default config of the component merged with config specified by the user.model_storage
- Storage which graph components can use to persist and load themselves.resource
- Resource locator for this component which can be used to persist and load itself from themodel_storage
.execution_context
- Information about the current graph run.kwargs
- Output values from previous nodes might be passed in askwargs
.
Returns:
An instantiated, loaded GraphComponent
.
get_default_config
Returns the component's default config.
Default config and user config are merged by the GraphNode
before the
config is passed to the create
and load
method of the component.
Returns:
The default config of the component.
supported_languages
Determines which languages this component can work with.
Returns: A list of supported languages, or None
to signify all are supported.
not_supported_languages
Determines which languages this component cannot work with.
Returns: A list of not supported languages, or
None
to signify all are supported.
required_packages
Any extra python dependencies required for this component to run.
fingerprint_addon
Adds additional data to the fingerprint calculation.
This is useful if a component uses external data that is not provided by the graph.
GraphNodeHook Objects
Holds functionality to be run before and after a GraphNode
.
on_before_node
Runs before the GraphNode
executes.
Arguments:
node_name
- The name of the node being run.execution_context
- The execution context of the current graph run.config
- The node's config.received_inputs
- Mapping from parameter name to input value.
Returns:
Data that is then passed to on_after_node
on_after_node
Runs after the GraphNode
as executed.
Arguments:
node_name
- The name of the node that has run.execution_context
- The execution context of the current graph run.config
- The node's config.output
- The output of the node.input_hook_data
- Data returned fromon_before_node
.
ExecutionContext Objects
Holds information about a single graph run.
GraphNode Objects
Instantiates and runs a GraphComponent
within a graph.
A GraphNode
is a wrapper for a GraphComponent
that allows it to be executed
in the context of a graph. It is responsible for instantiating the component at the
correct time, collecting the inputs from the parent nodes, running the run function
of the component and passing the output onwards.
__init__
Initializes GraphNode
.
Arguments:
node_name
- The name of the node in the schema.component_class
- The class to be instantiated and run.constructor_name
- The method used to instantiate the component.component_config
- Config to be passed to the component.fn_name
- The function on the instantiatedGraphComponent
to be run when the node executes.inputs
- A map from input name to parent node name that provides it.eager
- Determines if the node is instantiated right away, or just before being run.model_storage
- Storage which graph components can use to persist and load themselves.node_name
0 - If given theGraphComponent
will be loaded from themodel_storage
using the given resource.node_name
3 - Information about the current graph run.node_name
4 - These are called before and after execution.
__call__
Calls the GraphComponent
run method when the node executes in the graph.
Arguments:
*inputs_from_previous_nodes
- The output of all parent nodes. Each is a dictionary with a single item mapping the node's name to its output. If the node couldn't be resolved and has no output, the node name is provided instead of a tuple.
Returns:
The node name and its output.
from_schema_node
Creates a GraphNode
from a SchemaNode
.
GraphModelConfiguration Objects
The model configuration to run as a graph during training and prediction.