Represents a dimension of a tensor. A dimension can come with further information such as individual sequence lengths.

This identifies one axis/dimension, like a time-dimension, etc. This was called DimensionTag earlier, and referred to as dimension tag.

This is used by Tensor (earlier Data). See Tensor.dims(). This would be passed as dims when creating a Tensor instance.

It is not to specify the specific axis in a specific Tensor, but to specify the content and dimension. I.e. if we have the same Dim for two Data instances, the dimensions should match. I.e.:

data1.dims[i] == data2.dims[j]

=> data1.raw_tensor.shape[i] == data2.raw_tensor.shape[j]

This also includes further information such as sequence lengths or a vocabulary.

Deprecated: We differentiate between the batch dim, spatial dim or feature dim, although that is just flag and in many contexts there is no real difference between a spatial dim and a feature dim (the batch dim is often handled differently).

class returnn.tensor.dim.Dim(dimension: int | Tensor | None, *, name: str | None = None, capacity: int | None = None, dyn_size_ext: Tensor | None = None, description: str | None = None, **kwargs)[source]#

Represents a dimension of a tensor. This potentially comes with further information such as individual sequence lengths. See the module docstring.


alias of DimTypes

capacity: int | None[source]#
size: int | None[source]#
dyn_size_ext: Tensor | None[source]#
name: str | None[source]#
exception returnn.tensor.dim.VerifyOutShapeException[source]#

Exception via Tensor.verify_out_shape().