<jupyter_start><jupyter_text>CLR Callback<jupyter_code>from clr_scheduler import *<jupyter_output><empty_output><jupyter_text>Test Set<jupyter_code>from fastai.basics import *
class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()
        
        self.fc1 = nn.Linear(15, 10)
        self.fc2 = nn.Linear(10, 1)

    def forward(self, x):
        x = torch.relu(self.fc1(x))
        y_pred = torch.sigmoid(self.fc2(x))
        return y_pred.squeeze()
train_x = torch.rand(2000000, 15)
valid_x = torch.rand(2000000, 15)
train_y = torch.randint(0,2, (2000000,)).float()
valid_y = torch.randint(0,2, (2000000,)).float()
model = Net()
class ArrayDataset(Dataset):
    "Sample numpy array dataset"
    def __init__(self, x, y):
        self.x, self.y = x, y
        self.c = 2 # binary label
    
    def __len__(self):
        return len(self.x)
    
    def __getitem__(self, i):
        return self.x[i], self.y[i]
train_ds, valid_ds = ArrayDataset(train_x, train_y), ArrayDataset(valid_x, valid_y)
data = DataBunch.create(train_ds, valid_ds, bs=2000, num_workers=1)
criterion = nn.BCELoss()
learn = Learner(data, model, loss_func=criterion)<jupyter_output><empty_output><jupyter_text>Callback test<jupyter_code>lr = 0.001
learn.callbacks.append(CircularLRScheduler(learn, mode='triangular', base_lr=lr, max_lr=0.003, step_size=2000))
learn.fit(10)
learn.recorder.plot_lr()
learn.callbacks = []
learn.callbacks.append(CircularLRScheduler(learn, mode='triangular2', base_lr=0.001, max_lr=0.003, step_size=2000))

learn.fit(20)
learn.recorder.plot_lr()
learn.callbacks = []
learn.callbacks.append(CircularLRScheduler(learn, mode='exp_range', base_lr=0.001, max_lr=0.003, step_size=2000, gamma=0.99994))

learn.fit(20)
learn.recorder.plot_lr()
clr_fn = lambda x: 1/(5**(x*0.0001))
clr = CircularLRScheduler(learn,base_lr=0.001, max_lr=0.006,
                                step_size=2000., scale_fn=clr_fn,
                                scale_mode='iterations')
learn.callbacks = []                    
learn.fit(10, callbacks=[clr])
learn.recorder.plot_lr()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14468085106382977, 'fraction_numerical': 0.05815602836879433, 'mean_word_length': 3.990566037735849, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '565309', 'license': 'MIT', 'n_tokens_mistral': 882, 'n_tokens_neox': 806, 'n_words': 128, 'path': 'clr_callback_tests.ipynb', 'repo_name': 'mameli/CLR', 'size': '2115'}