jina.drivers.predict

class jina.drivers.predict.BasePredictDriver(executor=None, method='predict', fields='embedding', *args, **kwargs)[source]

Bases: jina.drivers.FlatRecursiveMixin, jina.drivers.BaseExecutableDriver

Drivers inherited from BasePredictDriver will bind predict() by default

Parameters
  • fields (Union[Tuple, str]) – name of fields to be used to predict tags, default “embeddings”

  • args – additional positional arguments which are just used for the parent initialization

  • kwargs – additional key value arguments which are just used for the parent initialization

runtime: Optional[ZEDRuntime]
class jina.drivers.predict.BaseLabelPredictDriver(output_tag='prediction', *args, **kwargs)[source]

Bases: jina.drivers.predict.BasePredictDriver

Base class of a Driver for label prediction.

Parameters
  • output_tag (str) – output label will be written to doc.tags

  • args – additional positional arguments which are just used for the parent initialization

  • kwargs – additional key value arguments which are just used for the parent initialization

prediction2label(prediction)[source]

Converting ndarray prediction into list of readable labels

Note

len(output) should be the same as prediction.shape[0]

Parameters

prediction (ndarray) – the float/int numpy ndarray given by BaseClassifier

Return type

List[Any]

Returns

the readable label to be stored.

runtime: Optional[ZEDRuntime]
class jina.drivers.predict.BinaryPredictDriver(one_label='yes', zero_label='no', *args, **kwargs)[source]

Bases: jina.drivers.predict.BaseLabelPredictDriver

Converts binary prediction into string label. This is often used with binary classifier.

Parameters
  • one_label (str) – label when prediction is one

  • zero_label (str) – label when prediction is zero

  • args – additional positional arguments which are just used for the parent initialization

  • kwargs – additional key value arguments which are just used for the parent initialization

prediction2label(prediction)[source]
Parameters

prediction (ndarray) – a (B,) or (B, 1) zero one array

Return type

List[str]

Returns

the labels as either self.one_label or self.zero_label

runtime: Optional[ZEDRuntime]
class jina.drivers.predict.OneHotPredictDriver(labels, *args, **kwargs)[source]

Bases: jina.drivers.predict.BaseLabelPredictDriver

Mapping prediction to one of the given labels

Expect prediction to be 2dim array, zero-one valued. Each row corresponds to a sample, each column corresponds to a label. Each row can have only one 1.

This is often used with multi-class classifier.

validate_labels(prediction)[source]

Validate the labels.

Parameters

prediction (ndarray) – the predictions

prediction2label(prediction)[source]
Parameters

prediction (ndarray) – a (B, C) array where C is the number of classes, only one element can be one

Return type

List[str]

Returns

the list of labels

runtime: Optional[ZEDRuntime]
class jina.drivers.predict.MultiLabelPredictDriver(labels, *args, **kwargs)[source]

Bases: jina.drivers.predict.OneHotPredictDriver

Mapping prediction to a list of labels

Expect prediction to be 2dim array, zero-one valued. Each row corresponds to a sample, each column corresponds to a label. Each row can have only multiple 1s.

This is often used with multi-label classifier, where each instance can have multiple labels

prediction2label(prediction)[source]

Transform the prediction into labels.

Parameters

prediction (ndarray) – the array of predictions

Return type

List[List[str]]

Returns

nested list of labels

runtime: Optional[ZEDRuntime]
class jina.drivers.predict.Prediction2DocBlobDriver(executor=None, method='predict', fields='embedding', *args, **kwargs)[source]

Bases: jina.drivers.predict.BasePredictDriver

Write the prediction result directly into document.blob.

Warning

This will erase the content in document.text and document.buffer.

runtime: Optional[ZEDRuntime]