jina.executors.encoders

class jina.executors.encoders.BaseEncoder(*args, **kwargs)[source]

Bases: jina.executors.BaseExecutor

BaseEncoder encodes chunk into vector representation.

The key function is encode().

See also

jina.drivers.handlers.encode

encode(data, *args, **kwargs)[source]
Return type

Any

train(*args, **kwargs)

Train this executor, need to be overrided

Return type

None

class jina.executors.encoders.BaseNumericEncoder(*args, **kwargs)[source]

Bases: jina.executors.encoders.BaseEncoder

BaseNumericEncoder encodes data from a ndarray, potentially B x ([T] x D) into a ndarray of B x D

encode(data, *args, **kwargs)[source]
Parameters

data (np.ndarray) – a B x ([T] x D) numpy ndarray, B is the size of the batch

Return type

np.ndarray

Returns

a B x D numpy ndarray

train(*args, **kwargs)

Train this executor, need to be overrided

Return type

None

class jina.executors.encoders.BaseImageEncoder(*args, **kwargs)[source]

Bases: jina.executors.encoders.BaseNumericEncoder

BaseImageEncoder encodes data from a ndarray, potentially B x (Height x Width) into a ndarray of B x D

train(*args, **kwargs)

Train this executor, need to be overrided

Return type

None

class jina.executors.encoders.BaseVideoEncoder(*args, **kwargs)[source]

Bases: jina.executors.encoders.BaseNumericEncoder

BaseVideoEncoder encodes data from a ndarray, potentially B x (Time x Height x Width) into a ndarray of B x D

train(*args, **kwargs)

Train this executor, need to be overrided

Return type

None

class jina.executors.encoders.BaseAudioEncoder(*args, **kwargs)[source]

Bases: jina.executors.encoders.BaseNumericEncoder

BaseAudioEncoder encodes data from a ndarray, potentially B x (Time x D) into a ndarray of B x D

train(*args, **kwargs)

Train this executor, need to be overrided

Return type

None

class jina.executors.encoders.BaseTextEncoder(*args, **kwargs)[source]

Bases: jina.executors.encoders.BaseEncoder

BaseTextEncoder encodes data from an array of string type (data.dtype.kind == ‘U’) of size B into a ndarray of B x D.

encode(data, *args, **kwargs)[source]
Parameters

data (np.ndarray) – an 1d array of string type (data.dtype.kind == ‘U’) in size B

Return type

np.ndarray

Returns

an ndarray of B x D

train(*args, **kwargs)

Train this executor, need to be overrided

Return type

None

class jina.executors.encoders.PipelineEncoder(routes=None, resolve_all=True, *args, **kwargs)[source]

Bases: jina.executors.compound.CompoundExecutor

Create a new CompoundExecutor object

Parameters
  • routes (Optional[Dict[str, Dict]]) –

    a map of function routes. The key is the function name, the value is a tuple of two pieces, where the first element is the name of the referred component (metas.name) and the second element is the name of the referred function.

    See also

    add_route()

  • resolve_all (bool) – universally add *_all() to all functions that have the identical name

Example:

We have two dummy executors as follows:

class dummyA(BaseExecutor):
    def say(self):
        return 'a'

    def sayA(self):
        print('A: im A')


class dummyB(BaseExecutor):
    def say(self):
        return 'b'

    def sayB(self):
        print('B: im B')

and we create a CompoundExecutor consisting of these two via

da, db = dummyA(), dummyB()
ce = CompoundExecutor()
ce.components = lambda: [da, db]

Now the new executor ce have two new methods, i.e ce.sayA() and ce.sayB(). They point to the original dummyA.sayA() and dummyB.sayB() respectively. One can say ce has inherited these two methods.

The interesting part is say(), as this function name is shared between dummyA and dummyB. It requires some resolution. When resolve_all=True, then a new function say_all() is add to ce. ce.say_all works as if you call dummyA.sayA() and dummyB.sayB() in a row. This makes sense in some cases such as training, saving. In other cases, it may require a more sophisticated resolution, where one can use add_route() to achieve that. For example,

ce.add_route('say', db.name, 'say')
assert b.say() == 'b'

Such resolution is what we call routes here, and it can be specified in advance with the arguments routes in __init__(), or using YAML.

!CompoundExecutor
components: ...
with:
  resolve_all: true
  routes:
    say:
    - dummyB-e3acc910
    - say
encode(data, *args, **kwargs)[source]
Return type

Any

train(data, *args, **kwargs)[source]

Train this executor, need to be overrided

Return type

None