Esempio n. 1
0
# Python 2 and 3 compatibility
from __future__ import print_function, absolute_import, division, unicode_literals, with_statement

# In[ ]:

# Make sure python version is compatible with pyTorch
from cleanlab.util import VersionWarning

python_version = VersionWarning(
    warning_str="pyTorch supports Python version 2.7, 3.5, 3.6, 3.7.",
    list_of_compatible_versions=[2.7, 3.5, 3.6],
)

# In[ ]:

if python_version.is_compatible():  # pragma: no cover
    import argparse
    import torch
    import torch.nn as nn
    import torch.nn.functional as F
    import torch.optim as optim
    from torchvision import datasets, transforms
    from torch.autograd import Variable
    from torch.utils.data.sampler import SubsetRandomSampler
    import numpy as np

# In[ ]:

MNIST_TRAIN_SIZE = 60000
MNIST_TEST_SIZE = 10000
Esempio n. 2
0
            labels = z_list[:num_labels]
            content = " ".join(z_list[num_labels:])
            for l in labels:
                single_label_cook_data.append(l + " " + content)

        with open(data_dir + 'cooking.train.txt', 'w') as f:
            f.writelines(single_label_cook_data[:-5000])

        with open(data_dir + 'cooking.test.txt', 'w') as f:
            f.writelines(single_label_cook_data[-5000:])

        # Clean-up download files
        shutil.rmtree(data_dir + 'cooking')


if python_version.is_compatible():
    from fastText import train_supervised
    import cleanlab
    from cleanlab.models.fasttext import FastTextClassifier
    from sklearn.metrics import accuracy_score
    import numpy as np

    # Set-up for testing.
    import os
    cwd = os.getcwd()
    DATA_DIR = cwd + '/fasttext_data/'

    # Create train and test datasets for testing.
    create_cooking_dataset(DATA_DIR)

    # Load train text data