Spaces:
Running
Running
Download tokenize.mjs from Future-Labs/example-router: direct link, hf CLI and curl.
- Browser
- Download file 487 Bytes
-
https://huggingface.co/spaces/Future-Labs/example-router/resolve/main/tokenize.mjs
- Command line
-
hf download hf://spaces/Future-Labs/example-router/tokenize.mjs
-
curl -L -o tokenize.mjs https://huggingface.co/spaces/Future-Labs/example-router/resolve/main/tokenize.mjs
487 Bytes
| // Single-message BERT tokenization with the same 256-token limit as Python. | |
| export function encodeMessage(tokenizer, text) { | |
| const encoded = tokenizer.encode(text, { add_special_tokens: true, return_token_type_ids: true }); | |
| const truncated = encoded.ids.length > 256; | |
| const ids = truncated ? [...encoded.ids.slice(0, 255), tokenizer.token_to_id('[SEP]')] : encoded.ids; | |
| return { input_ids: ids, attention_mask: ids.map(() => 1), token_type_ids: ids.map(() => 0), truncated }; | |
| } | |