Problem with running WIT in a jupyter notebook

149 views
Skip to first unread message

gga...@gmail.com

unread,
Oct 22, 2019, 7:53:55 AM10/22/19
to What-If Tool
Hi,
I hope this i the right place to post this issue.
However, I'm getting an error from the constructor of WitWidget: "ValueError: Can't clean for JSON" (see full trace below).
I'm running on Windows 10Pro, with python 3.6 from anaconda distribution, on cpu.
I've tried using a clean conda environment, tried using JupyterLab, but I can't get around this.
I'd appreciate any help.

Thanks,
Guy.

-------------------------------------------------------------------------------------------------
full error trace:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-2ae7d512cb38> in <module>
      2 config_builder = WitConfigBuilder(test_examples).set_estimator_and_feature_spec(
      3     classifier, feature_spec).set_label_vocab(['Under 50K', 'Over 50K'])
----> 4 WitWidget(config_builder, height=tool_height_in_px)

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\witwidget\notebook\jupyter\wit.py in __init__(self, config_builder, height)
     61     """
     62     widgets.DOMWidget.__init__(self, layout=Layout(height='%ipx' % height))
---> 63     base.WitWidgetBase.__init__(self, config_builder)
     64     self.error_counter = 0
     65 

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\witwidget\notebook\base.py in __init__(self, config_builder)
     86       del copied_config['compare_adjust_attribution']
     87 
---> 88     self.config = copied_config
     89     self.set_examples(config['examples'])
     90     del copied_config['examples']

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\traitlets\traitlets.py in __set__(self, obj, value)
    583             raise TraitError('The "%s" trait is read-only.' % self.name)
    584         else:
--> 585             self.set(obj, value)
    586 
    587     def _validate(self, obj, value):

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\traitlets\traitlets.py in set(self, obj, value)
    572             # we explicitly compare silent to True just in case the equality
    573             # comparison above returns something other than True/False
--> 574             obj._notify_trait(self.name, old_value, new_value)
    575 
    576     def __set__(self, obj, value):

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\traitlets\traitlets.py in _notify_trait(self, name, old_value, new_value)
   1137             new=new_value,
   1138             owner=self,
-> 1139             type='change',
   1140         ))
   1141 

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipywidgets\widgets\widget.py in notify_change(self, change)
    603             if name in self.keys and self._should_send_property(name, getattr(self, name)):
    604                 # Send new state to front-end
--> 605                 self.send_state(key=name)
    606         super(Widget, self).notify_change(change)
    607 

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipywidgets\widgets\widget.py in send_state(self, key)
    487             state, buffer_paths, buffers = _remove_buffers(state)
    488             msg = {'method': 'update', 'state': state, 'buffer_paths': buffer_paths}
--> 489             self._send(msg, buffers=buffers)
    490 
    491 

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipywidgets\widgets\widget.py in _send(self, msg, buffers)
    735         """Sends a message to the model in the front-end."""
    736         if self.comm is not None and self.comm.kernel is not None:
--> 737             self.comm.send(data=msg, buffers=buffers)
    738 
    739     def _repr_keys(self):

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipykernel\comm\comm.py in send(self, data, metadata, buffers)
    121         """Send a message to the frontend-side version of this comm"""
    122         self._publish_msg('comm_msg',
--> 123             data=data, metadata=metadata, buffers=buffers,
    124         )
    125 

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipykernel\comm\comm.py in _publish_msg(self, msg_type, data, metadata, buffers, **keys)
     63         data = {} if data is None else data
     64         metadata = {} if metadata is None else metadata
---> 65         content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
     66         self.kernel.session.send(self.kernel.iopub_socket, msg_type,
     67             content,

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipykernel\jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipykernel\jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipykernel\jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipykernel\jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipykernel\jsonutil.py in json_clean(obj)
    175 
    176     if isinstance(obj, list):
--> 177         return [json_clean(x) for x in obj]
    178 
    179     if isinstance(obj, dict):

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipykernel\jsonutil.py in <listcomp>(.0)
    175 
    176     if isinstance(obj, list):
--> 177         return [json_clean(x) for x in obj]
    178 
    179     if isinstance(obj, dict):

c:\users\enduser\anaconda3\envs\py36\lib\site-packages\ipykernel\jsonutil.py in json_clean(obj)
    195 
    196     # we don't understand it, it's probably an unserializable object
--> 197     raise ValueError("Can't clean for JSON: %r" % obj)

ValueError: Can't clean for JSON: features {
  feature {
    key: "Age"
    value {
      int64_list {
        value: 25
      }
    }
  }
  feature {
    key: "Capital-Gain"
    value {
      int64_list {
        value: 0
      }
    }
  }
  feature {
    key: "Capital-Loss"
    value {
      int64_list {
        value: 0
      }
    }
  }
  feature {
    key: "Country"
    value {
      bytes_list {
        value: "United-States"
      }
    }
  }
  feature {
    key: "Education"
    value {
      bytes_list {
        value: "11th"
      }
    }
  }
  feature {
    key: "Education-Num"
    value {
      int64_list {
        value: 7
      }
    }
  }
  feature {
    key: "Hours-per-week"
    value {
      int64_list {
        value: 40
      }
    }
  }
  feature {
    key: "Marital-Status"
    value {
      bytes_list {
        value: "Never-married"
      }
    }
  }
  feature {
    key: "Occupation"
    value {
      bytes_list {
        value: "Machine-op-inspct"
      }
    }
  }
  feature {
    key: "Over-50K"
    value {
      int64_list {
        value: 0
      }
    }
  }
  feature {
    key: "Race"
    value {
      bytes_list {
        value: "Black"
      }
    }
  }
  feature {
    key: "Relationship"
    value {
      bytes_list {
        value: "Own-child"
      }
    }
  }
  feature {
    key: "Sex"
    value {
      bytes_list {
        value: "Male"
      }
    }
  }
  feature {
    key: "Workclass"
    value {
      bytes_list {
        value: "Private"
      }
    }
  }
  feature {
    key: "fnlwgt"
    value {
      int64_list {
        value: 226802
      }
    }
  }
}

James Wexler

unread,
Oct 28, 2019, 12:29:01 PM10/28/19
to What-If Tool
Thanks for pointing this out. It seems we had a regression for Jupyter notebooks in certain cases in witwidget 1.4.2 and will fix this and release a new patch version ASAP.

James Wexler

unread,
Oct 28, 2019, 3:18:21 PM10/28/19
to What-If Tool
We have released witwidget 1.4.5 which fixes this issue. Please update the let us know if the problem continues. Sorry for the trouble.

gga...@gmail.com

unread,
Oct 30, 2019, 10:57:34 AM10/30/19
to What-If Tool
Solved. thanks a lot!
Reply all
Reply to author
Forward
0 new messages