MCPcopy Create free account
hub / github.com/apache/singa / train

Function train

examples/rnn/char_rnn.py:212–240  ·  view source on GitHub ↗
(data,
          max_epoch,
          hidden_size=100,
          seq_length=100,
          batch_size=16,
          model_path='model')

Source from the content-addressed store, hash-verified

210
211
212def train(data,
213 max_epoch,
214 hidden_size=100,
215 seq_length=100,
216 batch_size=16,
217 model_path='model'):
218 # SGD with L2 gradient normalization
219 cuda = device.create_cuda_gpu()
220 model = CharRNN(data.vocab_size, hidden_size)
221 model.graph(True, False)
222
223 inputs, labels = None, None
224
225 for epoch in range(max_epoch):
226 model.train()
227 train_loss = 0
228 for b in tqdm(range(data.num_train_batch)):
229 batch = data.train_dat[b * batch_size:(b + 1) * batch_size]
230 inputs, labels = convert(batch, batch_size, seq_length,
231 data.vocab_size, cuda, inputs, labels)
232 out, loss = model(inputs, labels)
233 model.reset_states(cuda)
234 train_loss += tensor.to_numpy(loss)[0]
235
236 print('\nEpoch %d, train loss is %f' %
237 (epoch, train_loss / data.num_train_batch / seq_length))
238
239 evaluate(model, data, batch_size, seq_length, cuda, inputs, labels)
240 sample(model, data, cuda)
241
242
243if __name__ == '__main__':

Callers 1

char_rnn.pyFile · 0.70

Calls 7

reset_statesMethod · 0.95
CharRNNClass · 0.70
convertFunction · 0.70
evaluateFunction · 0.70
sampleFunction · 0.70
graphMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected