MCPcopy Create free account
hub / github.com/google-research/language / sample

Function sample

language/capwap/utils/text_utils.py:216–230  ·  view source on GitHub ↗

Sample length from truncated Geo(p).

(start, end)

Source from the content-addressed store, hash-verified

214 return tf.reduce_any([wordpiece_boundary, all_stopword, length])
215
216 def sample(start, end):
217 """Sample length from truncated Geo(p)."""
218 # Sample from truncated geometric distribution.
219 geometric = lambda k: (1 - p)**(k - 1) * p
220 probs = np.array([geometric(k) for k in range(1, max_span_len + 1)])
221 probs /= probs.sum()
222 length = tf.distributions.Categorical(probs=probs).sample() + 1
223
224 # Sample start uniformly.
225 max_offset = tf.maximum(1, seq_len - length + 1)
226 start = tf.random.uniform([], 0, max_offset, dtype=tf.int32)
227 end = start + length
228
229 # Return span.
230 return [start, end]
231
232 # Rejection sample. Start with dummy span variable.
233 start = tf.constant(0)

Callers

nothing calls this directly

Calls 1

sampleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…