################
# EXAMPLE CODE #
################

# setup the mockingjay model
options = {
    'ckpt_file':
    'result/result_mockingjay/mockingjay_libri_sd1337_MelBase/mockingjay-500000.ckpt',
    'load_pretrain': 'True',
    'no_grad': 'False',
    'dropout': 'default'
}
model = MOCKINGJAY(options=options, inp_dim=160)

# setup your downstream class model
classifier = example_classifier(input_dim=768, hidden_dim=128,
                                class_num=2).cuda()

# construct the Mockingjay optimizer
params = list(model.named_parameters()) + list(classifier.named_parameters())
optimizer = get_mockingjay_optimizer(params=params,
                                     lr=4e-3,
                                     warmup_proportion=0.7,
                                     training_steps=50000)

# forward
example_inputs = torch.zeros(
    1200, 3,
    160)  # A batch of spectrograms: (time_step, batch_size, dimension)
reps = model(example_inputs)  # returns: (time_step, batch_size, hidden_size)
reps = reps.permute(1, 0,
                    2)  # change to: (batch_size, time_step, feature_size)
예제 #2
0
 def __init__(self, options):
     super(Model, self).__init__()
     self.model = MOCKINGJAY(options=options, inp_dim=160)
     self.classifier = example_classifier(input_dim=768, hidden_dim=128, class_num=133)