I've developed a text classifier of the form of python function that can input a np.array of strings (each string is one observation).
def model(vector_of_strins):
... # do smthg
return vec_of_probabilities # like [0.1, 0.23, ..., 0.09]
When I try to use KernelExplainer
from shap
package like that
test_texts = pd.Series(['text1','text2','text3'])
shap.KernelExplainer(model, test_texts )
I receive the following error:
AttributeError: 'numpy.ndarray' object has no attribute 'find'
What can I do about it?
Since there is no information about the model function provided, I'm assuming that it iterates the strings and tries to use the
find
method on them to assign probabilities.The
KernelExplainer
method calls the model function by passing the samples as the first argument, the input array shape is#samples x #features
. In your case it will be(1,3)
, so trying to iterate over the array will give you the inner array.Try to adapt your code to work with 2d arrays. Or in your case to make a quick fix, just iterate over
vector_of_strins[0]
.