tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.26k stars 1.1k forks source link

KL Divergence for PlackettLuce throws an error #1133

Open LittleGoliathh opened 4 years ago

LittleGoliathh commented 4 years ago

Ok, so I'm trying to replicate the listnet and listmle loss functions (link) in keras/tensorflow, and in the above-mentioned link it says those loss functions rely on the Plackett Luce model, so that is how I got here. Now the docs say there should be support to calculate kl_divergence (see here), however when I try to calculate it, it throws me the following error::

NotImplementedError: No KL(distribution_a || distribution_b) registered for distribution_a type PlackettLuce and distribution_b type PlackettLuce

Code snippet:

`
def kl_loss(y_true, y_pred):

a_distr = tfp.distributions.PlackettLuce(y_true, tensorflow.float32)
b_distr = tfp.distributions.PlackettLuce(y_pred, tensorflow.float32)

return a_distr.kl_divergence(b_distr)`

So, I wonder has it not been implemented yet or am I doing something horribly wrong?

PS: Excuse me for any possible ignorance, I'm relatively new to tensorflow and still figuring things out

brianwa84 commented 4 years ago

Generally distributions where KL is implemented indicate which "other" distribution types are supported.

e.g. from https://www.tensorflow.org/probability/api_docs/python/tfp/distributions/Pareto?version=nightly other types with built-in registrations: Pareto

It's a bit of a documentation gap that when none exist, the method still exists and no notice is in place to indicate that there are no compatible 'other'.

You can find the exhaustive list of pairs here. https://www.tensorflow.org/probability/api_docs/python/tfp/distributions/kl_divergence?version=nightly

If you're aware of an analytic form for KL(PL || PL) we'd welcome a PR to add it. Otherwise, you could fall back to an empirical KL, namely samps=p.sample(n); emp_kl = tf.reduce_mean(p.log_prob(samps) - q.log_prob(samps), axis=0)

On Fri, Oct 16, 2020 at 8:38 PM LittleGoliathh notifications@github.com wrote:

Ok, so I'm trying to replicate the listnet and listmle loss functions (link) https://sutheeblog.wordpress.com/2017/03/10/listnet-and-listmle/ in keras/tensorflow, and in the above-mentioned link it says those loss functions rely on the Plackett Luce model, so that is how I got here. Now the docs say there should be support to calculate kl_divergence (see here) https://www.tensorflow.org/probability/api_docs/python/tfp/distributions/PlackettLuce, however when I try to calculate it, it throws me the following error::

NotImplementedError: No KL(distribution_a || distribution_b) registered for distribution_a type PlackettLuce and distribution_b type PlackettLuce

Code snippet:

` def kl_loss(y_true, y_pred):

a_distr = tfp.distributions.PlackettLuce(y_true, tensorflow.float32) b_distr = tfp.distributions.PlackettLuce(y_pred, tensorflow.float32)

return a_distr.kl_divergence(b_distr)`

So, I wonder has it not been implemented yet or am I doing something horribly wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tensorflow/probability/issues/1133, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJFSIYWZLX64XC4WNBK33TSLDRQZANCNFSM4ST7DTTQ .