'Update or predict on a batch of examples.
More efficient than act().'

def batch_act(self, observations):

    if self.is_shared:
        raise RuntimeError('Parallel    act    is    not    supported.')
    batchsize = len(observations)
    batch_reply = [{'id': self.getID()} for _ in range(batchsize)]
    examples = [self._build_ex(obs) for obs in observations]
    valid_inds = [i for i in range(batchsize) if (examples[i] is not None)]
    examples = [ex for ex in examples if (ex is not None)]
    if (len(examples) == 0):
        return batch_reply
    batch = batchify(examples, null=self.word_dict[self.word_dict.null_token], cuda=self.opt['cuda'])
    if ('labels' in observations[0]):
        self.n_examples += len(examples)
        self.model.update(batch)
    else:
        predictions = self.model.predict(batch)
        for i in range(len(predictions)):
            batch_reply[valid_inds[i]]['text'] = predictions[i]
    return batch_reply
