MCPcopy Create free account
hub / github.com/CLUEbenchmark/CLUE / ids_tensor

Method ids_tensor

baselines/models/bert/modeling_test.py:147–160  ·  view source on GitHub ↗

Creates a random int32 tensor of the shape within the vocab size.

(cls, shape, vocab_size, rng=None, name=None)

Source from the content-addressed store, hash-verified

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."""

Callers 1

create_modelMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected