Skip to content

pixano.data.item.item_embedding

ItemEmbedding(**data)

Bases: BaseModel

Embedding type for DatasetItem

Attributes:

Name Type Description
view_id str

Embedding view ID

data str

Embedding data in base 64

Raises ValidationError if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Source code in pydantic/main.py
def __init__(self, /, **data: Any) -> None:
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.
    """
    # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    __tracebackhide__ = True
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    if self is not validated_self:
        warnings.warn(
            'A custom validator is returning a value other than `self`.\n'
            "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
            'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
            category=None,
        )

from_pyarrow(table, schema) staticmethod

Create dictionary of ItemEmbedding from PyArrow Table

Parameters:

Name Type Description Default
table dict[str, Any]

PyArrow table

required
schema schema

PyArrow schema

required

Returns:

Type Description
dict[str, ItemEmbedding]

Dictionary of ItemEmbedding

Source code in pixano/data/item/item_embedding.py
@staticmethod
def from_pyarrow(table: pa.Table, schema: pa.schema) -> dict[str, "ItemEmbedding"]:
    """Create dictionary of ItemEmbedding from PyArrow Table

    Args:
        table (dict[str, Any]): PyArrow table
        schema (pa.schema): PyArrow schema

    Returns:
        dict[str, ItemEmbedding]: Dictionary of ItemEmbedding
    """

    list_item = table.to_pylist()
    if len(list_item) == 0:
        return {}
    item = list_item[0]
    embeddings = {}

    # Iterate on fields
    for field in schema:
        # Image
        if is_binary(field.type):
            embeddings[field.name] = ItemEmbedding(
                view_id=field.name,
                data=base64.b64encode(item[field.name]).decode("ascii"),
            )

    return embeddings