import torch


def get_dropout_mask(dropout_probability: float, tensor_for_masking: torch.Tensor,num_layer :int =1 ):
    """
    Computes and returns an element-wise dropout mask for a given tensor, where
    each element in the mask is dropped out with probability dropout_probability.
    Note that the mask is NOT applied to the tensor - the tensor is passed to retain
    the correct CUDA tensor type for the mask.
    Parameters
    ----------
    dropout_probability : float, required.
        Probability of dropping a dimension of the input.
    tensor_for_masking : torch.Tensor, required.
    Returns
    -------
    A torch.FloatTensor consisting of the binary mask scaled by 1/ (1 - dropout_probability).
    This scaling ensures expected values and variances of the output of applying this mask
     and the original tensor are the same.
    """
    dropout_mask_list = []

    for i in range(num_layer):
        tmp_dropmasks = []
        for j in range(2):
            binary_mask = tensor_for_masking.new_tensor(torch.rand(tensor_for_masking.size()) > dropout_probability)
            # Scale mask by 1/keep_prob to preserve output statistics.
            dropout_mask = binary_mask.float().div(1.0 - dropout_probability)
            tmp_dropmasks.append(dropout_mask)
        dropout_mask_list.append(tmp_dropmasks)
    return dropout_mask_list