Common

Exceptions

class forte.common.exception.PackIndexError[source]

Raise this error when there is a problem accessing the indexes pack data.

class forte.common.exception.IncompleteEntryError[source]

Raise this error when the entry is not complete.

class forte.common.exception.EntryNotFoundError[source]

Raise this error when the entry is not found in the data pack.

class forte.common.exception.ProcessorConfigError[source]

Raise this error when the there is a problem with the processor configuration.

class forte.common.exception.PackDataException[source]

Raise this error when the data in pack is wrong.

class forte.common.exception.ProcessFlowException[source]

Raise this when errors happen in flow control

class forte.common.exception.ProcessExecutionException[source]

Raise this when process execution fail

class forte.common.exception.ValidationError[source]

Raise this error when input validate fail

class forte.common.exception.ResourceError[source]

Raise this error when there are problems accessing Resources of the processor.

class forte.common.exception.ExpectedRecordNotFound[source]

Raise this error when expected type for input is not in input record

class forte.common.exception.InvalidOperationException[source]

Throw when a method call is invalid for the object’s current state

class forte.common.exception.UnknownOntologyClassException[source]

Throw when there are unrecognized ontology class in the input

Configuration

forte.common.configuration.Config

alias of asyml_utilities.hyperparams.HParams

Configurable

class forte.common.configurable.Configurable[source]

Classes that implement the Configurable interface enables the classes to easily manage configurations. The extended classes should implement default_configs to provide additional default configurations. A make_configs functions is provided to create the configurations. There are the following behaviors:

  • default_configs: the default configs provide the configurations structure accepted by this class. This behavior is the same as texar.torch.HParams. If the current class extends another Configurable class, the default_configs of the parent class will be inherited in an recursive way. If the same configuration key is defined for a parent and child class, the one from the child class will prevail.

  • make_configs: this function accepts user configurations and create the configuration by merging the user config and the default configs. Check the docstring of make_configs for its behaviors.

classmethod make_configs(configs)[source]

Create the configuration by merging the provided config with the default_configs.

The following config conventions are expected:

  • The top level key can be a special @config_path.

  • @config_path should be point to a file system path, which will be a YAML file containing configurations.

  • Other key values in the configs will be considered as parameters.

Parameters

configs (Union[HParams, Dict[str, Any], None]) – The input config to be merged with the default config.

Return type

HParams

Returns

The merged configuration.

Resources

class forte.common.resources.Resources(**kwargs)[source]

The Resources object is a global registry used in the pipeline. Objects defined as Resources will be passed on to the processors in the pipeline for initialization.

save(keys=None, output_dir=None)[source]

Save the resources specified by keys in binary format.

Parameters
  • keys (Union[List[str], Dict[str, Callable[[Any, Union[str, Path]], None]], None]) –

    list or dict:

    • If keys is a list, the objects corresponding to those keys are saved

    • If keys is a dict mapping from a key to a serialize function, then the serialize function will be used to save the object corresponding to that key

    • If keys is None, all objects in this resource will be saved.

  • output_dir (Optional[str]) – A directory specifying the location to save the resources.

keys()[source]

Return all keys of the resources.

Return type

KeysView

contains(key)[source]

Return whether the specified key exists.

Return type

bool

get(key)[source]

Get the corresponding resource by specifying the key.

update(**kwargs)[source]

Update the resources.

remove(key)[source]

Remove the corresponding resource by specifying the key.

load(keys, path=None)[source]

Load the resources specified by keys.

Parameters
  • list or dict (keys) –

    • If keys is a list, the objects corresponding to those keys are loaded

    • If keys is a dict mapping from a key to a deserialize function, then the deserialize function will be used to load the object corresponding to that key

  • path (Optional[str]) – str A directory specifying the location to load the resources from.