BrikerMan / Kashgari

Kashgari is a production-level NLP Transfer learning framework built on top of tf.keras for text-labeling and text-classification, includes Word2Vec, BERT, and GPT2 Language Embedding.
http://kashgari.readthedocs.io/
Apache License 2.0
2.4k stars 441 forks source link

[BUG] :Gradients do not exist for variables ['k_conditional_random_field/transitions:0'] #478

Closed cccccrj closed 2 years ago

cccccrj commented 3 years ago

You must follow the issue template and provide as much information as possible. otherwise, this issue will be closed. 请按照 issue 模板要求填写信息。如果没有按照 issue 模板填写,将会忽略并关闭这个 issue

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

You can post pictures, but if specific text or code is required to reproduce the issue, please provide the text in a plain text format for easy copy/paste.

Environment

[requirements.txt](https://github.com/BrikerMan/Kashgari/files/7402383/requirements.txt)

Issue Description

2021-10-23 14:35:16,906 [DEBUG] kashgari - ------------------------------------------------ 2021-10-23 14:35:16,906 [DEBUG] kashgari - Loaded transformer model's vocab 2021-10-23 14:35:16,906 [DEBUG] kashgari - config_path : chinese_wwm_ext_L-12_H-768_A-12\bert_config.json 2021-10-23 14:35:16,906 [DEBUG] kashgari - vocab_path : chinese_wwm_ext_L-12_H-768_A-12\vocab.txt 2021-10-23 14:35:16,906 [DEBUG] kashgari - checkpoint_path : chinese_wwm_ext_L-12_H-768_A-12\bert_model.ckpt 2021-10-23 14:35:16,906 [DEBUG] kashgari - Top 50 words : ['[PAD]', '[unused1]', '[unused2]', '[unused3]', '[unused4]', '[unused5]', '[unused6]', '[unused7]', '[unused8]', '[unused9]', '[unused10]', '[unused11]', '[unused12]', '[unused13]', '[unused14]', '[unused15]', '[unused16]', '[unused17]', '[unused18]', '[unused19]', '[unused20]', '[unused21]', '[unused22]', '[unused23]', '[unused24]', '[unused25]', '[unused26]', '[unused27]', '[unused28]', '[unused29]', '[unused30]', '[unused31]', '[unused32]', '[unused33]', '[unused34]', '[unused35]', '[unused36]', '[unused37]', '[unused38]', '[unused39]', '[unused40]', '[unused41]', '[unused42]', '[unused43]', '[unused44]', '[unused45]', '[unused46]', '[unused47]', '[unused48]', '[unused49]'] 2021-10-23 14:35:16,906 [DEBUG] kashgari - ------------------------------------------------ Preparing text vocab dict: 100%|██████████| 500/500 [00:00<00:00, 100012.02it/s] 2021-10-23 14:35:16,914 [DEBUG] kashgari - --- Build vocab dict finished, Total: 1153 --- 2021-10-23 14:35:16,914 [DEBUG] kashgari - Top-10: ['[PAD]', '[UNK]', '[CLS]', '[SEP]', ',', '的', '。', '机', '“', '”'] Preparing text vocab dict: 100%|██████████| 500/500 [00:00<00:00, 125009.06it/s] 2021-10-23 14:35:16,919 [DEBUG] kashgari - --- Build vocab dict finished, Total: 42 --- 2021-10-23 14:35:16,919 [DEBUG] kashgari - Top-10: ['[PAD]', 'O', 'I-飞机', 'I-舰船', 'B-飞机', 'I-航空母舰', 'I-导弹', 'B-舰船', 'I-部队', 'I-城市'] 2021-10-23 14:35:16.934857: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll 2021-10-23 14:35:17.019839: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected 2021-10-23 14:35:17.029292: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-D01NAD5 2021-10-23 14:35:17.029534: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-D01NAD5 2021-10-23 14:35:17.030544: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 2021-10-23 14:35:17.049853: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x19bde303610 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2021-10-23 14:35:17.050005: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version Calculating sequence length: 100%|██████████| 500/500 [00:00<?, ?it/s] 2021-10-23 14:35:25,599 [DEBUG] kashgari - Calculated sequence length = 132 2021-10-23 14:35:27,890 [DEBUG] kashgari - fit input shape: (2, 4, 132) 2021-10-23 14:35:27,890 [DEBUG] kashgari - fit input shape: (4, 132) WARNING:tensorflow:Gradients do not exist for variables ['k_conditional_random_field/transitions:0'] when minimizing the loss. WARNING:tensorflow:Gradients do not exist for variables ['k_conditional_random_field/transitions:0'] when minimizing the loss. WARNING:tensorflow:Gradients do not exist for variables ['k_conditional_random_field/transitions:0'] when minimizing the loss. WARNING:tensorflow:Gradients do not exist for variables ['k_conditional_random_field/transitions:0'] when minimizing the loss.

Reproduce

加入loss和metrics参数就会报错,如下。只有optimizer参数则不会出现此错误。 Thanks! optimizer = tensorflow.keras.optimizers.Adam(lr=5e-5) model.compile_model(optimizer=optimizer, loss='sparse_categorical_crossentropy', metrics=['accuracy'])

Other Comment

类似的问题 https://github.com/tensorflow/tensorflow/issues/37501

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.