MCPcopy Create free account
hub / github.com/modelscope/modelscope / get_segment_index

Function get_segment_index

modelscope/models/nlp/ponet/backbone.py:75–80  ·  view source on GitHub ↗
(input_ids, cls_id=CLS_ID, eos_id=EOS_ID)

Source from the content-addressed store, hash-verified

73
74
75def get_segment_index(input_ids, cls_id=CLS_ID, eos_id=EOS_ID):
76 mask = (input_ids == cls_id).to(
77 dtype=torch.long) + (input_ids == eos_id).to(dtype=torch.long)
78 mask = mask + torch.cat([torch.zeros_like(mask[:, 0:1]), mask[:, :-1]],
79 dim=1)
80 return mask.cumsum(dim=1) - 1
81
82
83def get_token_type_mask(input_ids, cls_id=CLS_ID, eos_id=EOS_ID):

Callers 1

forwardMethod · 0.85

Calls 3

cumsumMethod · 0.80
toMethod · 0.45
catMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…