NeMo Core APIs#

Base class for all NeMo models#

Base Neural Module class#

Base Mixin classes#

Base Connector classes#

Base Mixin Classes#

Neural Type checking#

Neural Type classes#

class nemo.core.neural_types.NeuralType(axes: Any | None = None, elements_type: Any | None = None, optional: bool = False)[source]#

Bases: object

This is the main class which would represent neural type concept. It is used to represent the types of inputs and outputs.

Parameters:
  • axes (Optional[Tuple]) – a tuple of AxisTypes objects representing the semantics of what varying each axis means You can use a short, string-based form here. For example: (‘B’, ‘C’, ‘H’, ‘W’) would correspond to an NCHW format frequently used in computer vision. (‘B’, ‘T’, ‘D’) is frequently used for signal processing and means [batch, time, dimension/channel].

  • elements_type (ElementType) – an instance of ElementType class representing the semantics of what is stored inside the tensor. For example: logits (LogitsType), log probabilities (LogprobType), etc.

  • optional (bool) – By default, this is false. If set to True, it would means that input to the port of this type can be optional.

compare(second) NeuralTypeComparisonResult[source]#

Performs neural type comparison of self with second. When you chain two modules’ inputs/outputs via __call__ method, this comparison will be called to ensure neural type compatibility.

compare_and_raise_error(parent_type_name, port_name, second_object)[source]#

Method compares definition of one type with another and raises an error if not compatible.

class nemo.core.neural_types.axes.AxisType(kind: AxisKindAbstract, size: int | None = None, is_list=False)[source]#

Bases: object

This class represents axis semantics and (optionally) it’s dimensionality :param kind: what kind of axis it is? For example Batch, Height, etc. :type kind: AxisKindAbstract :param size: specify if the axis should have a fixed size. By default it is set to None and you :type size: int, optional :param typically do not want to set it for Batch and Time: :param is_list: whether this is a list or a tensor axis :type is_list: bool, default=False

class nemo.core.neural_types.elements.ElementType[source]#

Bases: ABC

Abstract class defining semantics of the tensor elements. We are relying on Python for inheritance checking

property type_parameters: Dict[str, Any]#

Override this property to parametrize your type. For example, you can specify ‘storage’ type such as float, int, bool with ‘dtype’ keyword. Another example, is if you want to represent a signal with a particular property (say, sample frequency), then you can put sample_freq->value in there. When two types are compared their type_parameters must match.

property fields#

This should be used to logically represent tuples/structures. For example, if you want to represent a bounding box (x, y, width, height) you can put a tuple with names (‘x’, y’, ‘w’, ‘h’) in here. Under the hood this should be converted to the last tesnor dimension of fixed size = len(fields). When two types are compared their fields must match.

compare(second) NeuralTypeComparisonResult[source]#
class nemo.core.neural_types.comparison.NeuralTypeComparisonResult(value)[source]#

Bases: Enum

The result of comparing two neural type objects for compatibility. When comparing A.compare_to(B):

SAME = 0#
LESS = 1#
GREATER = 2#
DIM_INCOMPATIBLE = 3#
TRANSPOSE_SAME = 4#
CONTAINER_SIZE_MISMATCH = 5#
INCOMPATIBLE = 6#
SAME_TYPE_INCOMPATIBLE_PARAMS = 7#
UNCHECKED = 8#

Experiment manager#

Exportable#