salesforce / OmniXAI

OmniXAI: A Library for eXplainable AI
BSD 3-Clause "New" or "Revised" License
863 stars 92 forks source link

Error in NLP example #62

Closed SeibertronSS closed 1 year ago

SeibertronSS commented 1 year ago

I used the NLP example in https://github.com/salesforce/OmniXAI/blob/main/tutorials/nlp.ipynb, but I got the error

Traceback (most recent call last):
  File "/export/home/x/python_test/omnixai/text/nlp.py", line 42, in <module>
    local_explanations = explainer.explain(x)
  File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/omnixai/explainers/base.py", line 276, in explain
    explanations = OrderedDict({"predict": self.predict(X)})
  File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/omnixai/explainers/base.py", line 252, in predict
    predictions = self.predict_function(self._convert_data(X))
  File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/omnixai/utils/misc.py", line 219, in _predict
    return tensor_to_numpy(postprocess(predict_func(*inputs)))
  File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/transformers/pipelines/text_classification.py", line 125, in __call__
    result = super().__call__(*args, **kwargs)
  File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/transformers/pipelines/base.py", line 1026, in __call__
    return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
  File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/transformers/pipelines/base.py", line 1032, in run_single
    model_inputs = self.preprocess(inputs, **preprocess_params)
  File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/transformers/pipelines/text_classification.py", line 134, in preprocess
    return self.tokenizer(inputs, return_tensors=return_tensors, **tokenizer_kwargs)
  File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 2451, in __call__
    raise ValueError(
ValueError: text input must of type `str` (single example), `List[str]` (batch or single pretokenized example) or `List[List[str]]` (batch of pretokenized examples).

I found that the values of the Text class are used in many places in the program and the Text object is still returned

    @property
    def values(self):
        """
        Returns the raw text data.

        :return: A list of the sentences/texts.
        :rtype: List
        """
        return self.data
SeibertronSS commented 1 year ago

It seems that many NLP examples do not work

yangwenz commented 1 year ago

Hi, which version of omnixai has been used?

On Thu, 29 Dec 2022 at 9:15 PM, SeibertronSS @.***> wrote:

''' Traceback (most recent call last): File "/export/home/x/python_test/omnixai/text/nlp.py", line 4, in from omnixai.explainers.nlp import NLPExplainer File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/omnixai/explainers/nlp/ init.py", line 9, in from .agnostic.shap import ShapText File "/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/omnixai/explainers/nlp/agnostic/shap.py", line 11, in import shap File "/export/home/x/python_test/omnixai/text/shap.py", line 3, in from omnixai.explainers.nlp import ShapText ImportError: cannot import name 'ShapText' from partially initialized module 'omnixai.explainers.nlp' (most likely due to a circular import) (/export/home/x/miniconda3/envs/kf/lib/python3.9/site-packages/omnixai/explainers/nlp/ init.py) '''

— Reply to this email directly, view it on GitHub https://github.com/salesforce/OmniXAI/issues/62#issuecomment-1367312297, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZWA6KDKT5LQIZNSWCYYTLWPWFI5ANCNFSM6AAAAAATMCDADQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

SeibertronSS commented 1 year ago

I use the omnixai=1.2.3

SeibertronSS commented 1 year ago

@yangwenz which version should I use?

yangwenz commented 1 year ago

We are checking the issue, and will make an update later.

On Tue, Jan 3, 2023 at 9:19 AM SeibertronSS @.***> wrote:

@yangwenz https://github.com/yangwenz which version should I use?

— Reply to this email directly, view it on GitHub https://github.com/salesforce/OmniXAI/issues/62#issuecomment-1369308421, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZWA6PBVRVDURKP5GDP4C3WQN5B5ANCNFSM6AAAAAATMCDADQ . You are receiving this because you were mentioned.Message ID: @.***>

SeibertronSS commented 1 year ago

Thank you!

yangwenz commented 1 year ago

The issue has been fixed, please update to v1.2.4.

SeibertronSS commented 1 year ago

Thanks for the quick fix, it helps me a lot.