Comments (2)
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
from triplet_recommendations_keras.
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
from triplet_recommendations_keras.
Related Issues (15)
- Fixing NaNs with built-in Sigmoid HOT 4
- Does not run with Keras 0.3.3 HOT 5
- Exception: ('Invalid merge mode:', 'join') HOT 5
- Why not control the nb_epoch within the fit function? HOT 1
- Doubt about margin_triplet_loss HOT 4
- Test set triplet sample HOT 1
- Item features as inputs for Item embedding HOT 1
- Both test loss and validation loss go to 0.5 HOT 6
- Loss and output functions are different. HOT 2
- Dumb question: how do ratings on a scale of 1-5 map to positive examples? HOT 4
- Please,I have a problem with your function "bpr_triplet_loss"... HOT 1
- AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
- Extract Embedding Model after training HOT 1
- Issues using items metadata HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from triplet_recommendations_keras.