Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error in running triplet_movielens.py #16

Open
sumedhvdatar opened this issue Nov 26, 2018 · 2 comments
Open

Error in running triplet_movielens.py #16

sumedhvdatar opened this issue Nov 26, 2018 · 2 comments

Comments

@sumedhvdatar
Copy link

I am trying to run triplet_movielens.py with the same movielens dataset and I get the following error.

Using TensorFlow backend.
Traceback (most recent call last):
File "triplet_movielens.py", line 80, in
model = build_model(num_users, num_items, latent_dim)
File "triplet_movielens.py", line 58, in build_model
output_shape=(1, ))
TypeError: 'module' object is not callable

I am stuck and I need help.

@mindis
Copy link

mindis commented Jan 1, 2019

based on https://stackoverflow.com/questions/43160181/keras-merge-layer-warning

"""
Triplet loss network example for recommenders
"""

from future import print_function

import numpy as np

from keras import backend as K
from keras.models import Model
from keras.layers import Embedding, Flatten, Input, Lambda
from keras.optimizers import Adam
import data
import metrics

def identity_loss(y_true, y_pred):

return K.mean(y_pred - 0 * y_true)

def bpr_triplet_loss(X):

positive_item_latent, negative_item_latent, user_latent = X

# BPR loss
loss = 1.0 - K.sigmoid(
    K.sum(user_latent * positive_item_latent, axis=-1, keepdims=True) -
    K.sum(user_latent * negative_item_latent, axis=-1, keepdims=True))

return loss

def build_model(num_users, num_items, latent_dim):

positive_item_input = Input((1, ), name='positive_item_input')
negative_item_input = Input((1, ), name='negative_item_input')

# Shared embedding layer for positive and negative items
item_embedding_layer = Embedding(
    num_items, latent_dim, name='item_embedding', input_length=1)

user_input = Input((1, ), name='user_input')

positive_item_embedding = Flatten()(item_embedding_layer(
    positive_item_input))
negative_item_embedding = Flatten()(item_embedding_layer(
    negative_item_input))
user_embedding = Flatten()(Embedding(
    num_users, latent_dim, name='user_embedding', input_length=1)(
        user_input))

def out_shape(shapes):
    return shapes[0]

loss = Lambda(bpr_triplet_loss, output_shape=out_shape)([positive_item_embedding, negative_item_embedding,user_embedding])

model = Model(
    input=[positive_item_input, negative_item_input, user_input],
    output=loss)
model.compile(loss=identity_loss, optimizer=Adam())

return model

@myeonghak
Copy link

myeonghak commented Jul 11, 2022

for those who are encountering this issue,

> TypeError: ('Keyword argument not understood:', 'input')

the solution is to remove keywords in Model function.

so the fixed code will be look like this.

model = Model(
[positive_item_input, negative_item_input, user_input],
loss)

source: https://stackoverflow.com/questions/60690327/typeerror-keyword-argument-not-understood-inputs

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants