Spaces:
Sleeping
Sleeping
|
Download README.md from YanaGabelev/TokenLab: direct link, hf CLI and curl.
- Browser
- Download file 3.73 kB
-
https://huggingface.co/spaces/YanaGabelev/TokenLab/resolve/main/README.md
- Command line
-
hf download hf://spaces/YanaGabelev/TokenLab/README.md
-
curl -L -o README.md https://huggingface.co/spaces/YanaGabelev/TokenLab/resolve/main/README.md
3.73 kB
| title: TokenLab | |
| emoji: π | |
| colorFrom: purple | |
| colorTo: blue | |
| sdk: gradio | |
| sdk_version: 5.34.2 | |
| app_file: app.py | |
| pinned: false | |
| license: mit | |
| # π§ Interactive Text Tokenization App | |
| An interactive Gradio app for exploring how different language models tokenize and process natural language inputs. The app demonstrates Tokenization, Stemming, and Lemmatization using modern NLP tools. | |
| --- | |
| ## π Features | |
| - Input a sentence and choose a tokenizer (`gpt2` or `bert-base-uncased`) | |
| - Display: | |
| - Tokens from the selected model | |
| - Decoded tokens (token IDs and readable tokens) | |
| - Stemmed words using **PorterStemmer** | |
| - Lemmatized words using **spaCy** (if available) or fallback to **WordNetLemmatizer** | |
| - Comparison table: | |
| | Original | Stemmed | Lemmatized | | |
| |----------|---------|------------| | |
| | running | runn | run | | |
| | better | better | good | | |
| - Comparison of Tokenizers: | |
| - BERT (WordPiece) | |
| - GPT2 (BPE) | |
| - tiktoken (OpenAI's cl100k_base) β *if installed* | |
| - Markdown explanations and linguistic insights | |
| --- | |
| ## π§° Technologies Used | |
| - **Gradio** β for the user interface | |
| - **Transformers (Hugging Face)** β AutoTokenizer for GPT2 and BERT | |
| - **nltk** β for stemming and fallback lemmatization | |
| - **spaCy** β primary lemmatizer (if available) | |
| - **tiktoken** β OpenAI tokenizer, used if installed | |
| --- | |
| ## π How to Use | |
| 1. Enter a sentence (e.g., `I was running faster than him`) | |
| 2. Choose a tokenizer (e.g., `gpt2` or `bert`) | |
| 3. Click **Analyze** | |
| 4. View: | |
| - Token comparisons (tokens, decoded, token IDs) | |
| - Stemmed & Lemmatized results | |
| - Table comparison | |
| - Linguistic explanation | |
| --- | |
| ## π What is Tokenization? | |
| Tokenization breaks text into smaller units called tokens β words, subwords, or characters. Different models tokenize differently: | |
| - **GPT2** uses *byte-pair encoding* (BPE) | |
| - **BERT** uses *WordPiece* encoding | |
| - **tiktoken** simulates tokenization in OpenAI models like ChatGPT | |
| --- | |
| ## πΏ What is Stemming? | |
| Stemming chops off suffixes to reduce a word to its base form. | |
| - Example: `running`, `runner`, `runs` β `run` | |
| - Can produce non-words: `running` β `runn` | |
| - Tool used: `nltk.PorterStemmer` | |
| --- | |
| ## π What is Lemmatization? | |
| Lemmatization maps a word to its **dictionary base form** using linguistic rules. | |
| - Example: `running` β `run`, `better` β `good` | |
| - More accurate than stemming | |
| - Tools used: | |
| - `spaCy` (if available) | |
| - Fallback: `nltk.WordNetLemmatizer` | |
| --- | |
| ## π When to Use Each? | |
| | Technique | Use Case | Pros | Cons | | |
| |---------------|-------------------------------------------|------------------------------|---------------------------| | |
| | Tokenization | Model preprocessing | Fast, essential | Model-dependent results | | |
| | Stemming | Lightweight, fast normalization | Simple, quick | Less accurate | | |
| | Lemmatization | Semantic-level analysis | Linguistic, precise | Slower, depends on tools | | |
| --- | |
| ## π§ͺ Example Insight | |
| > Do all models treat `running` the same? | |
| No: | |
| - **BERT** might split it into `["run", "##ning"]` | |
| - **GPT2** may tokenize it differently (based on byte-pairs) | |
| - **spaCy** lemmatizes `running` β `run`, **WordNet** does the same (but context-dependent) | |
| - **Stemming** gives: `runn` | |
| --- | |
| ## π§ Built as part of a Natural Language Processing assignment | |
| --- | |
| ## π Repository Files | |
| - `app.py`: Main Gradio application | |
| - `README.md`: This file | |
| - `requirements.txt`: Project dependencies | |
| --- | |
| ## π¦ Installation (for local use) | |
| ```bash | |
| pip install -r requirements.txt | |
| python app.py | |
| ``` | |
| --- | |