MCPcopy
hub / github.com/PaddlePaddle/ERNIE / flatten

Method flatten

ernie/dataset/pvp.py:46–59  ·  view source on GitHub ↗

Flatten nested token sequences into a single list. Returns: List[str]: Flattened list of tokens from nested sequences.

(s)

Source from the content-addressed store, hash-verified

44
45 @staticmethod
46 def flatten(s):
47 """Flatten nested token sequences into a single list.
48
49 Returns:
50 List[str]: Flattened list of tokens from nested sequences.
51 """
52 tokens = []
53 for x in s:
54 if isinstance(x, tuple):
55 tokens.extend(x[0])
56 else:
57 tokens.extend(x)
58
59 return tokens
60
61 @staticmethod
62 def _seq_length(parts: List[Tuple[List, bool]], only_shortenable: bool = False):

Callers 15

encodeMethod · 0.95
forwardMethod · 0.80
forwardMethod · 0.80
rot_pos_embMethod · 0.80
dpo_logpsMethod · 0.80
get_rope_indexMethod · 0.80
mem_eff_attnFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected