Ejemplo n.º 1
0
    def build(self,input_dims):
        #句子特征
        model=Sequential()
        model.add(Convolution2D(100,1,input_dims[0],input_shape=(self.num_channel,100,input_dims[0]),activation='relu'))
        model.add(Dropout(0.5))
        model.add(MaxPooling2D(pool_size=(50,1)))
        model.add(Flatten())
        model.add(Dropout(0.5))
        model.add(Dense(100,activation='tanh'))
        model.add(Dropout(0.5))

        #用户整体特征
        model2=Sequential()
        model2.add(Dense(100,input_dim=input_dims[1],activation='tanh'))
        model2.add(Dropout(0.5))
        
        #时间地域特征
        model3=Sequential()
        model3.add(Dense(output_dim=800,input_dim=input_dims[2],activation='tanh'))
        model3.add(Dropout(0.5))
        model3.add(Dense(output_dim=300,activation='tanh'))
        model3.add(Dropout(0.5))

        merged_model= Sequential()
        merged_model.add(Merge([model, model2,model3], mode='concat', concat_axis=1))
        merged_model.add(Dense(self.num_class))
        merged_model.add(Activation('softmax'))

        merged_model.compile(loss='categorical_crossentropy',optimizer='adadelta',metrics=['accuracy'],)
        
        self.model=merged_model
        self.earlyStopping=EarlyStopping(monitor='val_loss', patience=25, verbose=0, mode='auto')
        self.checkpoint=ModelCheckpointPlus(filepath='weights.hdf5',monitor='val_loss',verbose_show=20)
Ejemplo n.º 2
0
    def build(self, vector_dim):
        #句子特征
        model = Sequential()
        model.add(
            Convolution2D(100,
                          1,
                          vector_dim,
                          input_shape=(2, 100, vector_dim),
                          activation='relu'))
        model.add(Dropout(0.5))
        model.add(MaxPooling2D(pool_size=(50, 1)))
        model.add(Flatten())
        model.add(Dropout(0.5))
        model.add(Dense(100, activation='tanh'))
        model.add(Dropout(0.5))
        model.add(Dense(3, activation='softmax'))
        model.compile(
            loss='categorical_crossentropy',
            optimizer='adadelta',
            metrics=['accuracy'],
        )

        self.model = model
        self.earlyStopping = EarlyStopping(monitor='val_loss',
                                           patience=25,
                                           verbose=0,
                                           mode='auto')
        self.checkpoint = ModelCheckpointPlus(filepath='weights.hdf5',
                                              monitor='val_loss',
                                              verbose_show=20)
Ejemplo n.º 3
0
    def build(self, input_dim):
        model = Sequential()
        model.add(Dense(output_dim=800, input_dim=input_dim,
                        activation='tanh'))
        model.add(Dropout(0.5))
        model.add(Dense(output_dim=300, activation='tanh'))
        model.add(Dropout(0.5))
        model.add(Dense(output_dim=8))
        model.add(Dropout(0.3))
        model.add(Activation('softmax'))

        model.compile(optimizer='adadelta',
                      loss='categorical_crossentropy',
                      metrics=['accuracy'])

        self.model = model
        self.earlyStopping = EarlyStopping(monitor='val_loss',
                                           patience=100,
                                           verbose=0,
                                           mode='auto')
        self.checkpoint = ModelCheckpointPlus(filepath='weights.hdf5',
                                              monitor='val_loss',
                                              verbose_show=20)