Code Monkey home page Code Monkey logo

recommendation-systems's Introduction

Trace's Profile ๐Ÿ‘‹

  • ๐Ÿ”ญ Working on SlickML
  • ๐ŸŒฑ Learning More Details on MLOps and Software Engineering
  • ๐Ÿ‘ฏ Looking to Collaborate on Machine Learning Projects
  • ๐Ÿ’ฌ Ask me about Data Science and Machine Learning
  • ๐Ÿ“ซ How to reach me: [email protected]

Connect with me:

LinkedIn Github Twitter



Data Science Skills & Languages:

Python

R

spark

vim

git

aws

azure

docker

pytorch

tensorflow




Tsmith5151's Github Stats



GitHub last commit pv

recommendation-systems's People

Contributors

tsmith5151 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

recommendation-systems's Issues

Parameters in case of 6 meta data

history = Hybrid.train([train['user_id_encoded'],
train['item_id_encoded'],
np.stack(train['tfidf'],axis=0),
train['frame_shape'],train['rim_type'],train['classification'],train['frameMaterial'],train['frameStylePrimary'],train['platform']],train['Rating'])
model = Hybrid.model

`

class HybridRecommender:
def init(
self,
unique_users: int,
unique_items: int,
tfidf_features: int,
epochs: int,
dense_units: int,
dropout: float,
batch_size: int,
embedding_dim: int,
):
"""
Deep Hybrid Recommender Engine:

    One of the advantage of using neural networks for recommendation
    systems is the ability to create an architecture that utilizes both
    the collaborative and content based filtering approaches. This class
    exploits using explicit data to include side features for user/items.
    Ideally this type of approach could help address the cold start problem
    or refined ranking given a subset of items filtered from a candidate
    generator model (e.g. see retrieval.py)

    Parameters
    ----------
    unique_users: np.ndarray
        input array of unique users for creating embedding layer
    unique_items: np.ndarray
        input array of unique items for creating embedding layer
    tfidf: np.ndarray
        input array of tfidf features
    epochs: int
        number of epochs to train the model. An epoch is an iteration over the
        entire x and y data provided.
    dense_units:int
        dimensionality of the output space for hidden layer
    dropout:int
        randomly sets input units to 0 with a frequency of rate at each
        step during training time to help prevent overfitting
    batch_size:int
        number of samples per batch of computation.
    embedding_dim: int
        number of dimensions for embedding layer
    """
    self.unique_users = unique_users
    self.unique_items = unique_items
    self.tfidf_features = tfidf_features
    self.dropout = dropout
    self.units = dense_units
    self.batch_size = batch_size
    self.epochs = epochs
    self.embedding_dim = embedding_dim
    self.loss = "mse"

def __repr__(self):
    return """ Deep Hybrid Recommendation Engine """

def build_model(self, x, y):
    """Build Hybrid Model
    This helper function for generating the model can be
    extended to incorporate additional hidden features.

    Parameters
    ----------
    x: np.ndarray
       input training data; example input: [use_id,item_id,features]
    y: np.ndarray
       input target
    """

    # TFIDF Feature Vector - Item Feature
    print(self.tfidf_features.shape)        
    self.tfidf_input = Input(shape=(self.tfidf_features.shape[0]), name="tfidf")

    self.tfidf_vector = Dense(64, activation="relu")(self.tfidf_input)

    # Meta Item Feature
    self.item_meta_input = Input(shape=[1], name="item_meta_feature")
    self.item_meta_vector = Dense(64, activation="relu")(self.item_meta_input)

    # User Embeddings
    self.user_id_input = Input(shape=[1], name="user")
    self.user_embedding = Embedding(
        output_dim=self.embedding_dim,
        input_dim=self.unique_users.shape[0],
        input_length=1,
        embeddings_regularizer=l2(1e-6),
        name="user_embedding",
    )(self.user_id_input)
    self.user_vector = Reshape([self.embedding_dim])(self.user_embedding)
    self.user_vector = Dense(64, activation="relu")(self.user_vector)

    # Item Embeddings
    self.item_id_input = Input(shape=[1], name="item")
    self.item_embedding = Embedding(
        output_dim=self.embedding_dim,
        input_dim=self.unique_items.shape[0],
        input_length=1,
        embeddings_regularizer=l2(1e-6),
        name="item_embedding",
    )(self.item_id_input)
    self.item_vector = Reshape([self.embedding_dim])(self.item_embedding)
    self.item_vector = Dense(64, activation="relu")(self.item_vector)

    # concatentate items vector
    concat_items_vector = Concatenate()(
        [
            self.item_vector,
            self.tfidf_vector,
            self.item_meta_vector,
        ]
    )

    # concatenate user/items vector followed by dense layer(s)
    user_items_vector = Concatenate(name="user_items")(
        [self.user_vector, concat_items_vector]
    )
    layer_1 = Dense(self.units, kernel_regularizer="l2", activation="relu")(
        user_items_vector
    )
    dropout = Dropout(self.dropout)(layer_1)
    layer_2 = Dense(self.units, kernel_regularizer="l2", activation="relu")(dropout)
    self.output = Dense(1)(layer_2)

    self.model = Model(
        inputs=[
            self.user_id_input,
            self.item_id_input,
            self.tfidf_input,
            self.item_meta_input,
        ],
        outputs=self.output,
    )
    self.model.compile(loss=self.loss, optimizer="adam")

def _evaluate(self, X, Y, name):
    """Evaluate Model"""
    mse = self.model.evaluate(X, Y)
    logger.info(f"{name} mean squared error: {mse:.4f}")

def train(self, X_train: np.ndarray, Y_train: np.ndarray):
    """Helper function to train model

    Parameters
    ----------
    x: np.ndarray
            input training data; example input: [use_id,item_id,features, *args]
    y: np.ndarray
            input target; example movie ratings
    """

    self.build_model(X_train, Y_train)
    early_stop = EarlyStopping(
        monitor="val_loss", mode="auto", verbose=0, patience=5
    )
    history = self.model.fit(
        X_train,
        Y_train,
        batch_size=self.batch_size,
        epochs=self.epochs,
        validation_split=0.1,
        shuffle=True,
        verbose=1,
        callbacks=[early_stop],
    ).history

    self._evaluate(X_train, Y_train, "train")
    return history

`

getting this error :

his is the error File "/root/anaconda3/envs/reco3.7/lib/python3.7/site-packages/keras/engine/input_spec.py", line 217, in assert_input_compatibility
f'Layer "{layer_name}" expects {len(input_spec)} input(s),'

ValueError: Layer "model" expects 4 input(s), but it received 9 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, 1) dtype=int64>, <tf.Tensor 'IteratorGetNext:1' shape=(None, 1) dtype=int64>, <tf.Tensor 'IteratorGetNext:2' shape=(None, 25) dtype=float32>, <tf.Tensor 'IteratorGetNext:3' shape=(None, 1) dtype=int64>, <tf.Tensor 'IteratorGetNext:4' shape=(None, 1) dtype=int64>, <tf.Tensor 'IteratorGetNext:5' shape=(None, 1) dtype=int64>, <tf.Tensor 'IteratorGetNext:6' shape=(None, 1) dtype=int64>, <tf.Tensor 'IteratorGetNext:7' shape=(None, 1) dtype=int64>, <tf.Tensor 'IteratorGetNext:8' shape=(None, 1) dtype=int64>]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.