instancelib.labels.memory module

class instancelib.labels.memory.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