GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - NeaByteLab/Byte-Tokenizer: Turns each letter into a raw byte number and keeps each chat marker as one token, then restores the original text.

BranchesTags
Open more actions menu

Latest commit

 

History

5 Commits
5 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.config.ts
build.config.ts
 
 
deno.json
deno.json
 
 
package.json
package.json
 
 

Repository files navigation

Byte Tokenizer

Encode text as UTF-8 bytes and special tokens

Deno Node Bun Browser License

What is Byte Tokenizer?

Byte Tokenizer turns text into token IDs and turns those IDs back into text. Ordinary characters become raw UTF-8 bytes from 0 to 255, while optional special tokens start at 256 and match longest-first, so <|im_start|> is not split into a shorter <|im|> prefix. There is no vocabulary file, lowercase folding, or Unicode normalization, so case, combining marks, null bytes, and a leading BOM stay as encoded. Duplicate special tokens are ignored, and invalid UTF-8 bytes decode as U+FFFD.

Installation

Deno:

deno add npm:@neabyte/byte-tokenizer

npm:

npm install @neabyte/byte-tokenizer

CDN (jsDelivr/esm.sh):

<script type="module">
  import Tokenizer from 'https://cdn.jsdelivr.net/npm/@neabyte/byte-tokenizer/dist/index.mjs'
</script>

Or via esm.sh:

<script type="module">
  import Tokenizer from 'https://esm.sh/@neabyte/byte-tokenizer'
</script>

Usage

import Tokenizer from '@neabyte/byte-tokenizer'

// Raw bytes from 0 to 255
const tokenizer = new Tokenizer()

const rawIds = tokenizer.encode('Hello!')
// [72, 101, 108, 108, 111, 33]

const rawText = tokenizer.decode(rawIds)
// 'Hello!'

// Special tokens start at 256
const customTokenizer = new Tokenizer(['<|bos|>', '<|eos|>'])

const customIds = customTokenizer.encode('<|bos|>Hello!<|eos|>')
// [256, 72, 101, 108, 108, 111, 33, 257]

const customText = customTokenizer.decode(customIds)
// '<|bos|>Hello!<|eos|>'

API

constructor

new Tokenizer(specialToken?)
  • specialToken <string[]>: (Optional) Special token strings. Defaults to []. Empty strings are rejected. Duplicate strings keep the first ID. IDs start at 256 and follow first-seen order.
  • Throws: TypeError when the argument is not an array, or a token is empty or not a string.

encode

tokenizer.encode(text)
  • text <string>: Text to encode. Plain spans become UTF-8 byte IDs. A matching special token becomes one ID, and the longest match wins.
  • Returns: <number[]>
  • Throws: TypeError when text is not a string.

decode

tokenizer.decode(identifier)
  • identifier <ArrayLike<number>>: Token IDs, including typed arrays. IDs 0 to 255 become bytes. IDs 256 and above expand to their special-token text. A leading BOM is kept.
  • Returns: <string>
  • Throws: TypeError when the value is not array-like, or an ID is not an integer.
  • Throws: RangeError when an ID is negative, -0, or outside the vocabulary.

Build

npm run build

Testing

deno task check
deno task test

License

This project is licensed under the MIT License.

About

Turns each letter into a raw byte number and keeps each chat marker as one token, then restores the original text.

www.npmjs.com/@neabyte/byte-tokenizer

Topics

byte-levelbyte-tokenizerchat-templatedecodingencodinglanguage-modelmitnatural-language-processingnlpspecial-tokensstring-processingtext-decodingtext-encodingtext-processingtokenidstokenizationtokenizerunicodeutf-8vocabulary-free

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.