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

Bug: AttributeError: 'MaskingTextSamplers' object has no attribute 'sampler_params' when using TextExplainer with MaskingTextSamplers #27

Open
nickt121 opened this issue Jun 20, 2022 · 0 comments

Comments

@nickt121
Copy link

When using the default values for TextExplainer, it fails reutrning:

AttributeError                            Traceback (most recent call last)
File ~\.conda\envs\eli5-pip\lib\site-packages\IPython\core\formatters.py:973, in MimeBundleFormatter.__call__(self, obj, include, exclude)
    970     method = get_real_method(obj, self.print_method)
    972     if method is not None:
--> 973         return method(include=include, exclude=exclude)
    974     return None
    975 else:

File ~\.conda\envs\eli5-pip\lib\site-packages\sklearn\base.py:629, in BaseEstimator._repr_mimebundle_(self, **kwargs)
    627 def _repr_mimebundle_(self, **kwargs):
    628     """Mime bundle used by jupyter kernels to display estimator"""
--> 629     output = {"text/plain": repr(self)}
    630     if get_config()["display"] == "diagram":
    631         output["text/html"] = estimator_html_repr(self)

File ~\.conda\envs\eli5-pip\lib\site-packages\sklearn\base.py:279, in BaseEstimator.__repr__(self, N_CHAR_MAX)
    271 # use ellipsis for sequences with a lot of elements
    272 pp = _EstimatorPrettyPrinter(
    273     compact=True,
    274     indent=1,
    275     indent_at_name=True,
    276     n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW,
    277 )
--> 279 repr_ = pp.pformat(self)
    281 # Use bruteforce ellipsis when there are a lot of non-blank characters
    282 n_nonblank = len("".join(repr_.split()))

File ~\.conda\envs\eli5-pip\lib\pprint.py:157, in PrettyPrinter.pformat(self, object)
    155 def pformat(self, object):
    156     sio = _StringIO()
--> 157     self._format(object, sio, 0, 0, {}, 0)
    158     return sio.getvalue()

File ~\.conda\envs\eli5-pip\lib\pprint.py:174, in PrettyPrinter._format(self, object, stream, indent, allowance, context, level)
    172     self._readable = False
    173     return
--> 174 rep = self._repr(object, context, level)
    175 max_width = self._width - indent - allowance
    176 if len(rep) > max_width:

File ~\.conda\envs\eli5-pip\lib\pprint.py:454, in PrettyPrinter._repr(self, object, context, level)
    453 def _repr(self, object, context, level):
--> 454     repr, readable, recursive = self.format(object, context.copy(),
    455                                             self._depth, level)
    456     if not readable:
    457         self._readable = False

File ~\.conda\envs\eli5-pip\lib\site-packages\sklearn\utils\_pprint.py:189, in _EstimatorPrettyPrinter.format(self, object, context, maxlevels, level)
    188 def format(self, object, context, maxlevels, level):
--> 189     return _safe_repr(
    190         object, context, maxlevels, level, changed_only=self._changed_only
    191     )

File ~\.conda\envs\eli5-pip\lib\site-packages\sklearn\utils\_pprint.py:452, in _safe_repr(object, context, maxlevels, level, changed_only)
    448 for k, v in items:
    449     krepr, kreadable, krecur = saferepr(
    450         k, context, maxlevels, level, changed_only=changed_only
    451     )
--> 452     vrepr, vreadable, vrecur = saferepr(
    453         v, context, maxlevels, level, changed_only=changed_only
    454     )
    455     append("%s=%s" % (krepr.strip("'"), vrepr))
    456     readable = readable and kreadable and vreadable

File ~\.conda\envs\eli5-pip\lib\site-packages\sklearn\utils\_pprint.py:440, in _safe_repr(object, context, maxlevels, level, changed_only)
    438 recursive = False
    439 if changed_only:
--> 440     params = _changed_params(object)
    441 else:
    442     params = object.get_params(deep=False)

File ~\.conda\envs\eli5-pip\lib\site-packages\sklearn\utils\_pprint.py:93, in _changed_params(estimator)
     89 def _changed_params(estimator):
     90     """Return dict (param_name: value) of parameters that were given to
     91     estimator with non-default values."""
---> 93     params = estimator.get_params(deep=False)
     94     init_func = getattr(estimator.__init__, "deprecated_original", estimator.__init__)
     95     init_params = inspect.signature(init_func).parameters

File ~\.conda\envs\eli5-pip\lib\site-packages\sklearn\base.py:211, in BaseEstimator.get_params(self, deep)
    209 out = dict()
    210 for key in self._get_param_names():
--> 211     value = getattr(self, key)
    212     if deep and hasattr(value, "get_params"):
    213         deep_items = value.get_params().items()

AttributeError: 'MaskingTextSamplers' object has no attribute 'sampler_params'

Or alternative non jupyter run:

C:\Users\admin\.conda\envs\eli5-pip\lib\site-packages\sklearn\linear_model\_stochastic_gradient.py:173: FutureWarning: The loss 'log' was deprecated in v1.1 and will be removed in version 1.3. Use `loss='log_loss'` which is equivalent.
  warnings.warn(
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\admin\.conda\envs\eli5-pip\lib\site-packages\sklearn\base.py", line 279, in __repr__
    repr_ = pp.pformat(self)
  File "C:\Users\admin\.conda\envs\eli5-pip\lib\pprint.py", line 157, in pformat
    self._format(object, sio, 0, 0, {}, 0)
  File "C:\Users\admin\.conda\envs\eli5-pip\lib\pprint.py", line 174, in _format
    rep = self._repr(object, context, level)
  File "C:\Users\admin\.conda\envs\eli5-pip\lib\pprint.py", line 454, in _repr
    repr, readable, recursive = self.format(object, context.copy(),
  File "C:\Users\admin\.conda\envs\eli5-pip\lib\site-packages\sklearn\utils\_pprint.py", line 189, in format
    return _safe_repr(
  File "C:\Users\admin\.conda\envs\eli5-pip\lib\site-packages\sklearn\utils\_pprint.py", line 452, in _safe_repr
    vrepr, vreadable, vrecur = saferepr(
  File "C:\Users\admin\.conda\envs\eli5-pip\lib\site-packages\sklearn\utils\_pprint.py", line 440, in _safe_repr
    params = _changed_params(object)
  File "C:\Users\admin\.conda\envs\eli5-pip\lib\site-packages\sklearn\utils\_pprint.py", line 93, in _changed_params
    params = estimator.get_params(deep=False)
  File "C:\Users\admin\.conda\envs\eli5-pip\lib\site-packages\sklearn\base.py", line 211, in get_params
    value = getattr(self, key)
AttributeError: 'MaskingTextSamplers' object has no attribute 'sampler_params'

This seems to be more of an issue relating to sklearn rather than to eli5 itself. However, an easy fix would be to include the sampler_params as an attribute in the MaskingTextSamplers class.

Do let me know if there is something that I have done wrong here.

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