tlc.client.sample_type

Implementations of all SampleType classes.

Module Contents

Classes

Class

Description

AtomicSampleType

Base class for all atomic sample types.

Bool

A python bool.

BoundingBoxList

A COCO-like list of bounding boxes.

Box

A helper SampleType for making a dict with a single value appear as just the value itself, when provided as a sample.

CategoricalLabel

A categorical label.

CompositeSampleType

Base class for all composite sample types.

Confidence

A confidence score.

DimensionalSampleType

Base class for all dimensional sample types.

Float

A floating point number.

Hidden

A value which should not be present in the sample.

HorizontalList

A list of fixed length and structure.

HorizontalTuple

A tuple of fixed length and structure.

ImagePath

A path to an image file.

InstanceSegmentationMasks

A sample type for instance segmentation masks.

InstanceSegmentationPolygons

A sample type for instance segmentation polygons.

Int

An integer.

IoU

An Intersection over Union score.

LargeBytes

A bytes object.

LargeNumpyArray

A large numpy array.

LargeTorchTensor

A large torch tensor.

List

A list of variable length.

NoOpSampleType

The fallback SampleType for atomic schemas.

Number

Base class for numeric types

PILImage

A PIL Image.

Path

A string representing a path.

PythonContainer

Dimensional sample types whose row representation is a list.

ReferencedAtomicSampleType

Base class for referenced atomic sample types.

SampleType

The base class for all sample types.

SegmentationImagePath

A path to a semantic segmentation mask image.

SegmentationMask

A torch tensor representing a segmentation mask.

SegmentationPILImage

A single-channel PIL-image containing a segmentation mask.

Singleton

A sample type for handling the concept of a pseudo-scalar; a scalar which has a size0 with min=max=1.

SmallBytes

A small bytes object.

SmallNumpyArray

A small numpy array.

SmallTorchTensor

A small torch tensor.

String

A python string.

StringKeyDict

A dict with string keys.

TrivialAtomicSampleType

A base class for atomic sample types whose row representation is the same as their sample representation.

Tuple

A tuple of variable length.

Functions

Function

Description

Bytes

Create a Bytes SampleType.

NumpyArray

Create a NumpyArray SampleType.

TorchTensor

Create a TorchTensor SampleType.

register_sample_type

A decorator for registering a SampleType.

Data

Data

Description

RT

Generic row type

ST

Generic sample type

API

class AtomicSampleType(
name: str,
)

Bases: tlc.client.sample_type.SampleType[tlc.client.sample_type.ST, tlc.client.sample_type.RT]

Base class for all atomic sample types.

Atomic sample types are sample types that contain a single value. They are used to represent atomic data structures like ints, floats, strings, and images. Atomic sample types have the value attribute, which is a ScalarValue required to create a Schema for the SampleType.

Subclasses of AtomicSampleType only need to implement the sample_from_row and row_from_sample methods, which define how the value should be converted to and from a row, as well as the value property.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

abstract row_from_sample(
sample: Any,
) Any
abstract sample_from_row(
row: Any,
) Any
property schema: Schema
abstract property value: ScalarValue

A ScalarValue representing the SampleType.

Returns:

The ScalarValue object.

class Bool(
name: str,
)

Bases: tlc.client.sample_type.TrivialAtomicSampleType[bool]

A python bool.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

sample_type = bool
property value: BoolValue
class BoundingBoxList(
name: str,
format: Literal[xywh, xyxy] = 'xyxy',
normalized: bool = False,
classes: list[str] | dict[int, str] | dict[float, str] | dict[float, MapElement] | None = None,
)

Bases: tlc.client.sample_type.StringKeyDict

A COCO-like list of bounding boxes.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

class Box(
child: tlc.client.sample_type._SampleTypeStructure,
hidden_children: list[tlc.client.sample_type._SampleTypeStructure] | None = None,
)

Bases: tlc.client.sample_type.CompositeSampleType[object]

A helper SampleType for making a dict with a single value appear as just the value itself, when provided as a sample.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

