def forward_backward(self, x):
(src_seq, tgt_seq, src_valid_length, tgt_valid_length), batch_size = x<EOL>with mx.autograd.record():<EOL><INDENT>out, _ = self._model(src_seq, tgt_seq[:, :-<NUM_LIT:1>],<EOL>src_valid_length, tgt_valid_length - <NUM_LIT:1>)<EOL>smoothed_label = self._label_smoothing(tgt_seq[:, <NUM_LIT:1>:])<EOL>ls = self._loss(out, smoothed_label, tgt_valid_length - <NUM_LIT:1>).sum()<EOL>ls = (ls * (tgt_seq.shape[<NUM_LIT:1>] - <NUM_LIT:1>)) / batch_size / self._rescale_loss<EOL><DEDENT>ls.backward()<EOL>return ls<EOL>
Perform forward and backward computation for a batch of src seq and dst seq