Open konL opened 3 years ago
keras的输入,要不然是一个Input层,要不然是Input层组成的list
请问你是否肉眼观察过[mlp.input, cnn.input]
是一个什么东西?
mlp.input是input层吧,但是cnn.input是一个tensor的list [<tf.Tensor 'Input-Token:0' shape=(None, None) dtype=float32>, <tf.Tensor 'Input-Segment:0' shape=(None, None) dtype=float32>]
我的做法:修改zip_data()、data_generator、和模型结构(从keras.layers导入Input和Concatenate)
训练代码无需修改,用这种方式我跑通了。刚学的keras,应该还有更好的方法。
@Chrisma-98 同样遇到这个问题想请问一下
model = build_transformer_model(config_path, checkpoint_path, model='albert') category = Input(shape=(1,), name='feature_input') categoryEmbedding = Embedding(1, 312)(category) categoryEmbedding = Flatten()(categoryEmbedding) // 特征拼接 input = model.input input.append(category)
output = concatenate([model.output, model.input[2]]) output = GlobalPointer(len(categories), 64)(output)
model = Model(input, output) model.summary()
如果使用bert.output作为输出的情况下,这种(None,None,dims)和(None,dim)的拼接要怎么处理呢,直接拼接会报维度不一致的问题。
提问时请尽可能提供如下信息:
基本信息
核心代码
输出信息
自我尝试
【目的】在Bert场景中在编码之后,引入特征(如KG信息,或者人工设计领域特征),与Bert编码向量融合后再用于预测任务。 【思路】
模型输入
class data_generator(DataGenerator): """ 数据生成器 """ def iter(self, random=False): batch_token_ids, batch_segment_ids, batch_labels = [], [], [] for is_end, (text,text1, label) in self.sample(random):
token_ids, segment_ids = tokenizer.encode(text,text1, maxlen=maxlen) batch_token_ids.append(token_ids) batch_segment_ids.append(segment_ids) batch_labels.append([label]) if len(batch_token_ids) == self.batch_size or is_end: batch_token_ids = sequence_padding(batch_token_ids) batch_segment_ids = sequence_padding(batch_segment_ids) batch_labels = sequence_padding(batch_labels) yield [batch_token_ids, batch_segment_ids], batch_labels batch_token_ids, batch_segment_ids, batch_labels = [], [], []
mlp = models.create_mlp(....) cnn = models.create_cnn(.......) combinedInput = concatenate([mlp.output, cnn.output]) x = Dense(4, activation="relu")(combinedInput) x = Dense(1, activation="linear")(x) model = Model(inputs=[mlp.input, cnn.input], outputs=x)