PAIR-code / what-if-tool

Source code/webpage/demos for the What-If Tool
https://pair-code.github.io/what-if-tool
Apache License 2.0
892 stars 165 forks source link

No datapoints are loaded #200

Open isaavedr opened 2 years ago

isaavedr commented 2 years ago

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 commented 2 years ago

Hi Issavedr,

I am facing ths same isuue.

were you able to fix this?

isaavedr commented 2 years ago

unfortunately no

I think is related with package compatibility version. Any clue?

On Wed, Feb 23, 2022 at 10:38 PM Sudhir Deshmukh @.***> wrote:

Hi Issavedr,

I am facing ths same isuue.

were you able to fix this?

— Reply to this email directly, view it on GitHub https://github.com/PAIR-code/what-if-tool/issues/200#issuecomment-1049408423, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7LS3TPGSXQAPUKMT3Q2ZTU4WD3BANCNFSM5PES73DQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

jameswex commented 2 years ago

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 commented 2 years ago

Yes indeed, I tested in colab and it worked!

Thanks

On Mon, Feb 28, 2022 at 6:16 PM James Wexler @.***> wrote:

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,

— Reply to this email directly, view it on GitHub https://github.com/PAIR-code/what-if-tool/issues/200#issuecomment-1054669601, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7LS3UG7YJPWYDSDXA2QJDU5PQZBANCNFSM5PES73DQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

jameswex commented 2 years ago

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

isaavedr commented 2 years ago

Cool, thanks!

On Wed, 9 Mar 2022 at 11:59 James Wexler @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/PAIR-code/what-if-tool/issues/200#issuecomment-1063009021, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7LS3RZWB2YS3AEPFP4GCLU7C4EPANCNFSM5PES73DQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

Lagyamfi commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.