Creates a random int32 tensor of the shape within the vocab size.
(cls, shape, vocab_size, rng=None, name=None)
| 145 | |
| 146 | @classmethod |
| 147 | def ids_tensor(cls, shape, vocab_size, rng=None, name=None): |
| 148 | """Creates a random int32 tensor of the shape within the vocab size.""" |
| 149 | if rng is None: |
| 150 | rng = random.Random() |
| 151 | |
| 152 | total_dims = 1 |
| 153 | for dim in shape: |
| 154 | total_dims *= dim |
| 155 | |
| 156 | values = [] |
| 157 | for _ in range(total_dims): |
| 158 | values.append(rng.randint(0, vocab_size - 1)) |
| 159 | |
| 160 | return tf.constant(value=values, dtype=tf.int32, shape=shape, name=name) |
| 161 | |
| 162 | def assert_all_tensors_reachable(self, sess, outputs): |
| 163 | """Checks that all the tensors in the graph are reachable from outputs.""" |