question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: Not all estimated parameters are finite, your model may have diverged

See original GitHub issue

Hi,

I’m running this very simple code:

def csr_values_analysis(values):
   num_zeros = 0
   num_ones = 0
   num_other = 0

   for v in values:
       if v == 0:
           num_zeros += 1
       elif v == 1:
           num_ones += 1
       else:
           num_other += 1

   return num_zeros, num_ones, num_other


print("Reading user_features.npz")
with open("/path/to/user_features.npz", "rb") as in_file:
    user_features_csr = sp.load_npz(in_file)
    print("User features read, shape: {}".format(user_features_csr.shape))
    print("Data values analysis: zeros: %i, ones: %i, other: %i" % csr_values_analysis(user_features_csr.data))

print("Reading item_features.npz")
with open("/path/to/item_features.npz", "rb") as in_file:
    item_features_csr = sp.load_npz(in_file)
    print("Item features read, shape: {}".format(item_features_csr.shape))
    print("Data values analysis: zeros: %i, ones: %i, other: %i" % csr_values_analysis(item_features_csr.data))

print("Reading interactions.npz")
with open("/path/to/interactions.npz", "rb") as in_file:
    interactions_csr = sp.load_npz(in_file)
    print("Interactions read, shape: {}".format(interactions_csr.shape))
    print("Data values analysis: zeros: %i, ones: %i, other: %i" % csr_values_analysis(interactions_csr.data))
    interactions_coo = interactions_csr.tocoo()

# Run lightfm

print("Running lightfm...")
model = LightFM(loss='warp')
model.fit(interactions_coo, user_features=user_features_csr, item_features=item_features_csr, epochs=20, num_threads=2, verbose=True)

With the following output:

Reading user_features.npz
User features read, shape: (827568, 105)
Data values analysis: zeros: 0, ones: 3153032, other: 0
Reading item_features.npz
Item features read, shape: (67339359, 36)
Data values analysis: zeros: 0, ones: 25259081, other: 0
Reading interactions.npz
Interactions read, shape: (827568, 67339359)
Data values analysis: zeros: 0, ones: 172388, other: 0
Running lightfm...
Epoch 0
Traceback (most recent call last):
  File "training.py", line 92, in <module>
    model.fit(interactions_coo, user_features=user_features_csr, item_features=item_features_csr, epochs=20, num_threads=2, verbose=True)
  File "/usr/lib64/python3.6/site-packages/lightfm/lightfm.py", line 479, in fit
    verbose=verbose)
  File "/usr/lib64/python3.6/site-packages/lightfm/lightfm.py", line 578, in fit_partial
    self._check_finite()
  File "/usr/lib64/python3.6/site-packages/lightfm/lightfm.py", line 413, in _check_finite
    raise ValueError("Not all estimated parameters are finite,"
ValueError: Not all estimated parameters are finite, your model may have diverged. Try decreasing the learning rate or normalising feature values and sample weights

All my Scipy matrices are normalized (i.e. the values are 0 or 1).

I’ve tried to change the learning schedule and the learning rate with no results.

I’ve checked this only occurs when I add the item features to the equation. There is no error when running lightfm only with interactions, or intereactions + user features.

AFAIK, I’ve installed the latest version:

$ pip freeze | grep lightfm
lightfm==1.15

Any idea? Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
maciejkulacommented, Mar 14, 2019

That’s some great debugging! It may be useful to add this cause as another suggestion in the error message.

0reactions
SimonCWcommented, Feb 25, 2021

Hi @dbalabka , the comments can still be discovered in the closed issues. The idea for closing issues that haven’t seen much activity, is to keep the focus on issues people are willing to work on and contribute. I added the enhancement label to make it easier to find in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

lightfm error: Not all estimated parameters are finite, your ...
ValueError: Not all estimated parameters are finite, your model may have diverged. Try decreasing the learning rate or normalising feature ...
Read more >
LightFM 1.16 documentation
In this case, LightFM reduces to a traditional collaborative filtering matrix ... "Not all estimated parameters are finite," " your model may have...
Read more >
lightfm-rec/Lobby - Gitter
I'm trying to build a recommender system where I have a set of item feature vectors that are real valued and dense, would...
Read more >
lyst - Bountysource
Hello to everyone! I'm implementing a LightFM model on a TV series dataset. I want to include user features on Binge-watcher users and...
Read more >
Source code for ultranest.integrator
logZ and not good_state: # stop as the results diverged already break if ... raise ValueError('file "%s" has parameters %s, expected %s, cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found