# Buggy code
def __init__(
    self,
    model,
    processor,
    batch_size=4,
    gpu=False,
    name=None,
    return_class_probs=False,
    multiprocessing_chunk_size=100,
):
    """
    Initializes Inferencer from an AdaptiveModel and a Processor instance.

    :param model: AdaptiveModel to run in inference mode
    :type model: AdaptiveModel
    :param processor: A dataset specific Processor object which will turn input (file or dict) into a Pytorch Dataset.
    :type processor: Processor
    :param batch_size: Number of samples computed once per batch
    :type batch_size: int
    :param gpu: If GPU shall be used
    :type gpu: bool
    :param name: Name for the current Inferencer model, displayed in the REST API
    :type name: string
    :param return_class_probs: either return probability distribution over all labels or the prob of the associated label
    :type return_class_probs: bool
    :return: An instance of the Inferencer.

    """
    # Init device and distributed settings
    device, n_gpu = initialize_device_settings(use_cuda=gpu, local_rank=-1, fp16=False)

    self.processor = processor
    self.model = model
    self.model.eval()
    self.batch_size = batch_size
    self.device = device
    self.language = self.model.language_model.language
    # TODO adjust for multiple prediction heads
    if len(self.model.prediction_heads) == 1:
        self.prediction_type = self.model.prediction_heads[0].model_type
        # self.label_map = self.processor.label_maps[0]
    elif len(self.model.prediction_heads) == 0:
        self.prediction_type = "embedder"
    # else:
    #     raise NotImplementedError("A model with multiple prediction heads is currently not supported by the Inferencer")
    self.name = name if name != None else f"anonymous-{self.prediction_type}"
    self.return_class_probs = return_class_probs
    self.multiprocessing_chunk_size = multiprocessing_chunk_size

    model.connect_heads_with_processor(processor.tasks, require_labels=False)
    set_all_seeds(42, n_gpu)


# Traceback (AssertionError)
10/11/2019 17:12:47 - INFO - farm.data_handler.data_silo -   Loading dev set as a slice of train set
Traceback (most recent call last):
File ".../train.py", line 436, in <module>
augmentation=True)
File ".../train.py", line 348, in continue_finetuning
data_silo = DataSilo(processor=processor, batch_size=batch_size, multiprocessing_chunk_size=2000)
File "/.../farm/data_handler/data_silo.py", line 49, in __init__
self._load_data()
File ".../farm/data_handler/data_silo.py", line 104, in _load_data
self._create_dev_from_train()
File ".../farm/data_handler/data_silo.py", line 175, in _create_dev_from_train
train_dataset, dev_dataset = self.random_split_ConcatDataset(self.data["train"], lengths=[n_train, n_dev])
File ".../farm/data_handler/data_silo.py", line 200, in random_split_ConcatDataset
train = ConcatDataset(ds.datasets[:idx_dataset])
File ".../torch/utils/data/dataset.py", line 68, in __init__
assert len(datasets) > 0, 'datasets should not be an empty iterable'
AssertionError: datasets should not be an empty iterable

# Fixed code
def __init__(
    self, model, processor, batch_size=4, gpu=False, name=None, return_class_probs=False
):
    """
    Initializes Inferencer from an AdaptiveModel and a Processor instance.

    :param model: AdaptiveModel to run in inference mode
    :type model: AdaptiveModel
    :param processor: A dataset specific Processor object which will turn input (file or dict) into a Pytorch Dataset.
    :type processor: Processor
    :param batch_size: Number of samples computed once per batch
    :type batch_size: int
    :param gpu: If GPU shall be used
    :type gpu: bool
    :param name: Name for the current Inferencer model, displayed in the REST API
    :type name: string
    :param return_class_probs: either return probability distribution over all labels or the prob of the associated label
    :type return_class_probs: bool
    :return: An instance of the Inferencer.

    """
    # Init device and distributed settings
    device, n_gpu = initialize_device_settings(use_cuda=gpu, local_rank=-1, fp16=False)

    self.processor = processor
    self.model = model
    self.model.eval()
    self.batch_size = batch_size
    self.device = device
    self.language = self.model.language_model.language
    # TODO adjust for multiple prediction heads
    if len(self.model.prediction_heads) == 1:
        self.prediction_type = self.model.prediction_heads[0].model_type
        # self.label_map = self.processor.label_maps[0]
    elif len(self.model.prediction_heads) == 0:
        self.prediction_type = "embedder"
    # else:
    #     raise NotImplementedError("A model with multiple prediction heads is currently not supported by the Inferencer")
    self.name = name if name != None else f"anonymous-{self.prediction_type}"
    self.return_class_probs = return_class_probs

    model.connect_heads_with_processor(processor.tasks, require_labels=False)
    set_all_seeds(42, n_gpu)