jina.drivers.predict¶

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

Bases: jina.drivers.BaseExecutableDriver

Drivers inherited from this Driver will bind predict() by default

Initialize a BaseExecutableDriver

Parameters
  • executor (Optional[str]) – the name of the sub-executor, only necessary when jina.executors.compound.CompoundExecutor is used

  • method (str) – the function name of the executor that the driver feeds to

class jina.drivers.predict.BaseLabelPredictDriver(output_tag='prediction', *args, **kwargs)[source]¶

Bases: jina.drivers.predict.BasePredictDriver

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

  • args –

  • kwargs –

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.

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 –

  • kwargs –

prediction2label(prediction)[source]¶
Parameters

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

Return type

List[str]

Returns

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.

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

  • args –

  • kwargs –

validate_labels(prediction)[source]¶
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

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

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

  • args –

  • kwargs –

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[List[str]]

Returns

class jina.drivers.predict.Prediction2DocBlobDriver(executor=None, method='predict', *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.

Initialize a BaseExecutableDriver

Parameters
  • executor (Optional[str]) – the name of the sub-executor, only necessary when jina.executors.compound.CompoundExecutor is used

  • method (str) – the function name of the executor that the driver feeds to