Contextual Data for LibFM

157 views
Skip to first unread message

fzl.l...@gmail.com

unread,
Nov 24, 2017, 6:20:35 AM11/24/17
to libFM - Factorization Machines
Hi,

I am a bit confused about using contextual data with libfm.

If data is like:
userA, itemC, ratingX, context1, context4, context7
userB, itemC, ratingY, context1, context2, context4

The context4 appears at two different position in the list, then when converting to libfm format, context4 will have two different ids, like if there were two context4.

How to deal with this?

How did authors of "Fast context-aware recommendations with factorization machines" model the contextualized data ?

thanks for help!

Thierry Silbermann

unread,
Nov 25, 2017, 9:08:13 AM11/25/17
to libFM - Factorization Machines

Hey,

Well I think you are getting it wrong.

userA, itemC, ratingX, context1, context4, context7
userB, itemC, ratingY, context1, context2, context4

Let's say you have 3 differents kind of features here (user, item and context) and then the rating.

Let's say you have 3 users (User A, B and C), 4 items (Item A, B, C, D) and 7 contexts (context 1 to 7).

If you one hot encode the first sample you will end up with:
User    Item           Context
1 0 0 | 0 0 1 0 | 1 0 0 1 0 0 1

and the second as:
User    Item           Context
0 1 0 | 0 0 1 0 | 1 1 0 1 0 0 0

In libFM format you might end up with this:

X 0:1 5:1 7:1 10:1 13:1
Y 1:1 5:1 7:1   8:1 10:1

Which corresponds to the rating then the index position of the first feature in your sample and then the value for this feature. You can replace the value of 1 in the context with a normalized value, here because you have 3 contexts for each sample you can just put 1/3.

I hope it's clearer

fatima zahra lahlou

unread,
Nov 25, 2017, 6:32:06 PM11/25/17
to Thierry Silbermann, libFM - Factorization Machines
Thanks Thierry


I got your clarification.

Now my question is how data should be written as input of  triple_format_to_libfm.pl in order to be converted like this
X 0:1 5:1 7:1 10:1 13:1
Y 1:1 5:1 7:1   8:1 10:1

Thanks again!

--
You received this message because you are subscribed to a topic in the Google Groups "libFM - Factorization Machines" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/libfm/Ik2m_JU5UZc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to libfm+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thierry Silbermann

unread,
Nov 27, 2017, 10:14:15 AM11/27/17
to libFM - Factorization Machines
I almost never used this perl script before. I think it's compatible with the format you have from the movielens dataset. Unfortunately with context I don't think you can use this script easily. The script is used when you have only one element by features and not a list like you have for context. You need to create your own converter. 
Thanks again!

To unsubscribe from this group and all its topics, send an email to libfm+un...@googlegroups.com.

fzl.l...@gmail.com

unread,
Nov 28, 2017, 5:21:27 AM11/28/17
to libFM - Factorization Machines
oh, that means that I have been in a wrong way for a while!

I wonder how they did in "Fast context-aware recommendations with factorization machines" ?


Thanks for help Thierry.

Thierry Silbermann

unread,
Nov 28, 2017, 10:51:11 AM11/28/17
to libFM - Factorization Machines
Just write your own code to do the transformation... You just have to do what I explained before.
Reply all
Reply to author
Forward
0 new messages