【发布时间】:2022-03-08 07:05:52
【问题描述】:
使用以下函数定义创建模型
def create_model(max_length = 256):
bert_model = TFBertModel.from_pretrained('bert-base-uncased')
for layer in bert_model.layers:
layer.trainable = False
input_ids = tf.keras.Input(shape = (max_length, ), dtype = tf.int32, name = 'input_ids')
attention_masks = tf.keras.Input(shape = (max_length, ), dtype = tf.int32, name = 'attention_masks')
x = bert_model.bert([input_ids, attention_masks])
x = x.pooler_output
x = tf.keras.layers.Dropout(0.2)(x)
x = tf.keras.layers.Dense(256, activation = 'relu')(x)
x = tf.keras.layers.Dropout(0.2)(x)
x = tf.keras.layers.Dense(33)(x)
out = tf.keras.layers.Activation('sigmoid')(x)
model = tf.keras.Model(inputs = [input_ids, attention_masks], outputs = out)
model.compile(optimizer = tf.keras.optimizers.Adam(learning_rate=3e-5),
loss = tf.keras.losses.BinaryCrossentropy(),
metrics = tf.metrics.BinaryAccuracy())
return model
在尝试使用 tf.keras.models.save_model 保存模型时,我遇到了以下错误:IndexError: Exception encountered when calling layer 'bert' (type TFBertMainLayer). list index out of range
【问题讨论】:
-
title 应该是'list index out of range...'????
标签: tensorflow huggingface-transformers