<jupyter_start><jupyter_text>WaveNet Training<jupyter_code>from model import WaveNetModel, Optimizer, WaveNetData

import torch
import numpy as np
import time

from IPython.display import Audio
from IPython.core.debugger import Tracer
from matplotlib import pyplot as plt
from matplotlib import pylab as pl
from IPython import display

%matplotlib notebook<jupyter_output><empty_output><jupyter_text>Setup Model<jupyter_code>train_sample = "train_samples/saber.wav"
layers = 10
blocks = 2
classes = 128
hidden_channels = 32
kernel_size = 8

use_cuda = torch.cuda.is_available()
model = WaveNetModel(num_layers=layers,
                     num_blocks=blocks,
                     num_classes=classes,
                     hidden_channels=hidden_channels,
                     kernel_size=kernel_size)

if use_cuda:
    model.cuda()
    print("use cuda")

#print("model: ", model)
print("scope: ", model.scope)
print(model.parameter_count(), " parameters")

data = WaveNetData(train_sample,
                   input_length=model.scope,
                   target_length=model.last_block_scope,
                   num_classes=model.num_classes,
                   cuda=use_cuda)
start_tensor = data.get_minibatch([model.scope])[0].squeeze()

plt.ion()
plt.plot(start_tensor[-200:].numpy())
plt.ioff()<jupyter_output><empty_output><jupyter_text>Train Model<jupyter_code>learning_rate = 0.001
mini_batch_size = 4
avg_length = 4
epochs = 100
optimizer = Optimizer(model,
                      learning_rate=learning_rate,
                      stop_threshold=0.1,
                      avg_length=avg_length,
                      mini_batch_size=mini_batch_size)

def hook(losses):
    ax.clear()
    ax.plot(losses)
    fig.canvas.draw()
    
optimizer.hook = hook
fig = plt.figure()
ax = fig.add_subplot(111)
plt.ion()

fig.show()
fig.canvas.draw()

print('start training...')
tic = time.time()
optimizer.train(data, epochs=epochs)
toc = time.time()
print('Training took {} seconds.'.format(toc-tic))
torch.save(model.state_dict(), "model_parameters/saber_10-2-128-32-8")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10777300906056271, 'fraction_numerical': 0.017167381974248927, 'mean_word_length': 3.3526970954356847, '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': '557663', 'license': 'MIT', 'n_tokens_mistral': 741, 'n_tokens_neox': 686, 'n_words': 124, 'path': 'notebooks/WavenetTrain.ipynb', 'repo_name': 'tusharhero/pytorch-wavenet', 'size': '2097'}