Function
ids_tensor
(shape, vocab_size, rng=None, name=None)
Source from the content-addressed store, hash-verified
| 27 | |
| 28 | |
| 29 | def ids_tensor(shape, vocab_size, rng=None, name=None): |
| 30 | # Creates a random int32 tensor of the shape within the vocab size |
| 31 | if rng is None: |
| 32 | rng = random.Random() |
| 33 | |
| 34 | total_dims = 1 |
| 35 | for dim in shape: |
| 36 | total_dims *= dim |
| 37 | |
| 38 | values = [] |
| 39 | for _ in range(total_dims): |
| 40 | values.append(rng.randint(0, vocab_size - 1)) |
| 41 | |
| 42 | return paddle.to_tensor(data=values).reshape(shape) |
| 43 | |
| 44 | |
| 45 | class StoppingCriteriaTestCase(unittest.TestCase): |
Tested by
no test coverage detected