# Architecture Rexify has two main components: the `FeatureExtractor` and the `Recommender`. The former basically takes the original data, and learns all the transformations that need to be applied to the dataset. The output is a `tf.data.Dataset` with the right structure to be passed on to the `Recommender` model. This `Recommender` is a TensorFlow model with a dynamic architecture, which adapts itself according to the schema fed to the `FeatureExtractor`. ## Feature Extractor The `FeatureExtractor` is a scikit-learn Transformer. It implements a `.fit()` and a `.transform()` method that apply a set of transformations on the data. Essentially, it has a `_ppl` attribute which is a `sklearn.pipeline.Pipeline`; the pipeline steps are set according to the `schema` passed during instantiation, which are scikit-learn Transformers themselves. For example, an attribute classified as `id` would create a pipeline step with a `sklearn.compose.ColumnTransformer`, composed of a single `sklearn.preprocessing.OrdinalEncoder` Transformer. Additionally, it subclasses `rexify.features.TfDatasetGenerator`, which converts the output of the transformations of the `FeatureExtractor` into a `tf.data.Dataset`, with a nested structure such as this: ``` { "query": { "user_id": tf.Tensor([]), "user_features": tf.Tensor([]), "context": tf.Tensor([]), }, "candidate": { "item_id": tf.Tensor([]), "item_features": tf.Tensor([]) } } ``` With this structure, the Recommender model can call a different set of layers for the user and item ID attributes, and the remaining transformed features. ## Recommender The `Recommender` is a `tfrs.models.Model`, which subclasses `tf.keras.Model` and overrides the `.train_step()` method. According to the [TensorFlow Recommenders documentation](https://www.tensorflow.org/recommenders/api_docs/python/tfrs/models/Model): > Many recommender models are relatively complex, and do not neatly > fit into supervised or unsupervised paradigms. This base class makes it easy to > define custom training and test losses for such complex models. In this case, we use the Recommender model, to create a two tower model architecture, as explained [here](https://research.google/pubs/pub48840/). In short, it's composed of two main models, a Query model and a Candidate model, both of which learn to represent queries and candidates in the same vector space.