ensure_sample_valid(
sample: object,
) None
row_from_sample(
sample: object,
) dict[str, object]
sample_from_row(
row: dict[str, object],
) object
sample_type = box
Bytes(
name: str,
max_size: int,
) LargeBytes | SmallBytes

Create a Bytes SampleType.

If the maximum size of the bytes is less than or equal to a cutoff of 1,000 bytes, a SmallBytes is created. Otherwise, a LargeBytes is created.

Parameters:
  • name – The name of the Bytes SampleType.

  • max_size – The maximum size of the bytes object (in number of bytes).

Returns:

The created SampleType.

class CategoricalLabel(
name: str,
classes: Sequence[str] | Sequence[dict[str, str]] | Sequence[MapElement] | dict[float, str] | dict[int, str] | dict[float, MapElement] | dict[int, MapElement],
)

Bases: tlc.client.sample_type.TrivialAtomicSampleType[int]

A categorical label.

Categorical labels are represented as ints, with the mapping from ints to class names defined by the classes attribute, a list of strings.

Create a CategoricalLabel.

Parameters:
  • name – The name of the CategoricalLabel.

  • classes – The classes of the CategoricalLabel.

sample_type = categorical_label
property value: Int32Value
class CompositeSampleType(
name: str,
children: list[SampleType],
)

Bases: tlc.client.sample_type.SampleType[tlc.client.sample_type.ST, dict[str, object]], typing.Generic[tlc.client.sample_type.ST]

Base class for all composite sample types.

Composite sample types are sample types that contain other sample types. They are used to represent composite data structures like lists, tuples, and dicts. Composite sample types have the children attribute, which is a list of the sample types that they contain.

Subclasses of CompositeSampleType only need to implement the sample_from_row and row_from_sample methods, which define how the children should be composed into a single sample or row.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

ensure_row_valid(
row: object,
) None
ensure_sample_valid(
sample: object,
) None
rename(
name: str,
) None
abstract row_from_sample(
sample: Any,
) dict[str, object]
abstract sample_from_row(
row: dict[str, object],
) Any
property schema: Schema
class Confidence(
name: str,
)

Bases: tlc.client.sample_type.Float

A confidence score.

Parameters:
  • precision – The precision of the float, in bits. Must be one of [32, 64].

  • normalized – Whether the value of the float is normalized between 0 and 1.

  • number_role – The number role of the float. This determines how the float will be displayed in the Dashboard.

class DimensionalSampleType(
content: tlc.client.sample_type._SampleTypeStructure,
)

Bases: tlc.client.sample_type.SampleType[tlc.client.sample_type.ST, tlc.client.sample_type.RT]

Base class for all dimensional sample types.

Dimensional sample types describe how a sample can be extended along a dimension. They are used to represent composite data structures whose size might vary between samples in a dataset. Dimensional sample types have the content attribute, which is a sample type that describes the structure of the samples along the dimension.

Subclasses of DimensionalSampleType only need to implement the sample_from_row and row_from_sample methods, which define how the content should be composed into a single sample or row.

The basic initializer for all DimensionalSampleType objects.

Parameters:

content – The sample type that describes the structure of the samples along the dimension.

ensure_row_valid(
row: object,
) None
ensure_sample_valid(
sample: object,
) None
rename(
name: str,
) None
abstract row_from_sample(
sample: Any,
) Any
abstract sample_from_row(
row: Any,
) Any
class Float(
name: str,
precision: Literal[32, 64] = 64,
normalized: bool = False,
number_role: str = '',
)

Bases: tlc.client.sample_type.Number[float]

A floating point number.

Parameters:
  • precision – The precision of the float, in bits. Must be one of [32, 64].

  • normalized – Whether the value of the float is normalized between 0 and 1.

  • number_role – The number role of the float. This determines how the float will be displayed in the Dashboard.

ensure_sample_valid(
sample: object,
) None
sample_type = float
property value: Float32Value | Float64Value
class Hidden(
name: str,
schema: Schema,
)

