Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value error for more then one word ? any work through ? #723

Open
Achinth04 opened this issue Jul 18, 2023 · 0 comments
Open

Value error for more then one word ? any work through ? #723

Achinth04 opened this issue Jul 18, 2023 · 0 comments

Comments

@Achinth04
Copy link

Achinth04 commented Jul 18, 2023

import torch.nn.functional as f
texts='i dont know'

def predictor(texts):
 token=tokenizer(texts, return_tensors="pt", padding=True).to(device)
 print(token)
 outputs = model(**token)
 print(type(outputs))
 probas = f.softmax(outputs.logits,dim=1).detach().cpu().numpy()
 return probas
print(predictor(texts))
stringpreds='Parth is'
exp=explainer.explain_instance(stringpreds,predictor,num_samples=10)

**when ever i include more than a word in the stringpreds i get a value error, it works perfectly fine for a single word i do not know what happens when i increase the word am using a layoutLMfortokenclassification model **

this the error i get:

[/usr/local/lib/python3.10/dist-packages/lime/lime_base.py](https://localhost:8080/#) in feature_selection(self, data, labels, weights, num_features, method)
    132             else:
    133                 n_method = 'highest_weights'
--> 134             return self.feature_selection(data, labels, weights,
    135                                           num_features, n_method)
    136 

[/usr/local/lib/python3.10/dist-packages/lime/lime_base.py](https://localhost:8080/#) in feature_selection(self, data, labels, weights, num_features, method)
    108             else:
    109                 weighted_data = coef * data[0]
--> 110                 feature_weights = sorted(
    111                     zip(range(data.shape[1]), weighted_data),
    112                     key=lambda x: np.abs(x[1]),

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant