Package: deepex
DeepEX[TOC]OverviewDeepEXis a universal convenient frame with keras and Tensorflow,You can get well-known Wide&Deep model such as DeepFM here.Or, you can define you custom model use this frame.How to InstallFor Linux:pipinstalldeepexFor Windows:You need active cmd first and,pipinstalldeepexNotice: This frame needs keras and tensorflow, maybe it has some problem on windows with python 2.x because of tensorflow.DeepEX Class APIIn the functional API, given some parmeters, you can instantiate aDeepEXobject, via:DeepEX(data=None,feature_dim=None,category_index=None,embedding_dict_size=1000,embedding_size=64,depths_size=[1024,256,64],class_num=2,aggregate_flag=False,metrics=None,optimizer='Adam',activation='relu',embedding_way='dense')Only data is necessary, other parmeters have default value.Argumentsdata: np.arrayfeature_dim: integer, feature dimensioncategory_index:Can be a 2D list, like [A,B], A and B also a list, if len(A)>1, that means the element of A belong to a field, and will be input embedding layer together.Can be a integer, it specific feature_dim % integer == 0, that means split feature as equal intervals with category_indexIf None, all of feature will be embeddingNEW UPDATE: Can be a mix type, like [A,B,c], A and B is list but c is a integer. It can achive more flexible way of split field, A and B will be split as col.1 and the rest of element will be split as col.2 with parameter c. Notice: c must be the last element, and the count of remaining element can be evenly divisible by cembedding_dict_size: embedding dict size of categroy featureembedding_size: embedding size, it make output size like (?, len(category_index), embedding_size)depths_size: network of deep part parameter, last dimension means fc7 shapeclass_num: multi class or binary class, if class_num < 2, you will get a regression modelaggregate_flag:if True, first_order and second_order of FM part output as (?,1)if False, output as (?, len(category_index)) and (?, embedding_size)metrics: can recive custom metrics, if None, binary class use AUC, multi class use auccaryoptimizer: Network optimizer, default adam,  seeoptimizer.activation: Deep part activation, default relu, seeactivations.embedding_way: How network to do embedding, Embedding layer or Dense layerMethodsget_embedding_layerembedding input data as class parameter.returninputs: A list, which elements are Input layer,  prepare to deep modelnumerics: A list, which elements are numeric feature tensorembeddings:  A list, which elements are categroy feature embedding tensorembedding_layer: A tensor, which is concate numeric feature tensor and categroy feature embedding tensorget_wide_modelget fm partreturnA tensor, shape depends on class parameteraggregate_flagget_deep_modelget deep partreturninputs: A list, which elements are Input layer,  prepare to deep modelmodel: A tensor, which is also a keras functional layerdeepfmget deepfm model, fc7 which is the last layer before classifier, it will be a class variablereturnmodel: A keras functional modelaucauc(y_true,y_pred)A custom metrics, when class_num=2, use this metrics to evaluate modelfitfit(model,y,save_model_path=None,batch_size=None,epochs=1,verbose=1,callbacks=None,validation_split=0.0,validation_data=None,shuffle=True,class_weight=None,sample_weight=None,initial_epoch=0,steps_per_epoch=None,validation_steps=None)fit data to train modelArgumentsmodel: a DeepEX modelsave_model_path: A string, where model to save, if None, model will not be savedothers: see documentkeras fitget_fc7_outputget_fc7_output(self,model_path=None,layer_name='fc7',data=None)Get model's fc7 layer output, it can use for other operation, such as model ensembleArgumentsmodel_path: A string, only model_path is necessary,  tell function where model is, the model file should be saved use keras.models.Model.save() function.layer_name: A string, default 'fc7'data: numpy array, NOTICE: if you declare a DeepEX object use same parameter just like model will be load (actually just need [data] and [category_index] are same), this parametre can be None, data will read from self.data. HOWEVER, if you declare other way, you need split data format as model inputreturnintermediate_output: Numpy array(s) of intermediate outputs.How to UseThis class is very easy to use,  three steps to go：# step 1, declare DeepEX objectdeepEX=DeepEX(...)# step 2, get model you wantmodel=deepEX.deepfm()# step 3, train and savedeepEX.fit(...)examplefromdeepeximport*importnumpyasnpsamples=100000# set samples numfeat_dim=10# set feat_dimcate=np.random.randint(1,6,samples)# set a categroy feat randomlyx=np.random.random((samples,feat_dim))# generate feat randomlyx[:,3]=cate# chose a column to be categroy featy=np.random.randint(0,2,samples)# generate label# declare DeepEX objectsdeepEX=DeepEX(data=x,feature_dim=feat_dim,category_index=[[0,1],4],embedding_dict_size=1000,embedding_size=64,depths_size=[1024,256,64],class_num=2,aggregate_flag=False,metrics=None,optimizer='Adam',activation='relu',embedding_way='emb')model=deepEX.deepfm()# get DeepFMplot_model(model,'deepFM.png',show_shapes=True)# show model graph# train deepfmpath=NonedeepEX.fit(model,y,save_model_path=path,batch_size=None,epochs=1,verbose=1,callbacks=None,validation_split=0.0,validation_data=None,shuffle=True,class_weight=None,sample_weight=None,initial_epoch=0,steps_per_epoch=None,validation_steps=None)# get fc7 output tensorfc7=deepEX.get_fc7_output(model_path=path,layer_name='fc7',data=deepEX.data_split)