Bases: tlc.client.sample_type.SampleType[object, object]

A value which should not be present in the sample.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

ensure_sample_valid(
sample: object,
) None

Hidden values will not be present in the ‘sample view’, but this function never raises in order to allow users to write values with a “hidden” sample type in their schema to a Table using TableWriter.

row_from_sample(
sample: object,
) object

While the ‘sample view’ of a Hidden sample normally does not exist, this is a useful workaround for writing values with a “hidden” sample type in their schema to a Table using TableWriter

sample_from_row(
row: object,
) NoReturn
sample_type = hidden
property schema: Schema
class HorizontalList(
name: str,
children: list[SampleType],
)

Bases: tlc.client.sample_type.CompositeSampleType[list]

A list of fixed length and structure.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

row_from_sample(
sample: list,
) dict[str, object]
sample_from_row(
row: dict[str, object],
) list
sample_type = horizontal_list
class HorizontalTuple(
name: str,
children: list[SampleType],
)

Bases: tlc.client.sample_type.CompositeSampleType[tuple]

A tuple of fixed length and structure.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

row_from_sample(
sample: tuple,
) dict[str, object]
sample_from_row(
row: dict[str, object],
) tuple
sample_type = horizontal_tuple
class ImagePath(
name: str,
)

Bases: tlc.client.sample_type.Path

A path to an image file.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

sample_type = image_path
property value: StringValue
class InstanceSegmentationMasks(
name: str,
instance_properties_structure: dict[str, dict | tlc.client.sample_type._SampleTypeStructure] | None,
is_prediction: bool = False,
)

Bases: tlc.client.sample_type._InstanceSegmentation

A sample type for instance segmentation masks.

A sample of this type is a dictionary with the fields defined by the TypedDict SegmentationMasksDict.

Parameters:
  • name – The name of the sample type.

  • instance_properties_structure – The structure of the instance properties.

  • is_prediction – Whether the instance segmentation is a prediction.

create_rles_from_sample(
sample: SegmentationMasksDict,
) list[pycocotools._EncodedRLE]
ensure_sample_valid(
sample: object,
) None
sample_from_row(
row: tlc.core.data_formats.segmentation._InternalInstanceSegmentationDict,
) SegmentationMasksDict
sample_type = instance_segmentation_masks
class InstanceSegmentationPolygons(
name: str,
instance_properties_structure: dict[str, dict | tlc.client.sample_type._SampleTypeStructure],
relative: bool = False,
is_prediction: bool = False,
)

Bases: tlc.client.sample_type._InstanceSegmentation

A sample type for instance segmentation polygons.

A sample of this type is a dictionary with the fields defined by the TypedDict SegmentationPolygonsDict.

Parameters:
  • name – The name of the sample type.

  • instance_properties_structure – The structure of the instance properties.

  • relative – Whether the polygons are relative to the image size.

  • is_prediction – Whether the instance segmentation is a prediction.

create_rles_from_sample(
sample: SegmentationPolygonsDict,
) list[pycocotools._EncodedRLE]
ensure_sample_valid(
sample: object,
) None
sample_from_row(
row: tlc.core.data_formats.segmentation._InternalInstanceSegmentationDict,
) SegmentationPolygonsDict
sample_type = instance_segmentation_polygons
class Int(
name: str,
precision: Literal[8, 16, 32, 64] = 32,
signed: bool = True,
number_role: str = '',
)

Bases: tlc.client.sample_type.Number[int]

An integer.

Parameters:
  • precision – The precision of the integer, in bits. Must be one of [8, 16, 32, 64].

  • signed – Whether the value of the integer can be negative.

  • number_role – The number role of the integer. This determines how the integer will be displayed in the Dashboard.

ensure_sample_valid(
sample: object,
) None
sample_type = int
property value: tlc.client.sample_type._IntegerValue
class IoU(
name: str,
)

Bases: tlc.client.sample_type.Float

An Intersection over Union score.

