← Back to Home

Twitter Sentiment Analysis

Bilingual Deep-Learning NLP (Indonesian + English)

A pair of deep-learning sentiment classifiers for tweets — one for Indonesian, one for English — that clean raw, noisy tweet text, embed it with trained word vectors, and predict sentiment with a CNN + LSTM network, served behind a simple Flask web API. (Built during an internship at Kazee.)

#NLP#Sentiment Analysis#Deep Learning#CNN + LSTM#Word2Vec / Doc2Vec#Keras / TensorFlow#Text Preprocessing#Indonesian NLP (Sastrawi)#Flask API

// Overview

What it does. Given the text of a tweet, the models predict its sentiment (negative / neutral / positive). Two parallel pipelines cover two languages: an Indonesian model using Indonesian-specific preprocessing (Sastrawi stemming + stopword removal) and an English model using NLTK-style preprocessing. Each is wrapped in a small Flask service that takes raw text and returns a prediction, so the classifier can be called like any web endpoint.

Background

Social-media text is a hard input for classic ML:

  • Tweets are noisy. Mentions, links, hashtags, emoji, slang, and repeated letters drown the actual signal and have to be stripped before modeling.
  • Language matters. Indonesian needs its own stemming/stopword handling (Sastrawi); reusing an English pipeline would mangle it — hence two dedicated pipelines.
  • Word order carries sentiment. Bag-of-words loses negation and phrasing, motivating sequence models (CNN for local n-gram features, LSTM for order) over plain counting.
  • Pretrained vectors help. Training Word2Vec on the tweet corpus gives denser, more meaningful inputs than one-hot encoding.
  • Needs to be callable. The classifier had to be usable as a service, not just a notebook.

Solution

  1. Tweet cleaning. Regex-based removal of RT markers, mentions, URLs, hashtags, numbers, repeated characters, and non-letter symbols, then lowercase + tokenize.
  2. Language-specific normalization. Indonesian → Sastrawi stopword removal + stemming (with an extended stopword list); English → NLTK tokenization.
  3. Sequence encoding. A fitted Keras Tokenizer maps text to integer sequences, padded to a fixed max length.
  4. Trained embeddings. Word2Vec vectors trained on the corpus initialize the embedding layer (Doc2Vec explored as an alternative representation).
  5. CNN + LSTM model. Stacked Conv1D blocks (with dropout) extract local features, an LSTM captures sequence/order, and Dense + softmax produces the 3-class sentiment output; trained with checkpointing on best validation accuracy.
  6. Flask serving. A small Flask app exposes a /predict endpoint that runs the full clean→encode→predict pipeline on incoming text.

Impact

  • End-to-end working classifiers for two languages, from raw tweet to served prediction.
  • Proper Indonesian NLP, not an English pipeline bolted onto Indonesian text.
  • Sequence-aware modeling (CNN+LSTM) that respects word order and local phrasing.
  • Reusable as a service via a simple HTTP endpoint.
  • A reproducible workflow — preprocessing, embedding training, model training, and reporting captured as notebooks.

// Tech Stack

LayerTechnologies
ModelingKeras / TensorFlowEmbeddingConv1D (×3, dropout) → LSTMDense → softmax
EmbeddingsWord2Vec (Gensim) trained on corpus; Doc2Vec explored
Preprocessing (ID)Sastrawi stemmer + stopword remover, regex tweet cleaning
Preprocessing (EN)NLTK tokenization, regex tweet cleaning
EncodingKeras Tokenizer + pad_sequences
ServingFlask (/predict endpoint)
WorkflowJupyter notebooks (preprocess · embeddings · model · report), pickled tokenizer + saved model/weights

// Architecture & Diagrams

1 / 3Inference Pipeline (per language)
rendering…

Disclaimer: sample visuals may contain anonymized, simulated, or non-production values for presentation purposes.

// Demo

No demo configured yet.