microsoft / ProphetNet

A research project for natural language generation, containing the official implementations by MSRA NLC team.
MIT License
651 stars 104 forks source link

Train model for Vietnamese summarization #36

Open ghost opened 3 years ago

ghost commented 3 years ago

I am using ProphetNet to train a model for Vietnamese summarization. My train script is below !fairseq-train \ --fp16 \ --user-dir $USER_DIR --task translation_prophetnet --arch $ARCH \ --encoder-layers 12 --decoder-layers 12 \ --encoder-embed-dim 768 --decoder-embed-dim 768 \ --optimizer adam --adam-betas '(0.9, 0.999)' --clip-norm 0.1 \ --lr 0.0001 \ --lr-scheduler inverse_sqrt --warmup-init-lr 1e-07 --warmup-updates 1000 \ --dropout 0.1 --attention-dropout 0.1 --weight-decay 0.01 \ --criterion $CRITERION --label-smoothing 0.1 \ --update-freq 32 --max-sentences 2 \ --num-workers 4 \ --load-sep \ --ddp-backend=no_c10d --max-epoch 1 \ --max-source-positions 512 --max-target-positions 512 \ --skip-invalid-size-inputs-valid-test \ --seed 1 \ --save-dir $MODELS/vnexpress \ $DATA_DIR

