DASR:数据增强方式用于序列推荐

728 阅读2分钟

一、显式数据增强方式

image.png

(1)随机mask[1]

给定一段序列[1,2,3,8,9],经过随机mask操作之后可能变为[1,2,0,8,9]。其目标是使用指定的替换数据对原始序列中的一部分数据进行掩盖,这种方法可能会破坏原始序列中item与item之间的潜在关系,但与同时也有可能去掉一部分噪音。

class Mask(object):
    """Randomly mask k items given a sequence"""
    def __init__(self, gamma=0.7):
        self.gamma = gamma

    def __call__(self, sequence):
        # make a deep copy to avoid original sequence be modified
        copied_sequence = copy.deepcopy(sequence)
        mask_nums = int(self.gamma*len(copied_sequence))
        mask = [0 for i in range(mask_nums)]
        mask_idx = random.sample([i for i in range(len(copied_sequence))], k = mask_nums)
        for idx, mask_value in zip(mask_idx, mask):
            copied_sequence[idx] = mask_value
        return copied_sequence

(2)随机crop[1]

给定一段序列[1,2,3,8,9],经过随机剪切之后,可能变为[1,8,9]。其目标是将原始序列中的一部分数据去除掉。

class Crop(object):
    """Randomly crop a subseq from the original sequence"""
    def __init__(self, tao=0.2):
        self.tao = tao

    def __call__(self, sequence):
        # make a deep copy to avoid original sequence be modified
        copied_sequence = copy.deepcopy(sequence)
        sub_seq_length = int(self.tao*len(copied_sequence))
        #randint generate int x in range: a <= x <= b
        start_index = random.randint(0, len(copied_sequence)-sub_seq_length-1)
        if sub_seq_length<1:
            return [copied_sequence[start_index]]
        else:
            cropped_seq = copied_sequence[start_index:start_index+sub_seq_length]
            return cropped_seq

(3)随机reorder[1]

给定一段序列[1,2,3,8,9],经过随机打乱顺序之后,可能变为[1,3,6,2,9]。其目标是将原始序列中的一部分元素的数据的顺序打乱。

class Reorder(object):
    """Randomly shuffle a continuous sub-sequence"""
    def __init__(self, beta=0.2):
        self.beta = beta

    def __call__(self, sequence):
        # make a deep copy to avoid original sequence be modified
        copied_sequence = copy.deepcopy(sequence)
        sub_seq_length = int(self.beta*len(copied_sequence))
        start_index = random.randint(0, len(copied_sequence)-sub_seq_length-1)
        sub_seq = copied_sequence[start_index:start_index+sub_seq_length]
        random.shuffle(sub_seq)
        reordered_seq = copied_sequence[:start_index] + sub_seq + \
                        copied_sequence[start_index+sub_seq_length:]
        assert len(copied_sequence) == len(reordered_seq)
        return reordered_seq

(4)随机substitute[2]

给定一段序列[1,2,3,8,9],该方法是比较新颖的方法,经过随机替换之后原始序列可能变为[1,2,5,7,9],就是将原始序列中的部分item替换为与其相似的item。

(5)随机insert[2]

给定一段序列[1,2,3,8,9],该方法是比较新颖的方法,经过随机insert之后原始序列可能变为[1,5,2,3,7,8,9],就是在原始序列中的部分位置插入与相邻item相似的item。

二、隐式数据增强方式

(1)dropout

给定一个embedding矩阵,将其中的部分原始直接用0替换掉,比如给定一个二维矩阵[[1.,2.,3.],[2.,3.,4.]],经过droupout之后可能变为[[0.,2.,3.],[2.,0.,4.]]。原始序列经过embedding之后所获得的是一个特征矩阵,因此对该矩阵进行dropout,可以理解为对特征进行mask操作。

参考资料

[1] Xie X , Sun F , Liu Z , et al. Contrastive Learning for Sequential Recommendation[J]. 2020.

[2] Liu Z , Chen Y , Li J , et al. Contrastive Self-supervised Sequential Recommendation with Robust Augmentation[J]. 2021.