YanaGabelev commited on
Commit
8e6e79c
Β·
verified Β·
1 Parent(s): 09cf57c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +68 -41
README.md CHANGED
@@ -9,80 +9,107 @@ app_file: app.py
9
  pinned: false
10
  license: mit
11
  ---
 
12
  # 🧠 Interactive Text Tokenization App
13
  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.
 
14
  ---
15
  ## πŸš€ Features
16
- - Input a sentence and choose a tokenizer (gpt2 or bert-base-uncased)
17
  - Display:
18
  - Tokens from the selected model
19
- - Decoded tokens (optional)
20
- - Stemmed words using PorterStemmer
21
- - Lemmatized words using WordNetLemmatizer or spaCy
22
- - Table comparing:
23
 
24
  | Original | Stemmed | Lemmatized |
25
  |----------|---------|------------|
26
  | running | runn | run |
27
  | better | better | good |
28
- - Optional: Comparison with tiktoken (cl100k_base) if available
29
- - Written explanations and insights about each technique
 
 
 
 
 
 
30
  ---
31
  ## 🧰 Technologies Used
32
- - Gradio – for the user interface
33
- - Transformers (Hugging Face) – AutoTokenizer for GPT2 and BERT
34
- - nltk – for stemming and lemmatization
35
- - spaCy (optional) – for advanced lemmatization
36
- - tiktoken – OpenAI tokenizer, if installed
 
37
  ---
38
  ## πŸ” How to Use
39
- 1. Enter any sentence (e.g., I was running faster than him)
40
- 2. Choose a tokenizer (e.g., gpt2)
41
- 3. Click "Analyze"
42
  4. View:
43
- - List of tokens
44
- - Stemmed & Lemmatized versions
45
  - Table comparison
46
- - Explanation below
 
47
  ---
48
  ## πŸ“Š What is Tokenization?
49
- Tokenization is the process of breaking text into smaller units called tokens, which can be words, subwords, or characters. Different models tokenize text differently:
50
- - GPT2 uses byte-pair encoding (BPE) and might split a word like unbelievable into ['un', 'bel', 'ievable'].
51
- - BERT uses WordPiece encoding and might produce different splits for the same input.
52
- Optionally, tiktoken (cl100k_base) can show how OpenAI models (e.g., ChatGPT) tokenize text.
 
 
53
  ---
54
  ## 🌿 What is Stemming?
55
- Stemming reduces a word to its root form by removing suffixes. For example:
56
- - running, runner, runs β†’ run
57
- Stemming can be aggressive and may result in non-dictionary forms (e.g., running β†’ runn).
58
- Implemented with nltk.PorterStemmer.
 
59
  ---
60
  ## πŸƒ What is Lemmatization?
61
- Lemmatization also reduces words to their base form (lemma) but uses vocabulary and morphological analysis:
62
- - running β†’ run
63
- - better β†’ good
64
- More accurate than stemming, but requires more computation.
65
- Implemented with nltk.WordNetLemmatizer or spaCy.
 
 
66
  ---
67
  ## πŸ“Œ When to Use Each?
68
  | Technique | Use Case | Pros | Cons |
69
  |---------------|-------------------------------------------|------------------------------|---------------------------|
70
- | Tokenization | Preprocessing for any NLP model | Fast, essential | Model-dependent behavior |
71
- | Stemming | Rule-based reduction for simpler tasks | Fast, lightweight | Less accurate |
72
- | Lemmatization | Linguistically correct form for analysis | Accurate, semantic-friendly | Slower, requires context |
 
73
  ---
74
  ## πŸ§ͺ Example Insight
75
- > Do all models treat running the same way?
76
- No. BERT might split it as ['run', '##ning'], while GPT2 might split it differently depending on context. The stemmer will return runn, and the lemmatizer will return run.
 
 
 
 
 
 
77
  ---
78
- ## 🧠 Natural Language Processing assignment.
 
79
  ---
80
  ## πŸ“‚ Repository Files
81
- - app.py: Main Gradio application
82
- - README.md: This file
83
- - requirements.txt: Dependencies (see below)
 
84
  ---
85
  ## πŸ“¦ Installation (for local use)
