CoolFace
Apppublic

afeng/tokenizers

sourceHugging Facemitupdated 10mo agoView on Hugging Face
1likes
App README

๐Ÿ”ค Tokenizer Playground

An interactive web application for experimenting with various Hugging Face tokenizers. Perfect for NLP researchers and developers who need to quickly test and compare different tokenization strategies.

Features

๐Ÿ”ค Tokenize Tab

  • โ€”Convert any text into tokens using popular models
  • โ€”View tokens, token IDs, and detailed token information
  • โ€”See tokenization statistics (tokens per character, vocabulary size, etc.)
  • โ€”Support for adding/removing special tokens
  • โ€”Custom model support via Hugging Face model IDs

๐Ÿ”„ Detokenize Tab

  • โ€”Convert token IDs back to text
  • โ€”Support for various input formats (list, comma-separated, space-separated)
  • โ€”Option to skip special tokens
  • โ€”Verification of round-trip tokenization

๐Ÿ“Š Compare Tab

  • โ€”Compare tokenization across multiple models simultaneously
  • โ€”See token count differences and efficiency metrics
  • โ€”Identify which tokenizer is most efficient for your use case
  • โ€”Sort results by token count

๐Ÿ“– Vocabulary Tab

  • โ€”Explore tokenizer vocabulary details
  • โ€”View special tokens and their configurations
  • โ€”See vocabulary size and tokenizer type
  • โ€”Browse first 100 tokens in the vocabulary

Supported Models

Pre-configured Models

  • โ€”Qwen Series: Qwen 3, Qwen 2.5, Qwen 2, Qwen 1 (multiple sizes)
  • โ€”Llama Series: Llama 3.2, Llama 3.1, Llama 2 (multiple sizes)
  • โ€”GPT Models: GPT-2, GPT-NeoX
  • โ€”Google Models: Gemma, T5, BERT
  • โ€”Mistral Models: Mistral 7B, Mixtral 8x7B
  • โ€”Other Models: DeepSeek, Phi, Yi, BLOOM, OPT, StableLM

Custom Models

You can use any tokenizer available on the Hugging Face Hub by entering its model ID in the "Custom Model ID" field. Examples:

  • โ€”facebook/bart-base
  • โ€”EleutherAI/gpt-j-6b
  • โ€”bigscience/bloom
  • โ€”stabilityai/stablelm-2-1_6b

Technical Details

  • โ€”Built with Gradio for an intuitive web interface
  • โ€”Uses Hugging Face Transformers for tokenizer support
  • โ€”Supports both fast (Rust-based) and slow (Python-based) tokenizers
  • โ€”Caches loaded tokenizers for improved performance
  • โ€”Handles special tokens and custom vocabularies

Quick Start

  1. 1.Select a tokenizer from the dropdown or enter a custom model ID
  2. 2.Enter your text in the input field
  3. 3.Click the action button (Tokenize, Decode, Compare, or Analyze)
  4. 4.View the results in the output fields

Tips

  • โ€”Different tokenizers can produce significantly different token counts for the same text
  • โ€”Special tokens (like [CLS], [SEP], <s>, </s>) are model-specific
  • โ€”Subword tokenization allows handling of out-of-vocabulary words
  • โ€”Token efficiency directly impacts model inference costs and API usage

Local Development

To run this application locally:

bash
# Clone the repository
git clone <your-repo-url>
cd tokenizer-playground

# Install dependencies
pip install -r requirements.txt

# Run the application
python app.py

The application will be available at http://localhost:7860

License

This project is licensed under the MIT License.