我在使用Keras
中的CNN进行一个NLP任务,我尝试使用时间上的最大池化(max over time pooling)来替代最大池化(max pooling)。
有什么方法或技巧可以实现这个目标吗?
我所说的时间上的最大池化是指无论这些值在向量中的位置如何,都要池化最高的值。
回答:
假设你的数据形状是(batch_size, seq_len, features)
,你可以应用以下操作:
seq_model = Reshape((seq_len * features, 1))(seq_model)
seq_model = GlobalMaxPooling1D()(seq_model)