MCPcopy Index your code
hub / github.com/THUDM/GLM / sample_spans

Method sample_spans

blocklm_utils.py:103–114  ·  view source on GitHub ↗
(span_lengths, total_length, rng, offset=0)

Source from the content-addressed store, hash-verified

101
102 @staticmethod
103 def sample_spans(span_lengths, total_length, rng, offset=0):
104 blank_length = total_length - sum(span_lengths)
105 m = blank_length - len(span_lengths) + 1
106 places = [rng.randrange(m + 1) for _ in range(len(span_lengths))]
107 places.sort()
108 spans = []
109 for place, span_length in zip(places, span_lengths):
110 start = offset + place
111 end = offset + place + span_length
112 spans.append((start, end))
113 offset += span_length + 1
114 return spans
115
116 def sample_span_in_document(self, tokens, masked_lengths, rng):
117 rng.shuffle(masked_lengths)

Callers 1

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected