def create_reader_input(pad_token_id: int,
                        samples: List[ReaderSample],
                        passages_per_question: int,
                        max_length: int,
                        max_n_answers: int,
                        is_train: bool,
                        shuffle: bool,
                        ) -> ReaderBatch:
    """
    Creates a reader batch instance out of a list of ReaderSample-s
    :param pad_token_id: id of the padding token
    :param samples: list of samples to create the batch for
    :param passages_per_question: amount of passages for every question in a batch
    :param max_length: max model input sequence length
    :param max_n_answers: max num of answers per single question
    :param is_train: if the samples are for a train set
    :param shuffle: should passages selection be randomized
    :return: ReaderBatch instance
    """
    input_ids = []
    start_positions = []
    end_positions = []
    answers_masks = []
    empty_sequence = torch.Tensor().new_full((max_length,), pad_token_id, dtype=torch.long)

    for sample in samples:
        positive_ctxs = sample.positive_passages
        negative_ctxs = sample.negative_passages if is_train else sample.passages

        sample_tensors = _create_question_passages_tensors(positive_ctxs,
                                                           negative_ctxs,
                                                           passages_per_question,
                                                           empty_sequence,
                                                           max_n_answers,
                                                           pad_token_id,
                                                           is_train,
                                                           is_random=shuffle)
        if not sample_tensors:
            logger.warning('No valid passages combination for question=%s ', sample.question)
            continue
        sample_input_ids, starts_tensor, ends_tensor, answer_mask = sample_tensors
        input_ids.append(sample_input_ids)
        if is_train:
            start_positions.append(starts_tensor)
            end_positions.append(ends_tensor)
            answers_masks.append(answer_mask)
    input_ids = torch.cat([ids.unsqueeze(0) for ids in input_ids], dim=0)

    if is_train:
        start_positions = torch.stack(start_positions, dim=0)
        end_positions = torch.stack(end_positions, dim=0)
        answers_masks = torch.stack(answers_masks, dim=0)

    return ReaderBatch(input_ids, start_positions, end_positions, answers_masks)

    Creates a reader batch instance out of a list of ReaderSample-s
    :param pad_token_id: id of the padding token
    :param samples: list of samples to create the batch for
    :param passages_per_question: amount of passages for every question in a batch
    :param max_length: max model input sequence length
    :param max_n_answers: max num of answers per single question
    :param is_train: if the samples are for a train set
    :param shuffle: should passages selection be randomized
    :return: ReaderBatch instance
    
se2/DPR/dpr/models/reader.py