1

I am working on a BERT model for text classification and wish to use TextExplainer for model interpretation. However, when loading the library eli5.lime I receive the following error:

ImportError: cannot import name 'itemfreq' from 'scipy.stats'

It appears that scipy.stats.itemfreq is deprecated and was removed from the latest version of the scipy package. Anyone come across this issue? I note the suggestion is to use np.unique(…, return_counts=True) instead, however, this means updating samplers.py (which I have tried, but came across another indexing error).

Wondering if anyone has come across this one?

Michael S.
  • 3,050
  • 4
  • 19
  • 34

1 Answers1

4
import scipy
import numpy as np
def monkeypath_itemfreq(sampler_indices):
   return zip(*np.unique(sampler_indices, return_counts=True))

scipy.stats.itemfreq=monkeypath_itemfreq
f l
  • 1,684
  • 2
  • 10
  • 11
  • 1
    Despite your code sample solving the original problem, it is important to describe in more detail how it solves that problem. – Maciej Gol Oct 31 '22 at 22:36