But when I start inference using to the model, its show error Namespace(beam=10, bpe=None, cpu=False, criterion='cross_entropy', data='/content/ProphetNet/src/finetune_data/VnExpress_processed', dataset_impl=None, decoding_format=None, diverse_beam_groups=-1, diverse_beam_strength=0.5, empty_cache_freq=0, force_anneal=None, fp16=False, fp16_init_scale=128, fp16_scale_tolerance=0.0, fp16_scale_window=None, gen_subset='test', iter_decode_eos_penalty=0.0, iter_decode_force_max_iter=False, iter_decode_max_iter=10, lazy_load=False, left_pad_source='True', left_pad_target='False', lenpen=1.2, load_alignments=False, log_format=None, log_interval=1000, lr_scheduler='fixed', lr_shrink=0.1, match_source_len=False, max_len_a=0, max_len_b=110, max_sentences=32, max_source_positions=1024, max_target_positions=1024, max_tokens=None, memory_efficient_fp16=False, min_len=45.0, min_loss_scale=0.0001, model_overrides='{}', momentum=0.99, nbest=1, no_beamable_mm=False, no_early_stop=False, no_progress_bar=False, no_repeat_ngram_size=3, num_shards=1, num_workers=4, optimizer='nag', path='/content/drive/MyDrive/NLP2021/Models/vnexpress/checkpoint1.pt', prefix_size=0, print_alignment=False, print_step=False, quiet=False, raw_text=False, remove_bpe=None, replace_unk=None, required_batch_size_multiple=8, results_path=None, retain_iter_history=False, sacrebleu=False, sampling=False, sampling_topk=-1, sampling_topp=-1.0, score_reference=False, seed=1, shard_id=0, skip_invalid_size_inputs_valid_test=False, source_lang=None, target_lang=None, task='translation_prophetnet', temperature=1.0, tensorboard_logdir='', threshold_loss_scale=None, tokenizer=None, truncate_source=False, unkpen=0, unnormalized=False, upsample_primary=1, user_dir='/content/ProphetNet/src/prophetnet', warmup_updates=0, weight_decay=0.0) | [src] dictionary: 27671 types | [tgt] dictionary: 27671 types | loaded 4649 examples from: /content/ProphetNet/src/finetune_data/VnExpress_processed/test.src-tgt.src | loaded 4649 examples from: /content/ProphetNet/src/finetune_data/VnExpress_processed/test.src-tgt.tgt | /content/ProphetNet/src/finetune_data/VnExpress_processed test src-tgt 4649 examples | loading model(s) from /content/drive/MyDrive/NLP2021/Models/vnexpress/checkpoint1.pt tcmalloc: large alloc 1080451072 bytes == 0x251ec000 @ 0x7f20158f2b6b 0x7f2015912379 0x7f1fb843a2ea 0x7f1fb843bd9a 0x7f1fbaa9fdb3 0x7f2003c6dc20 0x551555 0x5a9dac 0x50a433 0x50beb4 0x507be4 0x508ec2 0x5a4c61 0x5a4fb8 0x4e012e 0x50a461 0x50beb4 0x507be4 0x588e5c 0x59fd0e 0x50d256 0x507be4 0x509900 0x50a2fd 0x50cc96 0x507be4 0x509900 0x50a2fd 0x50beb4 0x507be4 0x509900 0% 0/146 [00:00<?, ?it/s]Traceback (most recent call last): File "/usr/local/bin/fairseq-generate", line 8, in <module> sys.exit(cli_main()) File "/usr/local/lib/python3.6/dist-packages/fairseq_cli/generate.py", line 199, in cli_main main(args) File "/usr/local/lib/python3.6/dist-packages/fairseq_cli/generate.py", line 104, in main hypos = task.inference_step(generator, models, sample, prefix_tokens) File "/usr/local/lib/python3.6/dist-packages/fairseq/tasks/fairseq_task.py", line 265, in inference_step return generator.generate(models, sample, prefix_tokens=prefix_tokens) File "/usr/local/lib/python3.6/dist-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad return func(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/fairseq/sequence_generator.py", line 113, in generate return self._generate(model, sample, **kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad return func(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/fairseq/sequence_generator.py", line 295, in _generate tokens[:, :step + 1], encoder_outs, temperature=self.temperature, File "/usr/local/lib/python3.6/dist-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad return func(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/fairseq/sequence_generator.py", line 553, in forward_decoder temperature=temperature, File "/usr/local/lib/python3.6/dist-packages/fairseq/sequence_generator.py", line 584, in _decode_one tokens, encoder_out=encoder_out, incremental_state=self.incremental_states[model], File "/usr/local/lib/python3.6/dist-packages/fairseq/models/fairseq_model.py", line 228, in forward_decoder return self.decoder(prev_output_tokens, **kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 541, in __call__ result = self.forward(*input, **kwargs) File "/content/ProphetNet/src/prophetnet/ngram_s2s_model.py", line 615, in forward x_list, extra = self.extract_features(prev_output_tokens, encoder_out, incremental_state, **unused) File "/content/ProphetNet/src/prophetnet/ngram_s2s_model.py", line 776, in extract_features real_positions=real_positions File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 541, in __call__ result = self.forward(*input, **kwargs) File "/content/ProphetNet/src/prophetnet/ngram_s2s_model.py", line 390, in forward real_positions=real_positions File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 541, in __call__ result = self.forward(*input, **kwargs) File "/content/ProphetNet/src/prophetnet/ngram_multihead_attention.py", line 339, in forward predict_relative_logits = self.ngram_relative_logits(h_ngram, attn_weights_ngram, real_positions, i_bucket_relative_stream) File "/content/ProphetNet/src/prophetnet/ngram_multihead_attention.py", line 190, in ngram_relative_logits assert real_positions[0][0] == S - 1, 'memory position is 1 2 3 4 5(S-1)' AssertionError: memory position is 1 2 3 4 5(S-1)

By the way, I format my data using PhoBERT. Here is a sample of my input data

tối 26/3 , thành_@@ ủ@@ y đà_@@ n@@ ẵng gửi công_văn yêu_cầu các cấp_@@ ủ@@ y_@@ đảng , chính_quyền tập_trung cao_độ phòng_chống dịch_bệnh co@@ vid@@ -@@ 19 , không để dịch_bệnh bùng_phát trên địa_bàn . [SEP] nhận_định co@@ vid@@ -@@ 19 tiếp_tục lây_lan nhanh hơn trong cả nước , thường_trực thành_@@ ủ@@ y nêu rõ khi dịch được kiểm_soát và không còn nguy_cơ lây_nhiễm , đại_hội đảng_bộ cấp cơ_sở sẽ diễn ra , nhưng quy_mô nhỏ , giảm thủ_tục , giảm lượng khách_@@ mời và không mời học_sinh đến chào_mừng đại_hội . [SEP] lãnh_đạo thành_phố được giao khuyến_cáo người dân hạn_chế tiếp_xúc , ít di_chuyển . [SEP] cùng_với việc dừng tất_cả hoạt_động hội_họp và sự_kiện tập_trung trên 20 người theo chỉ_đạo của thủ_tướng , đà_@@ n@@ ẵng cấm tụ_tập nhiều hơn 10 người ở bên ngoài các công_sở , trường_học , bệnh_viện . [SEP] thường_trực thành_@@ ủ@@ y yêu_cầu đóng_cửa toàn_bộ cơ_sở dịch_vụ , trừ cung_cấp lương_thực , thực_phẩm , dược_phẩm , khám chữa bệnh ; tạm dừng hoặc tổ_chức hạn_chế hoạt_động giao_thông công_cộng ; cho trẻ mầm_non , học_sinh , sinh_viên , học_viên tiếp_tục nghỉ học đến hết ngày 12/4 , theo đề_nghị của ban cán_sự đảng_@@ ub@@ nd thành_phố . [SEP] chánh_@@ văn_phòng thành_@@ ủ@@ y trầ@@ n_th@@ ắ@@ ng_lợi cho biết , ngành chức_năng sẽ xử_lý những người không khai_báo y_tế , không cách_ly và áp_dụng các biện_pháp phòng_chống dịch theo quy_định ; thông_tin sai sự_thật gây hoang_mang dư_luận . [SEP] tại quảng_@@ nam , nhằm ngăn_chặn n@@ co@@ v và đảm_bảo sức_@@ kh@@ ỏ@@ e cộng_đồng , t@@ p hội_@@ an đề_nghị chủ các quán , hàng ăn_uống , giải_khát , tiệm cà_phê có biện_pháp thích_hợp nhằm hạn_chế việc tập_trung đông người . [SEP] chính_quyền hội_@@ an yêu_cầu những nơi này giãn cách lượt người phục_vụ để đảm_bảo không quá 30 người cho một lượt . [SEP] cơ_sở kinh_doanh thực_hiện nghiêm_túc các biện_pháp y_tế để phòng_chống dịch_bệnh . " [SEP] những trường_hợp không chấp_hành thì đề_nghị có biện_@@ pháp_@@ đình_chỉ , đóng_cửa cơ_sở kinh_doanh " , văn_bản của thành_phố ngày 26/3 nêu rõ . [SEP] đến tối 26/3 , việt_@@ nam ghi_nhận 153 ca dương_tính với n@@ co@@ v , trong đó 20 người đã khỏi .

@yuyan2do

HqWu-HITCS commented 3 years ago

hi, I am meeting the same error when inference, do you have solved the problem? Could you give me some advice on the problem?

HqWu-HITCS commented 3 years ago

@qiweizhen Thank you for your great job! Could you give us some advice on the problem?

dayihengliu commented 3 years ago

The default self.padding_idx is 0, but the self.paddingidx in your model may be another value. You can modify `positions = input.data.new(1, 1).fill(int(self.paddingidx + input.size(1)))topositions = input.data.new(1, 1).fill(int( input.size(1)))` at https://github.com/microsoft/ProphetNet/blob/master/ProphetNet_En/prophetnet/learned_positional_embedding.py#L33 @HqWu-HITCS @RichardYuen