neural_collaborative_filtering icon indicating copy to clipboard operation
neural_collaborative_filtering copied to clipboard

How to implement if input is the feature vector of user (item), not one-hot vector?

Open TruongKhang opened this issue 6 years ago • 16 comments

TruongKhang avatar Jul 25 '17 10:07 TruongKhang

You need to revise the codes a little bit. Two ways: 1) pass in a set of elements that denote the nonzero features for user/item; or 2) check the current support of Keras on sparse vector representation.

On Tue, Jul 25, 2017 at 12:28 PM, TruongKhang [email protected] wrote:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hexiangnan/neural_collaborative_filtering/issues/5, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGxjvfmoaI0Xtyf3S52WZqywtzBvc_Cks5sRcMxgaJpZM4OiXRV .

-- Best Regards, Xiangnan He

hexiangnan avatar Jul 26 '17 08:07 hexiangnan

I mean: for example, I have the extra information of the user such as time, place... and I want to add it to vector input. Can you have an idea?

TruongKhang avatar Jul 28 '17 02:07 TruongKhang

Yes. I understand your meaning. You can either pass the extra info in the similar way as user/item ID, or rely on the sparse vector support of Keras (represent all info as a one-hot encoded sparse feature vector).

On Fri, Jul 28, 2017 at 4:24 AM, TruongKhang [email protected] wrote:

I mean: for example, I have the extra information of the user such as time, place... and I want to add it to vector input. Can you have an idea?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hexiangnan/neural_collaborative_filtering/issues/5#issuecomment-318538653, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGxjtUm_pyGCEyvut99ZrzG5xN_4jeVks5sSUZDgaJpZM4OiXRV .

-- Best Regards, Xiangnan He

hexiangnan avatar Jul 28 '17 07:07 hexiangnan

Many thanks. I have tried to implement your model. Did you see the problem that the time training increase after each epoch when you run the experiment?

TruongKhang avatar Jul 30 '17 02:07 TruongKhang

I think I did not meet the problem.. How do you implement the model? With Keras or Tensorflow or other tools?

On Sun, Jul 30, 2017 at 10:51 AM, TruongKhang [email protected] wrote:

Many thanks. I have tried to implement your model. Did you see the problem that the time training increase after each epoch when you run the experiment?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hexiangnan/neural_collaborative_filtering/issues/5#issuecomment-318874092, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGxjlN688T8GiVfSejJBDCO_2cQpa5tks5sS-_FgaJpZM4OiXRV .

-- Best Regards, Xiangnan He

hexiangnan avatar Aug 01 '17 01:08 hexiangnan

Hi Truong,

I find a bug in my evaluation codes which may cause the increasing of evaluation time. I have fixed the bug. You may check whether are the evaluation codes causing your issue.

On Sun, Jul 30, 2017 at 10:51 AM, TruongKhang [email protected] wrote:

Many thanks. I have tried to implement your model. Did you see the problem that the time training increase after each epoch when you run the experiment?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hexiangnan/neural_collaborative_filtering/issues/5#issuecomment-318874092, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGxjlN688T8GiVfSejJBDCO_2cQpa5tks5sS-_FgaJpZM4OiXRV .

-- Best Regards, Xiangnan He

hexiangnan avatar Aug 02 '17 03:08 hexiangnan

Hi Khang, Xiangnan,

I also intend to change one-hot vector by feature vector. I try to change the function get_model. But it does not work. Can you tell me how do you change it?

Thank you for your time!

xanhho avatar Dec 06 '17 02:12 xanhho

You can search some function in keras, for example in my case, I used the function merge to add the information for input and then, I had the feature vector

TruongKhang avatar Dec 06 '17 11:12 TruongKhang

Hi Khang,

Thank you for your reply! I also try the function merge, with mode 'sum' or 'concat'. If I try with the code like this: item_latent = merge([item_latent, item_latent], mode = 'concat') It will work ok, but If I try with the code like this: item_latent = merge([item_latent, my_data], mode = 'concat') It will have some errors. I try to change my_data the same type with item_latent, but it also has an error.

I'm new to using Keras and Theano. Can you tell me how do you put your information into a variable that we can you this variable in merge function?

Thank you for your time!

xanhho avatar Dec 06 '17 13:12 xanhho

I need to know what your data looks like. And maybe you should show me your code. With the information above, it's quite abstract :))

TruongKhang avatar Dec 06 '17 14:12 TruongKhang

My data is numpy.ndarray with shape (num_items x latent_dim). I read my data into variable data. data = np.load('filename.npy')

// This code I use to change the type numpy.ndarray ---> TensorVariable (The same type with item_latent)

data_temp = np.zeros(shape=data.shape)
data_tensor = theano.shared(data, 'data')
data_temp_tensor = theano.shared(data_temp, 'temp')
item_feature_vector = T.add(data_tensor, data_temp_tensor)

// I don't know there are any way to change data from numpy.ndarray ---> TensorVariable, so I use the way is not look good.

If I try to run: item_latent = merge([item_latent, item_latent], mode = 'sum') It will ok. But, if I try to run: item_latent = merge([item_latent, item_feature_vector], mode = 'sum') It will have errors: "AttributeError: 'TensorVariable' object has no attribute 'get_shape'"

How do you change your data in type TensorVariable?

Thank you for your time!

xanhho avatar Dec 07 '17 05:12 xanhho

How about using the layer Input of Keras to pass your data into the network. I'm not sure about that, but you can read the code which I changed based on the code of Xiangnan here: https://github.com/TruongKhang/Instacart/blob/master/MLPlogistic.py In this code, I added the auxiliary information for user and item

TruongKhang avatar Dec 07 '17 05:12 TruongKhang

Hi Khang,

Thank you for your sharing! After I try to understand your code, It looks you create auxiliary information in the layer Input of Keras. You don't have to read the auxiliary information from somewhere, is it right?

I also try to read about the layer Input of Keras, but there is no document about how to pass data into the Input layer of Keras :'(.

xanhho avatar Dec 07 '17 08:12 xanhho

For example I create a Input layer to read the auxiliary input of user aux_user_input = Input(shape=(4,), name='aux_user_input') It means the auxiliary input is a numpy array 1x4. When you run model, you just pass the data numpy array into fit function

And about Input layer in Keras, because Xiangnan used the old version of Keras, the current version of Keras doesn't have that layer. Maybe it's replaced by other layers. I also don't know. But when I read the code of Xiangnan, I installed the right version and I spent a lot of time to understand it. Anyway, I'm just a student, not professional. But I can help you fix code if you want :))

TruongKhang avatar Dec 07 '17 09:12 TruongKhang

Hi Khang,

I also interest to discuss with you about this model, how can I contact with you?

xanhho avatar Dec 07 '17 12:12 xanhho

You can search [email protected] on skype and add me.

TruongKhang avatar Dec 07 '17 13:12 TruongKhang