

The default value is the same with `training` output_layer_num = 4, # The number of layers whose outputs will be concatenated as a single output.
Xtractor toy generator#
fit_generator ( generator = _generator (), steps_per_epoch = 1000, epochs = 100, validation_data = _generator (), validation_steps = 100, callbacks =, ) # Use the trained model inputs, output_layer = get_model ( token_num = len ( token_dict ), head_num = 5, transformer_num = 12, embed_dim = 25, feed_forward_dim = 100, seq_len = 20, pos_num = 20, dropout_rate = 0.05, training = False, # The input layers and output layer will be returned if `training` is `False` trainable = False, # Whether the model is trainable. summary () def _generator (): while True : yield gen_batch_inputs ( sentence_pairs, token_dict, token_list, seq_len = 20, mask_rate = 0.3, swap_sentence_rate = 1.0, ) model. keys ()) # Used for selecting a random word # Build & train the model model = get_model ( token_num = len ( token_dict ), head_num = 5, transformer_num = 12, embed_dim = 25, feed_forward_dim = 100, seq_len = 20, pos_num = 20, dropout_rate = 0.05, ) compile_model ( model ) model. encode ( first = 'unaffable', second = '钢', max_len = 10 ) print ( indices ) # Should be `` print ( segments ) # Should be `` Train & Use from tensorflow import keras from keras_bert import get_base_dict, get_model, compile_model, gen_batch_inputs # A toy input example sentence_pairs =, ],, ],, ], ] # Build token dictionary token_dict = get_base_dict () # A dict that contains some special tokens for pairs in sentence_pairs : for token in pairs + pairs : if token not in token_dict : token_dict = len ( token_dict ) token_list = list ( token_dict. tokenize ( first = 'unaffable', second = '钢' )) # The result should be `', 'un', '#aff', '#able', '', '钢', '']` indices, segments = tokenizer. encode ( 'unaffable' ) print ( indices ) # Should be `` print ( segments ) # Should be `` print ( tokenizer. tokenize ( 'unaffable' )) # The result should be `', 'un', '#aff', '#able', '']` indices, segments = tokenizer. The Tokenizer class is used for splitting texts and generating indices: from keras_bert import Tokenizer token_dict = tokenizer = Tokenizer ( token_dict ) print ( tokenizer.
Xtractor toy how to#
The classification demo shows how to apply the model to simple classification tasks.

The extraction demo shows how to convert to a model that runs on TPU. And in prediction demo, the missing word in the sentence could be predicted. In feature extraction demo, you should be able to get the same extraction results as the official model chinese_L-12_H-768_A-12.

