|
| 1 | +import os |
| 2 | +import uuid |
| 3 | +import shutil |
| 4 | +from pathlib import Path |
| 5 | +from urllib.parse import urlparse |
| 6 | + |
| 7 | +from sklearn.metrics import accuracy_score |
| 8 | +import requests |
| 9 | +import pandas as pd |
| 10 | +import matplotlib.pyplot as plt |
| 11 | +import numpy as np |
| 12 | +from jiwer import wer |
| 13 | +import datasets |
| 14 | +from renumics.spotlight import Image, Audio |
| 15 | +from sliceguard import data |
| 16 | + |
| 17 | +from sliceguard import SliceGuard |
| 18 | + |
| 19 | + |
| 20 | +def wer_metric(y_true, y_pred): |
| 21 | + return np.mean([wer(s_y, s_pred) for s_y, s_pred in zip(y_true, y_pred)]) |
| 22 | + |
| 23 | + |
| 24 | +def test_huggingface_mnist(): |
| 25 | + df = data.from_huggingface("mnist") |
| 26 | + |
| 27 | + sg = SliceGuard() |
| 28 | + issue_df = sg.find_issues( |
| 29 | + df.sample(100), |
| 30 | + ["image"], |
| 31 | + y="label", |
| 32 | + metric=accuracy_score, |
| 33 | + metric_mode="max", |
| 34 | + min_support=10, |
| 35 | + min_drop=0.08, |
| 36 | + ) |
| 37 | + |
| 38 | + sg.report(spotlight_dtype={"image_path": Image}) |
| 39 | + |
| 40 | + |
| 41 | +def test_huggingface_butterflies(): |
| 42 | + df = data.from_huggingface("ceyda/smithsonian_butterflies") |
| 43 | + |
| 44 | + sg = SliceGuard() |
| 45 | + issue_df = sg.find_issues( |
| 46 | + df, |
| 47 | + ["image"], |
| 48 | + y="scientific_name", |
| 49 | + metric=accuracy_score, |
| 50 | + metric_mode="max", |
| 51 | + min_support=10, |
| 52 | + min_drop=0.08, |
| 53 | + automl_train_split="train", |
| 54 | + automl_task="classification", |
| 55 | + automl_time_budget=40.0, |
| 56 | + ) |
| 57 | + |
| 58 | + sg.report(spotlight_dtype={"image_path": Image}) |
| 59 | + |
| 60 | + |
| 61 | +def test_huggingface_dead_by_daylight_perks(): |
| 62 | + df = data.from_huggingface("GabrielVidal/dead-by-daylight-perks") |
| 63 | + |
| 64 | + sg = SliceGuard() |
| 65 | + issue_df = sg.find_issues( |
| 66 | + df, |
| 67 | + ["image"], |
| 68 | + y="type", |
| 69 | + metric=accuracy_score, |
| 70 | + metric_mode="max", |
| 71 | + min_support=10, |
| 72 | + min_drop=0.08, |
| 73 | + automl_train_split="train", |
| 74 | + automl_task="classification", |
| 75 | + # automl_use_full_embeddings=True, |
| 76 | + automl_time_budget=40.0, |
| 77 | + ) |
| 78 | + |
| 79 | + sg.report(spotlight_dtype={"image_path": Image}) |
| 80 | + |
| 81 | + |
| 82 | +def test_huggingface_dog_dataset(): |
| 83 | + df = data.from_huggingface("437aewuh/dog-dataset") |
| 84 | + |
| 85 | + sg = SliceGuard() |
| 86 | + issue_df = sg.find_issues( |
| 87 | + df.sample(200), |
| 88 | + ["audio"], |
| 89 | + "label", |
| 90 | + metric=accuracy_score, |
| 91 | + metric_mode="max", |
| 92 | + embedding_models={"path": "superb/wav2vec2-base-superb-sid"}, |
| 93 | + min_support=5, |
| 94 | + min_drop=0.1, |
| 95 | + ) |
| 96 | + sg.report(spotlight_dtype={"path": Audio}) |
| 97 | + |
| 98 | + |
| 99 | +def test_huggingface_modeling(): |
| 100 | + df = data.from_huggingface("Gae8J/modeling") |
| 101 | + |
| 102 | + sg = SliceGuard() |
| 103 | + issue_df = sg.find_issues( |
| 104 | + df.sample(200), |
| 105 | + ["audio"], |
| 106 | + "label", |
| 107 | + metric=accuracy_score, |
| 108 | + metric_mode="max", |
| 109 | + automl_train_split="train", |
| 110 | + automl_task="classification", |
| 111 | + automl_time_budget=40.0, |
| 112 | + ) |
| 113 | + sg.report(spotlight_dtype={"path": Audio}) |
| 114 | + |
| 115 | + |
| 116 | +def test_huggingface_piano(): |
| 117 | + df = data.from_huggingface("ccmusic-database/piano_sound_quality") |
| 118 | + |
| 119 | + sg = SliceGuard() |
| 120 | + issue_df = sg.find_issues( |
| 121 | + df.sample(200), |
| 122 | + ["audio"], |
| 123 | + "label", |
| 124 | + metric=accuracy_score, |
| 125 | + metric_mode="max", |
| 126 | + automl_train_split="train", |
| 127 | + automl_task="classification", |
| 128 | + # automl_use_full_embeddings=True, |
| 129 | + automl_time_budget=40.0, |
| 130 | + ) |
| 131 | + sg.report(spotlight_dtype={"path": Audio}) |
| 132 | + |
| 133 | + |
| 134 | +def test_huggingface_xtreme(): |
| 135 | + df = data.from_huggingface("xtreme", "XNLI") |
| 136 | + sg = SliceGuard() |
| 137 | + issue_df = sg.find_issues( |
| 138 | + df.sample(1000), |
| 139 | + ['language'], |
| 140 | + "gold_label", |
| 141 | + metric=accuracy_score, |
| 142 | + min_drop=0.05, |
| 143 | + min_support=10, |
| 144 | + automl_task="classification", |
| 145 | + automl_time_budget=40.0, |
| 146 | + ) |
| 147 | + sg.report() |
| 148 | + |
| 149 | + |
| 150 | +def test_huggingface_indonlu(): |
| 151 | + df = data.from_huggingface("indonlp/indonlu", "smsa") |
| 152 | + sg = SliceGuard() |
| 153 | + issue_df = sg.find_issues( |
| 154 | + df.sample(1000), |
| 155 | + ['text'], |
| 156 | + "label", |
| 157 | + metric=accuracy_score, |
| 158 | + min_drop=0.05, |
| 159 | + min_support=10, |
| 160 | + automl_train_split="train", |
| 161 | + automl_task="classification", |
| 162 | + automl_time_budget=40.0, |
| 163 | + ) |
| 164 | + sg.report() |
| 165 | + |
| 166 | + |
| 167 | +def test_huggingface_tweet_eval(): |
| 168 | + df = data.from_huggingface("tweet_eval", "emoji") |
| 169 | + sg = SliceGuard() |
| 170 | + issue_df = sg.find_issues( |
| 171 | + df.sample(1000), |
| 172 | + ['text'], |
| 173 | + "label", |
| 174 | + metric=accuracy_score, |
| 175 | + # metric_mode="max", |
| 176 | + # wer_metric, |
| 177 | + # metric_mode="min", |
| 178 | + min_drop=0.05, |
| 179 | + min_support=10, |
| 180 | + # automl_split_key="", |
| 181 | + automl_train_split="train", |
| 182 | + automl_task="classification", |
| 183 | + # automl_use_full_embeddings=True, |
| 184 | + automl_time_budget=40.0, |
| 185 | + ) |
| 186 | + sg.report() |
| 187 | + |
| 188 | + |
| 189 | +# Image: |
| 190 | +test_huggingface_mnist() |
| 191 | +# test_huggingface_butterflies() |
| 192 | +# test_huggingface_dead_by_daylight_perks() |
| 193 | + |
| 194 | +# Audio: |
| 195 | +# test_huggingface_dog_dataset() |
| 196 | +# test_huggingface_modeling() |
| 197 | +# test_huggingface_piano() |
| 198 | + |
| 199 | +# Text: |
| 200 | +# test_huggingface_xtreme() |
| 201 | +# test_huggingface_indonlu() |
| 202 | +# test_huggingface_tweet_eval() |
0 commit comments