Embedding
docarray.typing.tensor.embedding.embedding
AnyEmbedding
Bases: AnyTensor
, EmbeddingMixin
Represents an embedding tensor object that can be used with TensorFlow, PyTorch, and NumPy type.
'''python from docarray import BaseDoc from docarray.typing import AnyEmbedding
class MyEmbeddingDoc(BaseDoc): embedding: AnyEmbedding
Example usage with TensorFlow:
import tensorflow as tf
doc = MyEmbeddingDoc(embedding=tf.zeros(1000, 2)) type(doc.embedding) # TensorFlowEmbedding
Example usage with PyTorch:
import torch
doc = MyEmbeddingDoc(embedding=torch.zeros(1000, 2)) type(doc.embedding) # TorchEmbedding
Example usage with NumPy:
import numpy as np
doc = MyEmbeddingDoc(embedding=np.zeros((1000, 2))) type(doc.embedding) # NdArrayEmbedding '''
Raises: TypeError: If the type of the value is not one of [torch.Tensor, tensorflow.Tensor, numpy.ndarray]
Source code in docarray/typing/tensor/embedding/embedding.py
docarray.typing.tensor.embedding.embedding_mixin
docarray.typing.tensor.embedding.ndarray
docarray.typing.tensor.embedding.tensorflow
docarray.typing.tensor.embedding.torch
TorchEmbedding
Bases: TorchTensor
, EmbeddingMixin
Source code in docarray/typing/tensor/embedding/torch.py
new_empty(*args, **kwargs)
This method enables the deepcopy of TorchEmbedding
by returning another instance of this subclass.
If this function is not implemented, the deepcopy will throw an RuntimeError from Torch.