File size: 1,364 Bytes
c6a85a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pickle
import datasets
import os
import umap


if __name__ == "__main__":
    cache_file = "dataset_cache.pkl"
    if os.path.exists(cache_file):
        # Load dataset from cache
        with open(cache_file, "rb") as file:
            dataset = pickle.load(file)
        print("Dataset loaded from cache.")
    else:
        # Load dataset using datasets.load_dataset()
        ds = datasets.load_dataset("renumics/cifar100-enriched", split="test")

        print("Dataset loaded using datasets.load_dataset().")

        df = ds.to_pandas()


        df = ds.rename_columns({"fine_label": "labels"}).to_pandas()
        from tabulate import tabulate
        from cleanlab import Datalab
        import pandas as pd
        import numpy as np


        lab = Datalab(data=ds, label_name="fine_label")
        features=np.array([x.tolist() for x in df["embedding"]])
        pred_probs= np.array([x.tolist() for x in df["probabilities"]])
        lab.find_issues(features=features,pred_probs=pred_probs)
        print(tabulate(lab.get_issues().iloc[[0,1,2,3,-3,-2,-1]], headers='keys', tablefmt='psql'))



        df_with_score = pd.concat([df, lab.get_issues()], axis=1)
        df = df_with_score


        # Save dataset to cache
        with open(cache_file, "wb") as file:
            pickle.dump(df, file)

        print("Dataset saved to cache.")