convert a batch of data into a sequence of input tensors
(batch,
batch_size,
seq_length,
vocab_size,
dev,
inputs=None,
labels=None)
| 144 | |
| 145 | |
| 146 | def convert(batch, |
| 147 | batch_size, |
| 148 | seq_length, |
| 149 | vocab_size, |
| 150 | dev, |
| 151 | inputs=None, |
| 152 | labels=None): |
| 153 | '''convert a batch of data into a sequence of input tensors''' |
| 154 | y = batch[:, 1:] |
| 155 | x1 = batch[:, :seq_length] |
| 156 | x = np.zeros((batch_size, seq_length, vocab_size), dtype=np.float32) |
| 157 | for b in range(batch_size): |
| 158 | for t in range(seq_length): |
| 159 | c = x1[b, t] |
| 160 | x[b, t, c] = 1 |
| 161 | return numpy2tensors(x, y, dev, inputs, labels) |
| 162 | |
| 163 | |
| 164 | def sample(model, data, dev, nsamples=100, use_max=False): |
no test coverage detected