Skip to content

Commit

Permalink
Update basic_extract_features.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bojone authored Oct 22, 2019
1 parent 85f9dd1 commit 46ba40f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/basic_extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from bert4keras.bert import load_pretrained_model
from bert4keras.utils import SimpleTokenizer, load_vocab
from keras.models import load_model
import numpy as np


Expand All @@ -16,6 +17,8 @@

# 编码测试
token_ids, segment_ids = tokenizer.encode(u'语言模型')

print('\n ===== predicting =====\n')
print(model.predict([np.array([token_ids]), np.array([segment_ids])]))

"""
Expand All @@ -33,3 +36,9 @@
[-0.8741375 -0.21650358 1.338839 ... 0.5816864 -0.4373226
0.56181806]]]
"""

print('\n ===== reloading and predicting =====\n')
model.save('test.model')
del model
model = load_model('test.model')
print(model.predict([np.array([token_ids]), np.array([segment_ids])]))

0 comments on commit 46ba40f

Please sign in to comment.