Source code for pyrelational.strategies.task_agnostic.random_acquisition_strategy

"""Defines and implements a random acquisition active learning strategy."""

from typing import List

import numpy as np

from pyrelational.data_managers import DataManager
from pyrelational.strategies.abstract_strategy import Strategy


[docs] class RandomAcquisitionStrategy(Strategy): """Implements RandomAcquisition whereby random samples from unlabelled set are chosen at each step.""" def __init__(self) -> None: """Override init method to do nothing. This strategy does not require any initialization.""" pass
[docs] def __call__(self, num_annotate: int, data_manager: DataManager) -> List[int]: """ Identify samples for labelling based on random sampling. :param num_annotate: number of samples to annotate :param data_manager: A pyrelational data manager which keeps track of what has been labelled and creates data loaders for active learning :return: list of indices to annotate """ num_annotate = min(num_annotate, len(data_manager.u_indices)) ret: List[int] = np.random.choice(data_manager.u_indices, size=num_annotate, replace=False).tolist() return ret