Parameters:
  • precision – The precision of the float, in bits. Must be one of [32, 64].

  • normalized – Whether the value of the float is normalized between 0 and 1.

  • number_role – The number role of the float. This determines how the float will be displayed in the Dashboard.

class LargeBytes(
name: str,
)

Bases: tlc.client.sample_type.ReferencedAtomicSampleType[bytes]

A bytes object.

Bytes objects with this sample type will, as opposed to SmallBytes, be stored in a table as references to files. This is useful for large binary data.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

extension = bin
read_sample_from_buffer(
buffer: BytesIO,
) bytes
sample_type = large_bytes
property value: UrlStringValue
write_sample_to_buffer(
sample: bytes,
buffer: BytesIO,
) None
class LargeNumpyArray(
name: str,
)

Bases: tlc.client.sample_type._LargeTensor[numpy.ndarray], tlc.client.sample_type._NumpyDataTypeMixin

A large numpy array.

Numpy arrays with this sample type will, as opposed to SmallNumpyArray, be stored in a table as references to files on disk. This is useful for large arrays that would be inefficient to store in the table itself. Note that you will not be able to view or edit individual elements of the array in the 3LC Dashboard when using this sample type.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

extension = npy
read_sample_from_buffer(
buffer: BytesIO,
) ndarray
sample_type = large_numpy_array
write_sample_to_buffer(
sample: ndarray,
buffer: BytesIO,
) None
class LargeTorchTensor(
content: SampleType,
)

Bases: tlc.client.sample_type._LargeTensor[torch.Tensor], tlc.client.sample_type._TorchDataTypeMixin

A large torch tensor.

Torch tensors with this sample type will, as opposed to SmallTorchTensor, be stored in a table as references to files on disk. This is useful for large tensors that would be inefficient to store in the table itself. Note that you will not be able to view or edit individual elements of the tensor in the 3LC Dashboard when using this sample type.

extension = pt
read_sample_from_buffer(
buffer: BytesIO,
) Tensor
sample_type = large_torch_tensor
write_sample_to_buffer(
sample: Tensor,
buffer: BytesIO,
) None
class List(
content: tlc.client.sample_type._SampleTypeStructure,
min_size: int = 0,
max_size: int | None = None,
)

Bases: tlc.client.sample_type.PythonContainer[list]

A list of variable length.

Parameters:
  • content – The sample type that describes the structure of the samples along the dimension.

  • min_size – The minimum size of the container.

  • max_size – The maximum size of the container.

ensure_sample_valid(
sample: object,
) None
sample_from_row(
row: list,
) list
sample_type = list
class NoOpSampleType(
name: str,
value: ScalarValue,
)

Bases: tlc.client.sample_type.TrivialAtomicSampleType[object]

The fallback SampleType for atomic schemas.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

sample_type = <Multiline-String>
property value: ScalarValue
class Number(
name: str,
number_role: str = '',
)

Bases: tlc.client.sample_type.TrivialAtomicSampleType[tlc.client.sample_type.ST]

Base class for numeric types

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

NumpyArray(
shape: tuple[int, ...] | int,
content: SampleType,
) SmallNumpyArray | LargeNumpyArray

Create a NumpyArray SampleType.

If the number of elements in the array is less than or equal to a cutoff of 1000, a SmallNumpyArray is created. Otherwise, a LargeNumpyArray is created.

Parameters:
  • shape – The shape of the array.

  • content – A SampleType representing the content of the array. A numpy array with dtype=f32, for instance, would have a content of tlc.Float("<Array Name>", precision=32).

Returns:

The created SampleType.

class PILImage(
name: str,
)

Bases: tlc.client.sample_type.ReferencedAtomicSampleType[PIL.Image.Image]

A PIL Image.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

extension = png
read_sample_from_buffer(
buffer: BytesIO,
) Image
row_from_sample(
sample: Image,
) str
sample_from_row(
row: str,
) Image
sample_type = PILImage
property value: StringValue
write_sample_to_buffer(
sample: Image,
buffer: BytesIO,
) None
class Path(
name: str,
)

Bases: tlc.client.sample_type.AtomicSampleType[str, str]

