Coder Social home page Coder Social logo

Add Ranking Example about fastfm HOT 5 OPEN

ibayer avatar ibayer commented on May 27, 2024
Add Ranking Example

from fastfm.

Comments (5)

ibayer avatar ibayer commented on May 27, 2024 3

Ok,
fastFM uses the Bayesian Personalized Ranking [0] (BPR) loss with stochastic gradient descent (SGD) for ranking. Usually for SGD you calculate the gradient for each sample and then update the parameter; for a pairwise loss the gradient is calculated for a pair of samples.

Let's assume that we have only 1 query and 3 items. Each user / item can be represented by a vector x, and we construct an example by concatenating x = [x_query, x_item] query and item vectors.
We further know that item1 is the only correct answer, we therefore want the model returns the highest value for x = [x_query1, x_item1].

training

fastFM needs two input files for training:
The first lists all samples (see: https://github.com/ibayer/fastFM-core/blob/master/demo/data/train_ranking)

    query1, item1
    query1, item2
    query1, item3

The second lists all possible pairs (i, j) such that sample_i > sample_j. This would
be

   0 1
   0 2

in our example (see: https://github.com/ibayer/fastFM-core/blob/master/demo/data/train_pairs)

test / prediction

We have learned a factorization machine with BPR that behaves like a scoring function.
We can now use this model like a regression model (per user) except that we use the prediction to sort the
samples. Back to our example: if we would like to know if item2 is better then item3 for query1 we construct the following input (X_test):

    query1, item2
    query1, item3

and evaluate the model

    y_pred = fm.predict(X_test)

We can now check if y_pred[0] > y_pred[1] to answer the question if item2 is better then item3 for query1.

Does this make sense?

from fastfm.

ibayer avatar ibayer commented on May 27, 2024

It's more a matter of time. But you are right it's a great idea to add a ranking example to the tutorial (http://ibayer.github.io/fastFM/index.html).

In the mean time you could have a look at https://github.com/ibayer/fastFM/blob/master/fastFM/tests/test_ranking.py .

from fastfm.

BrianMiner avatar BrianMiner commented on May 27, 2024

An example would be helpful. I am not sure how to structure the X and y. I have seen where each record is a (e.g. features for a query document pair) along with a single relevance rating and then there is an external file or an ID on the record that tells how to group the records into (e.g. queries). That doesnt seem to be the case here though,

from fastfm.

wzhd avatar wzhd commented on May 27, 2024

Thanks for your explanation. However, I'm confused by the first input file train_ranking.

0:6 1:1
0:2 1:3
0:3
0:6 1:1
0:4 1:5

The third line appears different.

from fastfm.

ibayer avatar ibayer commented on May 27, 2024

You can read the third line as: query with value of 3 for feature 0 and item with only zero valued features.
I agree that having an item with only zero valued features is a bit confusing.

from fastfm.

Related Issues (20)

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.