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

No datapoints are loaded #200

Open
isaavedr opened this issue Feb 23, 2022 · 11 comments
Open

No datapoints are loaded #200

isaavedr opened this issue Feb 23, 2022 · 11 comments

Comments

@isaavedr
Copy link

Hi I've made this tutorial https://codelabs.developers.google.com/vertex-xgb-wit#6
and the widget showed up without any data.

I checked the variables and they do have data.

Any clue?

Thanks

@bokey007
Copy link

Hi Issavedr,

I am facing ths same isuue.

were you able to fix this?

@isaavedr
Copy link
Author

isaavedr commented Feb 24, 2022 via email

@jameswex
Copy link
Collaborator

Thx I see this issue in Vertex AI notebooks and will take a look later this week to figure out root cause. Note that if you run WIT in a colab notebook (including running the code from that codelab in a colab notebook), then the issue does not occur and WIT works correctly,

@isaavedr
Copy link
Author

isaavedr commented Mar 1, 2022 via email

@jameswex
Copy link
Collaborator

jameswex commented Mar 9, 2022

Update: I'm working with the vertex notebook team to debug the issue, which seems specific to user-managed vertex ai notebooks.

@isaavedr
Copy link
Author

isaavedr commented Mar 9, 2022 via email

@Lagyamfi
Copy link

Hello @jameswex,
Please did you manage to find something on this?
I am trying to use the tool in a jupyter notebook and I have the same issue of the datapoints not being loaded.

Thanks

@jameswex
Copy link
Collaborator

I'm not aware of any issue in plain jupyter notebooks. Can you provide the versions you are using for jupyter and wit packages, how you installed them, and the extra repro steps? Thanks.

@Lagyamfi
Copy link

Thanks for the response. Please see below an extract from pip freeze for the jupyter and wit packages.

ipywidgets==7.6.5
jupyter==1.0.0
jupyter-console==6.4.4
jupyter-events==0.5.0
jupyter-http-over-ws==0.0.8
jupyter_client==7.4.8
jupyter_core==5.1.0
jupyter_server==2.0.1
jupyter_server_terminals==0.4.3
jupyterlab==3.5.2
jupyterlab-pygments==0.2.2
jupyterlab-widgets==3.0.4
jupyterlab_server==2.16.5
tensorboard-plugin-wit==1.8.1
witwidget==1.8.1

I had to downgrade the version of ipywidgets as the current one throws an error and from research online, it was recommended to use this earlier version. This at least gets the interface of wit to show up in the notebook.

Below is the code I am using. Unfortunately, I am using a locally developed library to train a classifier on hand digit mnist (2 classes). The resulting model has been used as part of the custom prediction method to get the scores (+ve and -ve) as recommended by the documentation of WIT.
My apologies if this doesn't seem very clear, please do let me know and I can clarify further.

Here is a sample example:

[[53.120157671281945,
-857.0493307492923,
-109.8069419594235,
-274.555738628991,
-204.97336557630445,
202.33888335660188,
-176.25513572375775,
-128.4388742491278,
159.347149510081,
-422.8094843022451,
-331.26089283500795,
-28.659245603962823,
278.5315796154663,
121.26575661261623,
-110.60426745594283,
13.71391025724078,
-44.75038992818486,
-200.75934837235405,
139.31024792675947,
220.73746273924493,
-252.97602862444694,
-9.806797422601875,
-11.398082106434003,
55.20888976854012,
109.41289220868214,
60.783656395467354,
115.82475478587398,
67.32505234655636,
140.9193922831989,
-82.84561756262917,
9.0],]

Here is a sample out from custom_predict_2:
[[4.76837158203125e-07, 0.9999995],]

from counterfactuals import Data, Model
import pandas as pd
import numpy as np
import tensorflow as tf

import torch
import torch.nn.functional as nnf

dataframe = pd.read_csv("20-12-22_WIT_test/data/train.csv")
classes_required = (4, 9)
sub_df = dataframe[dataframe['label'].isin(classes_required)]

split_size = 0.2
n_components = 30
data = Data.Data(sub_df)
data.split(split_size)
data.pca(n_components=n_components)
train_x = data._pca_train_x
train_y = data._train_y
val_x = data._pca_val_x
val_y = data._val_y

# define and train classifier

hidden_layers = [512, 256, 128]
num_epochs = 20
ml_model_1 = Model.Model(backend="pytorch")
ml_model_1.set_up(n_components, *hidden_layers)
ml_model_1.trainer(train_x, train_y, val_x, val_y, epochs=num_epochs)

# prepare data for WIT - input will be a list of the values

data = val_x.copy()
data['label'] = val_y.values

label_column = "label"

input_features = val_x.columns.tolist()
features_and_labels = input_features + [label_column]

cols_not_for_model = data.columns.get_loc(label_column)

def custom_predict_2(examples_to_infer):
    results = []
    model_inps = np.delete(np.array(examples_to_infer), cols_not_for_model, axis=1)
    preds = nnf.softmax(ml_model_1._model(torch.tensor(model_inps, dtype=torch.float32)), dim=1).topk(1, dim=1)[0]
    preds = preds.detach().numpy()
    preds = [[1-pred[0], pred[0]] for pred in preds]
    return preds

examples = data.values.tolist()

from witwidget.notebook.visualization import WitWidget, WitConfigBuilder
num_datapoints = 1000 
tool_height_in_px = 720 


# Setup the tool with the test examples and the trained classifier
config_builder = WitConfigBuilder(
    examples).set_custom_predict_fn(
    custom_predict_2).set_label_vocab([4, 9])

WitWidget(config_builder, height=tool_height_in_px)

Please let me know if this helps or if I need to add some further information. Thanks a lot.

@jameswex
Copy link
Collaborator

This is helpful @Lagyamfi , thanks. I also am struggling to get WIT working in a jupyter notebook for me in a fresh environment right now. Unfortunately, we have moved on from regular development of the WIT tool, focusing instead on the newer and more-fully-featured and flexible LIT tool (https://pair-code.github.io/lit/, https://github.com/pair-code/lit).

I did verify that code similar to yours does load in WIT correctly when using Colab notebooks, which is one possible option for you.

You might also want to look into using LIT instead of WIT as it has more features and flexibility.

In the new year I do plan on updating the WIT website and repo to point people to the LIT tool as an alternative that is being actively developed.

@Lagyamfi
Copy link

Thanks a lot @jameswex for verifying this. You are right it turns to run with no issues on colab. I will check out the LIT tool.

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

4 participants