A string representing a path.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

row_from_sample(
sample: str,
) str
sample_from_row(
row: str,
) str
sample_type: str = path
property value: StringValue
class PythonContainer(
content: tlc.client.sample_type._SampleTypeStructure,
min_size: int = 0,
max_size: int | None = None,
)

Bases: tlc.client.sample_type.DimensionalSampleType[tlc.client.sample_type._ContainerST, list]

Dimensional sample types whose row representation is a list.

Parameters:
  • content – The sample type that describes the structure of the samples along the dimension.

  • min_size – The minimum size of the container.

  • max_size – The maximum size of the container.

ensure_row_valid(
row: object,
) None
ensure_sample_valid(
sample: object,
) None
row_from_sample(
sample: tlc.client.sample_type._ContainerST,
) list
property schema: Schema
RT = TypeVar(...)

Generic row type

class ReferencedAtomicSampleType(
name: str,
)

Bases: tlc.client.sample_type.AtomicSampleType[tlc.client.sample_type.ST, str]

Base class for referenced atomic sample types.

These are samples whose row value is a reference to a file, but whose sample value is the file content.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

extension: str = None
abstract read_sample_from_buffer(
buffer: BytesIO,
) Any
row_from_sample(
sample: Any,
) str
sample_from_row(
row: str,
) Any
abstract write_sample_to_buffer(
sample: Any,
buffer: BytesIO,
) None
ST = TypeVar(...)

Generic sample type

class SampleType(
name: str,
)

Bases: abc.ABC, typing.Generic[tlc.client.sample_type.ST, tlc.client.sample_type.RT]

The base class for all sample types.

A SampleType defines the type of a single sample. It can be used to create a Schema for a Table, and convert samples between their ML ‘sample’ representation and their Table ‘row’ representation. SampleType objects are structured like trees, with composite types (e.g. lists, tuples, dicts) as internal nodes and atomic types (e.g. ints, floats, strings) as leaves.

SampleType objects can be created in three main ways:

  1. From a Schema object, using SampleType.from_schema(schema).

  2. From a sample, using SampleType.from_sample(sample).

  3. From a ‘structure’, a simple declarative description of the structure of a single sample, using SampleType.from_structure(structure).

If you have custom types that you want to use in your Table, you can create a SampleType for them by subclassing the appropriate subclass of SampleType and registering it with the register_sample_type decorator.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

ensure_row_valid(
row: object,
) None

Raises a ValueError if the row does not match this SampleType. Does nothing otherwise.

Parameters:

row – The row to validate.

Raises:

ValueError – If the row does not match this SampleType.

ensure_sample_valid(
sample: object,
) None

Raises a ValueError if the sample does not match this SampleType. Does nothing otherwise.

Parameters:

sample – The sample to validate.

Raises:

ValueError – If the sample does not match this SampleType.

classmethod from_sample(
sample: Any,
name: str = 'value',
all_arrays_are_fixed_size: bool = False,
) SampleType

Create a SampleType from a sample.

This method is used to create a SampleType when creating a Table from a PyTorch Dataset, and the user has not specified a SampleType or a structure. Since a SampleType is needed to convert a sample to a row, the first sample of the dataset is used as a reference to create the SampleType.

Parameters:
  • sample – The sample to create the SampleType from.

  • name – The name of the SampleType.

  • all_arrays_are_fixed_size – If True, all arrays will be treated as fixed size arrays.

Returns:

The created SampleType.

classmethod from_schema(
schema: Schema,
name: str = 'value',
) SampleType

Create a SampleType from a Schema.

Parameters:
  • schema – The Schema to create the SampleType from.

  • name – An optional name for the NoOpSampleType fallback.

Returns:

The created SampleType.

classmethod from_structure(
structure: tlc.client.sample_type._SampleTypeStructure,
name: str = 'value',
) SampleType

Create a SampleType from a structure.

A structure is a simple declarative description of the structure of a single sample. Instead of initializing SampleType objects for composite sample types, structures can be represented as nested lists, tuples, or dicts containing either SampleType objects, or simply a subclass of SampleType where you don’t care about the names of the columns.

