GithubHelp home page GithubHelp logo

Comments (3)

XiaoLongtaoo avatar XiaoLongtaoo commented on May 29, 2024 1

上面的问题我发现是由于你们Config的设置上似乎出现了点问题,这里的config = Config(model=DuoRec, dataset=dataset, config_file_list=config_file_list) DuoRec不能以model_name='DuoRec'的参数形式传进去,否则将会报错,对于自定义的模型不能通过传model=model_name来调用,只能直接以model=Customize model name这个形式调用。但是这里出现了另一个问题,请问这里的sem_aug是哪里出现的呢,我看DuoRec的source code,发现他们的实现似乎除了模型以及配置文件外,其余都与recbole的默认文件保持一致。如果我哪里出现了错误,劳烦指正我一下,谢谢!O(∩_∩)O

Traceback (most recent call last):
  File "/home/xiaolongtao/UniSRec/run_baseline.py", line 96, in <module>
    baseline_func(model=args.model, dataset=args.dataset, config_file_list=config_file_list)
  File "/home/xiaolongtao/UniSRec/run_baseline.py", line 64, in run_baseline
    best_valid_score, best_valid_result = trainer.fit(
  File "/home/xiaolongtao/anaconda3/envs/UniSRec/lib/python3.9/site-packages/recbole/trainer/trainer.py", line 439, in fit
    train_loss = self._train_epoch(
  File "/home/xiaolongtao/anaconda3/envs/UniSRec/lib/python3.9/site-packages/recbole/trainer/trainer.py", line 245, in _train_epoch
    losses = loss_func(interaction)
  File "/home/xiaolongtao/UniSRec/baselines/duorec.py", line 190, in calculate_loss
    sem_aug, sem_aug_lengths = interaction['sem_aug'], interaction['sem_aug_lengths']
  File "/home/xiaolongtao/anaconda3/envs/UniSRec/lib/python3.9/site-packages/recbole/data/interaction.py", line 135, in __getitem__
    return self.interaction[index]
KeyError: 'sem_aug'

from recbole.

TayTroye avatar TayTroye commented on May 29, 2024

@XiaoLongtaoo 你好!
这里的sem_augsoure code写在dataloader的duorec_aug用于数据增强的部分

from recbole.

XiaoLongtaoo avatar XiaoLongtaoo commented on May 29, 2024

@XiaoLongtaoo 你好! 这里的sem_augsoure code写在dataloader的duorec_aug用于数据增强的部分

我找到了这个数据增强办法,但是这里仍然存在一个问题,当我将它用在我自己的dataloader中时,代码如下所示:

    def duorec_aug(self, cur_data, index, interaction):
        cur_same_target = self.same_target_index[index]
        null_index = []
        sample_pos = []
        for i, targets in enumerate(cur_same_target):
            # in case there is no same-target sequence
            # don't know why this happens since the filtering has been applied
            if len(targets) == 0:
                sample_pos.append(-1)
                null_index.append(i)
            else:
                sample_pos.append(np.random.choice(targets))
        sem_pos_seqs = self.static_item_id_list[sample_pos] 
        sem_pos_lengths = self.static_item_length[sample_pos]
        if null_index:
            sem_pos_seqs[null_index] = cur_data['item_id_list'][null_index]
            sem_pos_lengths[null_index] = cur_data['item_length'][null_index]
        
        cur_data.update(Interaction({'sem_aug': sem_pos_seqs, 'sem_aug_lengths': sem_pos_lengths}))
        return cur_data

训练时所用的dataloader代码如下:

class CustomizedTrainDataLoader(TrainDataLoader):
    def __init__(self, config, dataset, sampler, shuffle=False):
        super().__init__(config, dataset, sampler, shuffle=shuffle)
        self.transform = construct_transform(config)
        self.model = config['model']
        
        "special parameters for DuoRec"
        if self.model == 'DuoRec':
            self.same_target_index = dataset.same_target_index
            self.static_item_id_list = dataset.static_item_id_list
            self.static_item_length = dataset.static_item_length
            # self.static_item_id_list = self.dataset.inter_feat['item_id_list']
            # self.static_item_length = self.dataset.inter_feat['item_length']
        """"""

    def _next_batch_data(self):
        cur_data = super()._next_batch_data()
        # index = cur_data.index()
        index = slice(self.pr - self.step, self.pr)
    """"""
        if self.model == 'DuoRec':
            cur_data = self.duorec_aug(self, cur_data, index)
            return cur_data
    """"""
        else:    
            transformed_data = self.transform(self, cur_data)
            return transformed_data


    def duorec_aug(self, cur_data, index, interaction):
        cur_same_target = self.same_target_index[index]
        null_index = []
        sample_pos = []
        for i, targets in enumerate(cur_same_target):
            # in case there is no same-target sequence
            # don't know why this happens since the filtering has been applied
            if len(targets) == 0:
                sample_pos.append(-1)
                null_index.append(i)
            else:
                sample_pos.append(np.random.choice(targets))
        sem_pos_seqs = self.static_item_id_list[sample_pos] 
        sem_pos_lengths = self.static_item_length[sample_pos]
        if null_index:
            sem_pos_seqs[null_index] = cur_data['item_id_list'][null_index]
            sem_pos_lengths[null_index] = cur_data['item_length'][null_index]
        
        cur_data.update(Interaction({'sem_aug': sem_pos_seqs, 'sem_aug_lengths': sem_pos_lengths}))
        return cur_data

请问为什么读取训练数据时仍然不会更新,数据中还是没有出现sem_aug, sem_aug_lengths这两个属性,请问这是哪里出现了问题呢?感谢!

from recbole.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.