code: """
  @Description: TextCNN 网络
  @Author: 吕明伟
  @Date: 2021-4-6
  """
  from tensorflow.keras import Input, Model
  from tensorflow.keras.layers import Embedding, Dense, Conv1D, GlobalMaxPooling1D, Concatenate, Dropout
  
  class TextCNN(object):
      def __init__(self, maxlen, max_features, embedding_dims,
                   class_num=5,
                   last_activation='softmax'):
          self.maxlen = maxlen
          self.max_features = max_features
          self.embedding_dims = embedding_dims
          self.class_num = class_num
          self.last_activation = last_activation
  
      def get_model(self):
          input = Input((self.maxlen,))
          embedding = Embedding(self.max_features, self.embedding_dims, input_length=self.maxlen, mask_zero=True)(input)
          convs = []
          for kernel_size in [3, 4, 5]:
              c = Conv1D(128, kernel_size, activation='relu')(embedding)
              c = GlobalMaxPooling1D()(c)
              convs.append(c)
          x = Concatenate()(convs)
  
          output = Dense(self.class_num, activation=self.last_activation)(x)
          model = Model(inputs=input, outputs=output)
          return model
apis: tensorflow.keras.layers.Concatenate tensorflow.keras.layers.Embedding tensorflow.keras.layers.Conv1D tensorflow.keras.Model tensorflow.keras.layers.Dense tensorflow.keras.layers.GlobalMaxPooling1D tensorflow.keras.Input