E.g. ((Int, Int), String) is equivalent to:

HorizontalTuple("value",
    [
        HorizontalTuple("value_0", [Int("value_0_0"), Int("value_0_1")]),
        String("value_1")
    ]
)
Parameters:
  • structure – The structure to create the SampleType from.

  • name – The name of the SampleType.

Returns:

The created SampleType.

rename(
name: str,
) None

Rename the SampleType.

Parameters:

name – The new name of the SampleType.

abstract row_from_sample(
sample: Any,
) Any

Convert a sample to a row using the SampleType.

Parameters:

sample – The sample to convert.

Returns:

The converted row.

abstract sample_from_row(
row: Any,
) Any

Convert a row to a sample using the SampleType.

Parameters:

row – The row to convert.

Returns:

The converted sample.

sample_type: str = None

A string representing the type of the SampleType. This is used to identify the SampleType in a Schema.

abstract property schema: Schema

A Schema object representing the SampleType.

Returns:

The Schema object.

class SegmentationImagePath(
name: str,
classes: Sequence[str] | Sequence[dict[str, str]] | Sequence[MapElement] | dict[float, str] | dict[int, str] | dict[float, MapElement] | dict[int, MapElement],
)

Bases: tlc.client.sample_type.Path

A path to a semantic segmentation mask image.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

sample_type = segmentation_image_path
property value: SegmentationMaskUrlStringValue
class SegmentationMask(
name: str,
classes: Sequence[str] | Sequence[dict[str, str]] | Sequence[MapElement] | dict[float, str] | dict[int, str] | dict[float, MapElement] | dict[int, MapElement],
)

Bases: tlc.client.sample_type.AtomicSampleType[torch.Tensor, str]

A torch tensor representing a segmentation mask.

The tensor is expected to have shape (H, W) and contain integer values representing the class of each pixel.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

row_from_sample(
sample: Tensor,
) str
sample_from_row(
row: str,
) Tensor
sample_type = segmentation_mask
property value: StringValue
class SegmentationPILImage(
name: str,
classes: Sequence[str] | Sequence[dict[str, str]] | Sequence[MapElement] | dict[float, str] | dict[int, str] | dict[float, MapElement] | dict[int, MapElement],
)

Bases: tlc.client.sample_type.PILImage

A single-channel PIL-image containing a segmentation mask.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

sample_type = segmentation_PILImage
property value: SegmentationMaskUrlStringValue
class Singleton(
content: tlc.client.sample_type._SampleTypeStructure,
)

Bases: tlc.client.sample_type.DimensionalSampleType[object, object]

A sample type for handling the concept of a pseudo-scalar; a scalar which has a size0 with min=max=1.

This value should appear in both its sample and row representations as the scalar itself, rather than a list containing the scalar.

The basic initializer for all DimensionalSampleType objects.

Parameters:

content – The sample type that describes the structure of the samples along the dimension.

ensure_row_valid(
row: object,
) None
ensure_sample_valid(
sample: object,
) None
row_from_sample(
sample: object,
) object
sample_from_row(
row: object,
) object
sample_type = singleton
property schema: Schema
class SmallBytes(
name: str,
)

Bases: tlc.client.sample_type.DimensionalSampleType[bytes, bytes]

A small bytes object.

Bytes objects with this sample type will be stored in the table itself. This is useful for small binary data.

The basic initializer for all DimensionalSampleType objects.

Parameters:

content – The sample type that describes the structure of the samples along the dimension.

row_from_sample(
sample: bytes,
) bytes
sample_from_row(
row: bytes,
) bytes
sample_type = small_bytes
property schema: Schema
class SmallNumpyArray(
shape: tuple[int, ...] | int,
content: tlc.client.sample_type._SampleTypeStructure,
)

Bases: tlc.client.sample_type._SmallTensor[numpy.ndarray], tlc.client.sample_type._NumpyDataTypeMixin

