MCPcopy Create free account
hub / github.com/ModalityDance/Omni-R1 / add

Method add

src/transformers/src/transformers/tokenization_utils.py:75–104  ·  view source on GitHub ↗

Passes over every char (utf-8 char) on word and recursively adds it to the internal `data` trie representation. The special key `""` in `self._termination_char` is used to represent termination. This function is idempotent, adding twice the same word will leave the trie unc

(self, word: str)

Source from the content-addressed store, hash-verified

73 self.add(token)
74
75 def add(self, word: str):
76 """
77 Passes over every char (utf-8 char) on word and recursively adds it to the internal `data` trie representation.
78 The special key `""` in `self._termination_char` is used to represent termination.
79
80 This function is idempotent, adding twice the same word will leave the trie unchanged
81
82 Example:
83
84 ```python
85 >>> trie = Trie()
86 >>> trie.add("Hello 友達")
87 >>> trie.data
88 {"H": {"e": {"l": {"l": {"o": {" ": {"友": {"達": {"": 1}}}}}}}}}
89
90 >>> trie.add("Hello")
91 >>> trie.data
92 {"H": {"e": {"l": {"l": {"o": {"": 1, " ": {"友": {"達": {"": 1}}}}}}}}}
93 ```
94 """
95 if not word:
96 # Prevent empty string
97 return
98
99 self._tokens.add(word)
100 ref = self.data
101 for char in word:
102 ref[char] = ref.setdefault(char, {})
103 ref = ref[char]
104 ref[self._termination_char] = 1
105
106 def split(self, text: str) -> List[str]:
107 """

Callers 15

updateMethod · 0.95
test_trieMethod · 0.95
test_trie_splitMethod · 0.95
test_trie_singleMethod · 0.95
test_trie_finalMethod · 0.95
test_trie_subtokensMethod · 0.95
test_trie_skipMethod · 0.95
parse_lineFunction · 0.45
get_all_model_namesFunction · 0.45
check_docstringsFunction · 0.45

Calls 1

setdefaultMethod · 0.80

Tested by 8

test_trieMethod · 0.76
test_trie_splitMethod · 0.76
test_trie_singleMethod · 0.76
test_trie_finalMethod · 0.76
test_trie_subtokensMethod · 0.76
test_trie_skipMethod · 0.76