86
  ```bash
87
  pip install -r requirements.txt
88
- python app.py
 
 
 
 
9
  pinned: false
10
  license: mit
11
  ---
12
+
13
  # 🧠 Interactive Text Tokenization App
14
  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.
15
+
16
  ---
17
  ## πŸš€ Features
18
+ - Input a sentence and choose a tokenizer (`gpt2` or `bert-base-uncased`)
19
  - Display:
20
  - Tokens from the selected model
21
+ - Decoded tokens (token IDs and readable tokens)
22
+ - Stemmed words using **PorterStemmer**
23
+ - Lemmatized words using **spaCy** (if available) or fallback to **WordNetLemmatizer**
24
+ - Comparison table:
25
 
26
  | Original | Stemmed | Lemmatized |
27
  |----------|---------|------------|
28
  | running | runn | run |
29
  | better | better | good |
30
+
31
+ - Comparison of Tokenizers:
32
+ - BERT (WordPiece)
33
+ - GPT2 (BPE)
34
+ - tiktoken (OpenAI's cl100k_base) β€” *if installed*
35
+
36
+ - Markdown explanations and linguistic insights
37
+
38
  ---
39
  ## 🧰 Technologies Used
40
+ - **Gradio** – for the user interface
41
+ - **Transformers (Hugging Face)** – AutoTokenizer for GPT2 and BERT
42
+ - **nltk** – for stemming and fallback lemmatization
43
+ - **spaCy** – primary lemmatizer (if available)
44
+ - **tiktoken** – OpenAI tokenizer, used if installed
45
+
46
  ---
47
  ## πŸ” How to Use
48
+ 1. Enter a sentence (e.g., `I was running faster than him`)
49
+ 2. Choose a tokenizer (e.g., `gpt2` or `bert`)
50
+ 3. Click **Analyze**
51
  4. View:
52
+ - Token comparisons (tokens, decoded, token IDs)
53
+ - Stemmed & Lemmatized results
54
  - Table comparison
55
+ - Linguistic explanation
56
+
57
  ---
58
  ## πŸ“Š What is Tokenization?
59
+ Tokenization breaks text into smaller units called tokens β€” words, subwords, or characters. Different models tokenize differently:
60
+
61
+ - **GPT2** uses *byte-pair encoding* (BPE)
62
+ - **BERT** uses *WordPiece* encoding
63
+ - **tiktoken** simulates tokenization in OpenAI models like ChatGPT
64
+
65
  ---
66
  ## 🌿 What is Stemming?
67
+ Stemming chops off suffixes to reduce a word to its base form.
68
+ - Example: `running`, `runner`, `runs` β†’ `run`
69
+ - Can produce non-words: `running` β†’ `runn`
70
+ - Tool used: `nltk.PorterStemmer`
71
+
72
  ---
73
  ## πŸƒ What is Lemmatization?
74
+ Lemmatization maps a word to its **dictionary base form** using linguistic rules.
75
+ - Example: `running` β†’ `run`, `better` β†’ `good`
76
+ - More accurate than stemming
77
+ - Tools used:
78
+ - `spaCy` (if available)
79
+ - Fallback: `nltk.WordNetLemmatizer`
80
+
81
  ---
82
  ## πŸ“Œ When to Use Each?
83
  | Technique | Use Case | Pros | Cons |
84
  |---------------|-------------------------------------------|------------------------------|---------------------------|
85
+ | Tokenization | Model preprocessing | Fast, essential | Model-dependent results |
86
+ | Stemming | Lightweight, fast normalization | Simple, quick | Less accurate |
87
+ | Lemmatization | Semantic-level analysis | Linguistic, precise | Slower, depends on tools |
88
+
89
  ---
90
  ## πŸ§ͺ Example Insight
91
+ > Do all models treat `running` the same?
92
+
93
+ No:
94
+ - **BERT** might split it into `["run", "##ning"]`
95
+ - **GPT2** may tokenize it differently (based on byte-pairs)
96
+ - **spaCy** lemmatizes `running` β†’ `run`, **WordNet** does the same (but context-dependent)
97
+ - **Stemming** gives: `runn`
98
+
99
  ---
100
+ ## 🧠 Built as part of a Natural Language Processing assignment
101
+
102
  ---
103
  ## πŸ“‚ Repository Files
104
+ - `app.py`: Main Gradio application
105
+ - `README.md`: This file
106
+ - `requirements.txt`: Project dependencies
107
+
108
  ---
109
  ## πŸ“¦ Installation (for local use)
110
  ```bash
111
  pip install -r requirements.txt
112
+ python app.py
113
+ ```
114
+
115
+ ---