This topic describes the DeepFM algorithm.
Overview
DeepFM combines a deep neural network (DNN) with a factorization machine (FM) to capture both low-order explicit feature interactions and high-order implicit feature interactions. DeepFM requires no manual feature engineering and is commonly used in recommendation systems and advertising systems.
-
Input features typically fall into two categories:
-
Categorical features: string values, such as gender (male or female) or product category (clothing, toys, electronics).
-
Numerical features: integer or floating-point values, such as user activity level or product price.
-
-
The output is typically a floating-point number between 0 and 1, representing the probability of the target value being 1. The output can be used for ranking or binary classification.
Use cases
DeepFM is commonly used in classification or ranking scenarios. It is especially effective when manually constructed features cannot directly reflect outcomes. In various recommendation scenarios, both low-order and high-order feature interactions affect user behavior. Because these interactions are often unclear to humans, DeepFM automatically learns them.
For example, in a personalized product recommendation scenario, a click-through rate (CTR) prediction model is required. Historical user behavior data (clicks, impressions without clicks, purchases) is used as training data to predict the probability of a user clicking or purchasing. When user behavior data is extensive and does not directly indicate future click or purchase patterns, DeepFM combines user behavior features and converts sparse features into high-dimensional dense representations.
Parameters
The following table lists the parameters that you can specify in the CREATE MODEL syntax by using the model_parameter clause. Select the parameters that suit your use case.
|
Parameter |
Description |
|
metrics |
The evaluation metric for the model. Valid values:
|
|
loss |
The loss function for the learning task. Valid values:
|
|
optimizer |
The optimizer. Valid values:
|
|
validation_split |
The fraction of data used for cross-validation. Default value: 0.2. |
|
epochs |
The number of training iterations. Default value: 6. |
|
batch_size |
The number of training samples per batch. Default value: 64. A smaller batch size is more prone to overfitting, but a larger batch_size increases memory consumption per iteration. For large datasets, consider increasing this value (for example, to 128 or 256) to improve training efficiency. For small datasets or memory-constrained environments, consider decreasing it. |
|
learning_rate |
The learning rate that controls the magnitude of parameter updates at each iteration. This parameter should be tuned together with epochs: when increasing epochs, you typically need to decrease learning_rate to prevent the model from diverging or failing to converge. Conversely, when decreasing epochs, you can increase the learning rate. |
|
dnn_hidden_units |
The architecture of the DNN hidden layers. Example: |
|
task |
The task type. Valid values:
|
Best practices for parameter configuration:
-
We recommend explicitly specifying key parameters such as
loss,metrics, andbatch_sizeto avoid unexpected training behavior caused by relying on default values. -
batch_sizeandepochsshould be tuned together: when increasing batch_size, consider decreasing epochs; when decreasing batch_size, increase epochs to ensure sufficient training. -
learning_rateandepochsshould be tuned together: when increasing epochs, decrease the learning rate to prevent divergence. -
dnn_hidden_unitsshould be set based on the number of features. Avoid using overly deep network structures when you have fewer features.
Examples
Train a model
/*polar4ai*/CREATE MODEL airline_deepfm WITH
(model_class = 'deepfm',
x_cols = 'Airline,Flight,AirportFrom,AirportTo,DayOfWeek,Time,Length',
y_cols='Delay',model_parameter=(epochs=6))
AS (SELECT * FROM db4ai.airlines);
Evaluate the model
/*polar4ai*/SELECT Airline FROM EVALUATE(MODEL airline_deepfm,
SELECT * FROM db4ai.airlines LIMIT 20) WITH
(x_cols = 'Airline,Flight,AirportFrom,AirportTo,DayOfWeek,Time,Length',y_cols='Delay',metrics='acc');
Run predictions
/*polar4ai*/SELECT Airline FROM PREDICT(MODEL airline_deepfm,
SELECT * FROM db4ai.airlines limit 20) WITH
(x_cols = 'Airline,Flight,AirportFrom,AirportTo,DayOfWeek,Time,Length');
FAQ
Q: How do I troubleshoot slow or failed DeepFM model training?
A: If DeepFM model training takes an unusually long time or eventually fails, troubleshoot the issue from the following aspects:
|
Possible cause |
Troubleshooting and solution |
|
|
Increase |
|
|
Adjust |
|
|
Simplify the network structure. For example, change |
|
Key parameters are not explicitly specified: relying on default values may result in unexpected training behavior. |
Explicitly configure key parameters such as |
|
Data quality issues: the training data contains a large number of missing values, outliers, or unevenly distributed features. |
Check the training data quality. Fill in missing values or remove outlier samples before retraining the model. |