williamSYSU / TextGAN-PyTorch

TextGAN is a PyTorch framework for Generative Adversarial Networks (GANs) based text generation models.
MIT License
878 stars 207 forks source link

AttributeError: 'SeqGANInstructor' object has no attribute 'train_data' #22

Open sydwings opened 4 years ago

sydwings commented 4 years ago

Thanks for your coding.I have some small problems,could you help me? When I use my dataset,it happens. `> training arguments:

if_test: False run_model: seqgan k_label: 2 dataset: comment model_type: vanilla loss_type: rsgan if_real_data: True cuda: True device: 0 shuffle: False gen_init: truncated_normal dis_init: uniform samples_num: 10000 vocab_size: 930 mle_epoch: 150 clas_pre_epoch: 10 adv_epoch: 2000 inter_epoch: 15 batch_size: 64 max_seq_len: 16 start_letter: 1 padding_idx: 0 gen_lr: 0.01 gen_adv_lr: 0.0001 dis_lr: 0.0001 clip_norm: 5.0 pre_log_step: 10 adv_log_step: 20 train_data: dataset/comment.txt test_data: dataset/testdata/comment_test.txt temp_adpt: exp temperature: 1 ora_pretrain: True gen_pretrain: False dis_pretrain: False adv_g_step: 1 rollout_num: 16 gen_embed_dim: 32 gen_hidden_dim: 32 goal_size: 16 step_size: 4 mem_slots: 1 num_heads: 2 head_size: 256 d_step: 5 d_epoch: 3 adv_d_step: 5 adv_d_epoch: 3 dis_embed_dim: 64 dis_hidden_dim: 64 num_rep: 64 use_nll_oracle: True use_nll_gen: True use_nll_div: True use_bleu: True use_self_bleu: True use_clas_acc: True use_ppl: False log_file: log/log_1216_1650_47.txt save_root: save/20191216/comment/seqgan_vanilla_lt-rsgan_sl16_temp1_T1216_1650_47/ signal_file: run_signal.txt tips:

Traceback (most recent call last): File "C:/Users/Administrator/Desktop/TextGAN-PyTorch-master/main.py", line 134, in inst = instruction_dictcfg.run_model File "C:\Users\Administrator\Desktop\TextGAN-PyTorch-master\instructor\real_data\seqgan_instructor.py", line 23, in init super(SeqGANInstructor, self).init(opt) File "C:\Users\Administrator\Desktop\TextGAN-PyTorch-master\instructor\real_data\instructor.py", line 74, in init self.ppl = PPL(self.train_data, self.test_data, n_gram=5, if_use=cfg.use_ppl) AttributeError: 'SeqGANInstructor' object has no attribute 'train_data'`

williamSYSU commented 4 years ago

Do you put the comment.txt file into the dataset directory? The self.train_data needs to load the dataset file you specified in the config.py file (parameter dataset), but it seems there is no file named dataset/comment.txt.

mnavaidd commented 3 years ago

I have received same error, when I changed the dataset. Even I have placed dataset file in dataset folder.

raceback (most recent call last):
  File "main.py", line 167, in <module>
    inst = instruction_dict[cfg.run_model](opt)
  File "TextGAN-PyTorch/instructor/real_data/seqgan_instructor.py", line 23, in __init__
    super(SeqGANInstructor, self).__init__(opt)
  File "TextGAN-PyTorch/instructor/real_data/instructor.py", line 72, in __init__
    self.ppl = PPL(self.train_data, self.test_data, n_gram=5, if_use=cfg.use_ppl)
AttributeError: 'SeqGANInstructor' object has no attribute 'train_data'
viko-3 commented 3 years ago

I have received same error, when I changed the dataset. Even I have placed dataset file in dataset folder.

raceback (most recent call last):
  File "main.py", line 167, in <module>
    inst = instruction_dict[cfg.run_model](opt)
  File "TextGAN-PyTorch/instructor/real_data/seqgan_instructor.py", line 23, in __init__
    super(SeqGANInstructor, self).__init__(opt)
  File "TextGAN-PyTorch/instructor/real_data/instructor.py", line 72, in __init__
    self.ppl = PPL(self.train_data, self.test_data, n_gram=5, if_use=cfg.use_ppl)
AttributeError: 'SeqGANInstructor' object has no attribute 'train_data'

and have you sloved this problem now?I have the same problem

viko-3 commented 3 years ago

I have received same error, when I changed the dataset. Even I have placed dataset file in dataset folder.

raceback (most recent call last):
  File "main.py", line 167, in <module>
    inst = instruction_dict[cfg.run_model](opt)
  File "TextGAN-PyTorch/instructor/real_data/seqgan_instructor.py", line 23, in __init__
    super(SeqGANInstructor, self).__init__(opt)
  File "TextGAN-PyTorch/instructor/real_data/instructor.py", line 72, in __init__
    self.ppl = PPL(self.train_data, self.test_data, n_gram=5, if_use=cfg.use_ppl)
AttributeError: 'SeqGANInstructor' object has no attribute 'train_data'

and have you sloved this problem now?I have the same problem

I solve it ,maybe the dataset has some problem.

HernandezEduin commented 2 years ago

I had the same issue. It turns out to be an issue with my dataset.

To overcome this, I modified the following in utils/text_process.py:

def tokens_to_tensor(tokens, dictionary):
    tensor = []
    for sent in tokens:
        sent_ten = []
        i = - 1
        for i, word in enumerate(sent):
            if word == cfg.padding_token:
                break
            sent_ten.append(int(dictionary[str(word)]))

        sent_ten = sent_ten + (cfg.max_seq_len + 1 - i)*[cfg.padding_idx]

        tensor.append(sent_ten[:cfg.max_seq_len])
    return torch.LongTensor(tensor)

Tensor was a list with list of dynamic size. This ensures all list are of the same size, even if the list is empty.

julfr commented 2 years ago

I had the same issue. It turns out to be an issue with my dataset.

To overcome this, I modified the following in utils/text_process.py:

def tokens_to_tensor(tokens, dictionary):
    tensor = []
    for sent in tokens:
        sent_ten = []
        i = - 1
        for i, word in enumerate(sent):
            if word == cfg.padding_token:
                break
            sent_ten.append(int(dictionary[str(word)]))

        sent_ten = sent_ten + (cfg.max_seq_len + 1 - i)*[cfg.padding_idx]

        tensor.append(sent_ten[:cfg.max_seq_len])
    return torch.LongTensor(tensor)

Tensor was a list with list of dynamic size. This ensures all list are of the same size, even if the list is empty.

Hi, I have the same problem with catgan.py. I modified text_process.py as you suggested, but then another error appears:

File "/home/sc.uni-leipzig.de/ie870xetu/TextGAN-PyTorch/instructor/real_data/catgan_instructor.py", line 63, in __init__
    self.all_train_data = CatGenDataIter(self.train_samples_list)
`AttributeError: 'CatGANInstructor' object has no attribute 'train_samples_list'`

@HernandezEduin

julfr commented 2 years ago

has some problem.

How did you solve your problem?

julfr commented 2 years ago

has some problem.

How did you solve your problem? @Cyy1216

keerthan-381 commented 1 year ago

I am also getting the same error. AttributeError: 'CatGANInstructor' object has no attribute 'train_samples_list' How to resolve it ?