Giter Site home page Giter Site logo

jmaczan / bpe-tokenizer Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 111 KB

Byte-Pair Encoding tokenizer for training large language models on huge datasets

License: GNU General Public License v3.0

Python 100.00%
bpe byte-pair-encoding deep-learning from-scratch large-language-models llm machine-learning python tokenizer chunking bpe-tokenizer

bpe-tokenizer's Introduction

bpe-tokenizer

Byte-Pair Encoding tokenizer for large language models that can be trained on arbitrarily huge datasets

"Materia" by Anita Maczan, Acrylic on canvas, 40x50, 2024

This implementation is suitable for working with huge datasets, because it processes data in chunks, both during tokenization and training

Training

from bpe_tokenizer import BPETokenizer

BPETokenizer().train(dataset_path="./path/to/dataset.txt")

CLI

python bpe_tokenizer.py train --training_dataset path_to_your_dataset.txt --vocabulary_size 5000 --training_output path_to_output_tokenizer.json

defaults:

  • training_dataset = "training.txt"
  • vocabulary_size = 50257
  • training_output = "tokenizer.json"

Tokenize

from bpe_tokenizer import BPETokenizer

BPETokenizer().tokenize(text_to_be_tokenized)

CLI

python bpe_tokenizer.py tokenize --tokenizer_data path_to_tokenizer_data.json --run_data tokenize.json

defaults:

  • tokenizer_data = "tokenizer.json"
  • run_data = "tokenize.txt"

run_data file structure:

{
  "data": "Study hard what interests you the most in the most undisciplined, irreverent and original manner possible - Richard Feynmann"
}

Detokenize

from bpe_tokenizer import BPETokenizer

BPETokenizer().detokenize(array_of_tokens_to_be_parsed_to_text)

CLI

python bpe_tokenizer.py detokenize --tokenizer_data path_to_tokenizer_data.json --run_data detokenize.json

defaults:

  • tokenizer_data = "tokenizer.json"
  • run_data = "detokenize.txt"

run_data file structure:

{
  "data": [
    275, 265, 282, 32, 111, 108, 100, 32, 98, 97, 115, 116, 97, 114, 100, 284,
    268, 265, 282, 32, 282, 110, 292, 98, 97, 115, 116, 97, 114, 100, 33
  ]
}

License

GPL v3

Jędrzej Maczan, 2024

bpe-tokenizer's People

Contributors

jmaczan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.