Tokenization in NLP and NLP Project Life Cycle

Nlp tutorial · PySpark.in

What is Tokenization?

Tokenization is the process of breaking text (paragraphs, sentences) into smaller units called tokens.

These tokens form the vocabulary of your dataset.

 Example

 Text:

I like to drink apple juice. My friend likes mango juice.

Step 1: Sentence Tokenization

Step 2: Word Tokenization

Sentence 1 → ["I", "like", "to", "drink", "apple", "juice"]
Sentence 2 → ["My", "friend", "likes", "mango", "juice"]

 Vocabulary

Note: "like" and "likes" are treated as different words unless we apply stemming/lemmatization.

 Key Definitions

 NLP Project Life Cycle (Example: Sentiment Analysis)-

Step 1: Dataset

Step 2: Text Pre-processing 

Cleaning raw text before feeding it into ML/DL models.

Step 3: Text Pre-processing 

Further refining of tokens.

Step 4: Text → Vectors (Numerical Representation)

We can’t feed raw text to ML models, so convert words/sentences into vectors.
Techniques:

  1. One Hot Encoding – simple but inefficient.

  2. Bag of Words (BoW) – count word occurrences.

  3. TF-IDF (Term Frequency – Inverse Document Frequency) – weighs words based on importance.

  4. Word2Vec – dense word embeddings, captures semantic meaning.

  5. Average Word2Vec – averages vectors of words in a sentence/document.

  6. Advanced embeddings (later) – GloVe, FastText, Transformers (BERT, GPT, etc.).

Step 5: Model Training

Step 6: Prediction & Evaluation


More Nlp tutorials

All tutorials · Try the free PySpark compiler · Practice challenges