A small numpy array.

Numpy arrays with this sample type will be stored in a table as a list of lists. This is useful for small arrays that can be efficiently stored in the table itself. Unlike LargeNumpyArray, you will be able to view and edit individual elements of the array in the 3LC Dashboard when using this sample type.

Parameters:
  • shape – The shape of the array.

  • content – The sample type that describes the structure of one element in the array.

ensure_sample_valid(
sample: object,
) None
row_from_sample(
sample: ndarray,
) list
sample_from_row(
row: list,
) ndarray
sample_type = small_numpy_array
class SmallTorchTensor(
shape: tuple[int, ...] | int,
content: tlc.client.sample_type._SampleTypeStructure,
)

Bases: tlc.client.sample_type._SmallTensor[torch.Tensor], tlc.client.sample_type._TorchDataTypeMixin

A small torch tensor.

Torch tensors with this sample type will be stored in a table as a list of lists. This is useful for small tensors that can be efficiently stored in the table itself. Unlike LargeTorchTensor, you will be able to view and edit individual elements of the tensor in the 3LC Dashboard when using this sample type.

Parameters:
  • shape – The shape of the tensor.

  • content – The sample type that describes the structure of one element in the tensor.

ensure_sample_valid(
sample: object,
) None
row_from_sample(
sample: Tensor,
) list
sample_from_row(
row: list,
) Tensor
sample_type = small_torch_tensor
class String(
name: str,
string_role: str = '',
)

Bases: tlc.client.sample_type.TrivialAtomicSampleType[str]

A python string.

Parameters:

string_role – The string role of the string. This determines how the string will be displayed in the Dashboard.

sample_type = string
property value: StringValue
class StringKeyDict(
name: str,
children: list[SampleType],
)

Bases: tlc.client.sample_type.CompositeSampleType[dict[str, object]]

A dict with string keys.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

ensure_sample_valid(
sample: object,
) None
rename(
name: str,
) None
row_from_sample(
sample: dict[str, object],
) dict[str, object]
sample_from_row(
row: dict[str, object],
) dict[str, object]
sample_type = <Multiline-String>
TorchTensor(
shape: tuple[int, ...] | int,
content: SampleType,
) SmallTorchTensor | LargeTorchTensor

Create a TorchTensor SampleType.

If the number of elements in the tensor is less than or equal to a cutoff of 1000, a SmallTorchTensor is created. Otherwise, a LargeTorchTensor is created.

Parameters:
  • shape – The shape of the tensor.

  • content – A SampleType representing the content of the tensor. A torch tensor with dtype=f32, for instance, would have a content of tlc.Float("<Array Name>", precision=32).

Returns:

The created SampleType.

class TrivialAtomicSampleType(
name: str,
)

Bases: tlc.client.sample_type.AtomicSampleType[tlc.client.sample_type.ST, tlc.client.sample_type.ST]

A base class for atomic sample types whose row representation is the same as their sample representation.

Subclasses of TrivialAtomicSampleType only need to implement the value property.

Parameters:

name – The name of the SampleType. This will be used as the column name in the Table.

row_from_sample(
sample: Any,
) Any
sample_from_row(
row: Any,
) Any
class Tuple(
content: tlc.client.sample_type._SampleTypeStructure,
min_size: int = 0,
max_size: int | None = None,
)

Bases: tlc.client.sample_type.PythonContainer[tuple]

A tuple of variable length.

Parameters:
  • content – The sample type that describes the structure of the samples along the dimension.

  • min_size – The minimum size of the container.

  • max_size – The maximum size of the container.

ensure_sample_valid(
sample: object,
) None
sample_from_row(
row: list,
) tuple
sample_type = tuple
register_sample_type(
sample_type: type[tlc.client.sample_type._SampleTypeSubclass],
) type[tlc.client.sample_type._SampleTypeSubclass]

A decorator for registering a SampleType.

Custom sample types must be registered with this decorator in order to be created from a Schema.

Parameters:

sample_type – The SampleType to register.

Returns:

The registered SampleType.