
Posted by Ellie Zhou, Tian Lin, Shuangfeng Li and Sushant Prakash
, we received a lot of interest from the community on introducing on-device recommender AI. Motivated and inspired by the feedback, we considered various use cases, and created a framework that could generate TensorFlow Lite recommendation models accommodating different kinds of data, features, and architectures to improve the previous models.Benefits of this framework:
- Flexible: The adaptive framework allows users to create a model in a configurable way.
- Better model representation: To improve the and create recommendation experience in your applications.
In this article, we will
- Introduce the improved model architecture and framework adaptivity.
- Walk you through how to utilize the framework step-by-step.
- Provide insights based on research done with a public dataset.
Please find more details on
Figure 1: An illustration of the configurable recommendation model. Each module is created according to the user-defined configuration. At the context side, representations of all user activities are aggregated by the encoder to generate the context embedding. We support three different types of encoders: 1) bag-of-words (a.k.a. BOW), 2) 1-D convolution (a.k.a. CNN), and 3) LSTM. At the label side, the label item as positive and all other items in the vocabulary as negatives will be encoded to vectors as well. Context and label embeddings are combined with a dot product and fed to the loss of softmax cross entropy.
Inside the framework, we encapsulate tf.keras layers for ContextEncoder, LabelEncoder and DotProductSimilarity as key components in RecommendationModel.
To model each user activity, we could use the ID of the activity item (called ID-based), or multiple features of the item (called feature-based), or a combination of both. The feature-based model utilizing multiple features to collectively encode users’ behavior. With our framework, you could create either ID-based or feature-based models in a configurable way.
Similar to the last version, a TensorFlow Lite model will be exported after training which can directly provide top-K predictions among the recommendation candidates.
Step-by-step
To demonstrate the new adaptive framework, we trained a on-device movie recommendation model with .
(a) Environment preparation
CODEgit clone https://github.com/tensorflow/examples
cd examples/lite/examples/recommendation/ml/
pip install -r requirements.txt(b) Prepare training data
Please prepare your training data reference to the movielens example generation file. Would like to note that TensorFlow Lite input features are expected to be , ), each of which could be utilized by itself. The following diagram illustrates the code structure:
, and we refer readers to check out the details there. Framework Adaptivity
Our framework provides a and
Comparison between ID-based and Feature-based models. We compare them on BOW/CNN/LSTM encoders and context history lengths 10/50/100. Since MovieLens dataset is an experimental dataset with ~4000 candidate movies and 19 movie genres, hence we scaled down embedding dimensions in the experiments to simulate the production scenario. For the above experiment result chart, ID embedding dimension is set to 8, and movie genre embedding dimension is set to 4. If we take the
context10_cnnas an example, the feature-based model outperforms the ID-based model by 58.6%. Furthermore, the on average results show that feature-based models outperforms by 48.35%. Therefore, In this case, the feature-based model outperforms the ID-based model, becausemovie_genrefeature introduces additional information to the model.Besides, underlying features of candidate items mostly have a smaller vocabulary size, hence smaller embedding spaces as well. For instance,the movie genre vocabulary is much smaller than the movie ID vocabulary. In this case, utilizing underlying features could reduce the memory size of the model, which is more on-device friendly.
Acknowledgement
Special thanks to Cong Li, Josh Gordon, Khanh LeViet, Arun Venkatesan and Lawrence Chan for providing valuable suggestions to this work.
↗ Original-Artikel auf blog.tensorflow.org lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf blog.tensorflow.org.
SOCIAL SHARE CARD GENERATOR