Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model.save:TypeError: Object of type module is not JSON serializable #461

Open
asd8095075 opened this issue Mar 5, 2021 · 8 comments
Open

Comments

@asd8095075
Copy link

from kashgari.corpus import ChineseDailyNerCorpus
from kashgari.embeddings import BertEmbedding
from kashgari.tasks.labeling import BiLSTM_CRF_Modelb
import kashgari

X_train, y_train = ChineseDailyNerCorpus.load_data('train')
x_test, y_test = ChineseDailyNerCorpus.load_data('test')
X_valid, y_valid = ChineseDailyNerCorpus.load_data('valid')

bert_embed = BertEmbedding('./bert/chinese_roberta_wwm_ext_L-12_H-768_A-12',
task=kashgari.tasks.labeling,
sequence_length=100)

model = BiLSTM_CRF_Model(bert_embed)
model.fit(X_train, y_train, X_valid, y_valid, epochs=1,batch_size=512)

@asd8095075
Copy link
Author

Version being used: kashgari2.0.0
Operating system: windows 10
Version of Python: 3.7.2
Errors in console: TypeError: Object of type module is not JSON serializable
Detailed description of the problem: use chinese_roberta_wwm_ext_L-12_H-768_A-12,save model fail

@Cliccker
Copy link

I've met the same problem while training a labeling model.
Did you find any solution?

@asd8095075
Copy link
Author

The problem remains unsolved

@cccccrj
Copy link

cccccrj commented Oct 10, 2021

also encountered this problem.

@HuizhiXu
Copy link

got this problem too

@HuizhiXu
Copy link

I tried to find why this happened.

I have located the problem, it’s in this file “lib/python3.6/site-packages/kashgari/tasks/abs_task_model.py”
in function save , line 84, f.write(json.dumps(self.to_dict(), indent=2, ensure_ascii=False)).

The structure of “module” might have wrong type, not JSON, so it cannot be serializied.

Also noticed that Keras has the same issue. keras-team/keras#9342
I’ve changed the source file of Keras, but nothing has changed.

my Setup:
tf 2.2.0
Ubuntu 20.04
kashgari 2.0.2
keras 2.3.1
cuda toolkit 10.1
cuDNN 7.6

@stale
Copy link

stale bot commented Nov 2, 2022

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.

@stale stale bot added the wontfix This will not be worked on label Nov 2, 2022
@cjrcjr
Copy link

cjrcjr commented Feb 26, 2024

我把
bert_embed = BertEmbedding('./bert/chinese_roberta_wwm_ext_L-12_H-768_A-12',
task=kashgari.tasks.labeling,
sequence_length=100)
改为
bert_embed = BertEmbedding('./bert/chinese_roberta_wwm_ext_L-12_H-768_A-12')
就能成功保存模型了,反正不传入task就可以保存

@stale stale bot removed the wontfix This will not be worked on label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants