instancelib.labels package

Submodules

Module contents

class instancelib.labels.LabelEncoder(*args, **kwds)[source]

Bases: ABC, Generic[LT, LVT, LMT, PMT]

abstract decode_matrix(matrix)[source]
Parameters:

matrix (TypeVar(LMT)) –

Return type:

Sequence[FrozenSet[TypeVar(LT)]]

abstract decode_proba_matrix(matrix)[source]
Parameters:

matrix (TypeVar(PMT)) –

Return type:

Sequence[FrozenSet[Tuple[TypeVar(LT), float]]]

abstract decode_vector(vector)[source]
Parameters:

vector (TypeVar(LVT)) –

Return type:

FrozenSet[TypeVar(LT)]

abstract encode(labels)[source]
Parameters:

labels (Iterable[TypeVar(LT)]) –

Return type:

TypeVar(LVT)

abstract encode_batch(labelings)[source]
Parameters:

labelings (Iterable[Iterable[TypeVar(LT)]]) –

Return type:

TypeVar(LMT)

encode_safe(labels)[source]
Parameters:

labels (Iterable[TypeVar(LT)]) –

Return type:

Optional[TypeVar(LVT)]

abstract get_label_column_index(label)[source]
Parameters:

label (TypeVar(LT)) –

Return type:

int

abstract initialize(labels)[source]
Parameters:

labels (Iterable[TypeVar(LT)]) –

Return type:

None

abstract property labels: Sequence[LT]
class instancelib.labels.LabelProvider(*args, **kwds)[source]

Bases: Mapping[KT, FrozenSet[LT]], ABC, Generic[KT, LT]

document_count(label)[source]
Parameters:

label (TypeVar(LT)) –

Return type:

int

abstract get_instances_by_label(label)[source]

Retrieve which instances are annotated with label

Parameters:

label (LT) – A Label

Returns:

The identifiers of the instance

Return type:

Set[Instance]

abstract get_labels(instance)[source]

Return the labels that are associated with the instance

Parameters:

instance (Union[KT, Instance]) – The instance

Returns:

The labels that are associated with the instance

Return type:

Set[LT]

abstract property labelset: FrozenSet[LT]

for setting up a classifier)

Returns:

Labels of type LT

Return type:

Set[LT]

Type:

Report all possible labels (example usage

property len_positive: int
abstract remove_labels(instance, *labels)[source]

Remove the labels from this instance

Parameters:
  • instance (Union[KT, Instance]) – The instance

  • *labels (LT) – The labels that should be removed from the instance

Return type:

None

abstract set_labels(instance, *labels)[source]

Annotate the instance with the labels listed in the parameters

Parameters:
  • instance (Union[KT, Instance]) – The instance

  • *labels (LT) – The labels that should be associated with the instance

Return type:

None

class instancelib.labels.MemoryLabelProvider(labelset, labeldict, labeldict_inv=None)[source]

Bases: LabelProvider[KT, LT], Generic[KT, LT]

A Memory based implementation to test and benchmark AL algorithms

Parameters:
document_count(label)[source]
Parameters:

label (TypeVar(LT)) –

Return type:

int

classmethod from_data(labelset, indices, labels)[source]
Parameters:
Return type:

MemoryLabelProvider[TypeVar(KT), TypeVar(LT)]

classmethod from_provider(provider, subset=[])[source]
Parameters:
Return type:

MemoryLabelProvider[TypeVar(KT), TypeVar(LT)]

classmethod from_tuples(predictions)[source]
Parameters:

predictions (Sequence[Tuple[TypeVar(KT), FrozenSet[TypeVar(LT)]]]) –

Return type:

MemoryLabelProvider[TypeVar(KT), TypeVar(LT)]

get_instances_by_label(label)[source]

Retrieve which instances are annotated with label

Parameters:

label (LT) – A Label

Returns:

The identifiers of the instance

Return type:

Set[Instance]

get_labels(instance)[source]

Return the labels that are associated with the instance

Parameters:

instance (Union[KT, Instance]) – The instance

Returns:

The labels that are associated with the instance

Return type:

Set[LT]

property labelset: FrozenSet[LT]

for setting up a classifier)

Returns:

Labels of type LT

Return type:

Set[LT]

Type:

Report all possible labels (example usage

remove_labels(instance, *labels)[source]

Remove the labels from this instance

Parameters:
  • instance (Union[KT, Instance]) – The instance

  • *labels (LT) – The labels that should be removed from the instance

classmethod rename_labels(provider, mapping)[source]
Parameters:
Return type:

MemoryLabelProvider[TypeVar(KT), TypeVar(LT)]

set_labels(instance, *labels)[source]

Annotate the instance with the labels listed in the parameters

Parameters:
  • instance (Union[KT, Instance]) – The instance

  • *labels (LT) – The labels that should be associated with the instance

classmethod translate_keys(provider, mapping)[source]
Parameters:
Return type:

Self