[BUG] TF-IDF tfidf_utils.py due to numpy deprecation of scalar conversion of ndim > 1 arrays

Author: Baccano01Created Jun 19, 2026Updated Jun 19, 2026
Labelsbug

Description

Minor bug in tfidf_utils.py when running tfidf_covid.ipynb notebook on local machine, in particular getting the top-k recommendations:

cols_to_keep = ['title','authors','journal','publish_time','url']
recommender.get_top_k_recommendations(metadata_public,article_of_interest,cols_to_keep)

Due to the following of code in the tfidf model: https://github.com/recommenders-team/recommenders/blob/6232b154548c955315650d58dca6bf1411c56020/recommenders/models/tfidf/tfidf_utils.py#L330 because of the deprecation of converting ndim > 0 arrays to scalar in numpy 1.25;

np.where(metadata[self.id_col] == rec_id)[0] returns an array of ndim 1.

In which platform does it happen?

Environment

OS: Debian GNU/Linux 12 (bookworm) Platform: Jupyter Lab. Python: 3.11.2 Numpy: 2.4.6 PyTorch: 2.12.1+cpu

How do we replicate the issue?

  1. Follow getting started section of README.
  2. Update torch to latest version to be able to use the models and not just tokenizers.
  3. Execute all cells of the tfidf_covid.ipynb notebook on Debian 12 using Jupyter Lab.
  4. TypeError raised when running following cell:
cols_to_keep = ['title','authors','journal','publish_time','url']
recommender.get_top_k_recommendations(metadata_public,article_of_interest,cols_to_keep)

Expected behavior (i.e. solution)

Executing cell

cols_to_keep = ['title','authors','journal','publish_time','url']
recommender.get_top_k_recommendations(metadata_public,article_of_interest,cols_to_keep)

should give

Willingness to contribute

  • [ x] Yes, I can contribute for this issue independently.
  • Yes, I can contribute for this issue with guidance from Recommenders community.
  • No, I cannot contribute at this time.

Other Comments

Source: recommenders-team/recommenders