MCPcopy Create free account
hub / github.com/cosdata/cosdata / safe_tokenize

Function safe_tokenize

tests/modal_remote_vllm/remote_cache_dense.py:91–99  ·  view source on GitHub ↗

Safely tokenize text without warnings.

(text: str, add_special_tokens: bool = True)

Source from the content-addressed store, hash-verified

89
90
91def safe_tokenize(text: str, add_special_tokens: bool = True) -> List[int]:
92 """
93 Safely tokenize text without warnings.
94 """
95 with warnings.catch_warnings():
96 warnings.simplefilter("ignore")
97 return get_tokenizer().encode(
98 text, add_special_tokens=add_special_tokens, truncation=True, max_length=512
99 )
100
101
102def clip_to_max_tokens(text: str, max_len: int = 512) -> str:

Callers 4

chunk_text_by_tokensFunction · 0.85
clip_to_max_tokensFunction · 0.85
validate_token_lengthFunction · 0.85
cache_datasetFunction · 0.85

Calls 1

get_tokenizerFunction · 0.85

Tested by

no test coverage detected