← Back to Home

Gender Classification from Name

Character-Level Deep Learning

A deep-learning model that predicts a person's gender from their name alone, by reading the name character by character through a CNN + LSTM network — no name dictionary required — served behind a simple Flask web API. (Built during an internship at Kazee.)

#NLP#Character-Level Modeling#Deep Learning#CNN + LSTM#Keras / TensorFlow#Binary Classification#Flask API

// Overview

What it does. Given a name (e.g. "Aditya Rizky"), the model predicts a binary gender label. It works purely from the spelling of the name — the sub-word patterns, suffixes, and letter sequences that correlate with gender — so it generalizes to names it has never seen, rather than looking them up in a list. It's wrapped in a small Flask service that takes a name and returns a prediction.

Background

Predicting gender from a name is deceptively tricky:

  • Dictionaries don't generalize. A lookup table fails on rare, novel, or compound names; the signal really lives in how a name is spelled.
  • Sub-word patterns matter. Endings and letter combinations carry most of the gender signal, which a character-level model can learn directly.
  • Order counts. The same letters in different orders mean different things, motivating a sequence model (CNN for local patterns + LSTM for order) over a bag-of-characters.
  • Short, variable input. Names are short and vary in length, so fixed-length padding and a compact network were appropriate.
  • Needs to be callable. The classifier had to run as a service, not just a notebook.

Solution

  1. Character preprocessing. Lowercase the name and split it into a list of characters.
  2. Sequence encoding. A fitted character tokenizer maps characters to integers; sequences are padded to a fixed max length (40).
  3. Character embedding. A learned Embedding layer turns character ids into dense vectors.
  4. CNN + LSTM model. A Conv1D layer extracts local letter-pattern features, an LSTM models character order, and Dense → sigmoid produces the binary gender probability; an LSTM-stacked variant was also trained for comparison.
  5. Flask serving. A small Flask app exposes a /predict_gender endpoint that runs the full preprocess→encode→predict pipeline on an incoming name.

Impact

  • Dictionary-free prediction that generalizes to unseen names from spelling alone.
  • Character-level modeling that learns the sub-word patterns carrying the gender signal.
  • Sequence-aware (CNN+LSTM) rather than treating a name as an unordered bag of letters.
  • Reusable as a service via a simple HTTP endpoint.
  • Reproducible workflow — model training and prediction captured as notebooks with saved artifacts.

// Tech Stack

LayerTechnologies
ModelingKeras / TensorFlowEmbeddingConv1DLSTMDense → sigmoid (LSTM-stacked variant also trained)
EncodingCharacter-level Keras Tokenizer + pad_sequences (maxlen 40)
ServingFlask (/predict_gender endpoint)
WorkflowJupyter notebooks (model · predict), pickled tokenizer + saved model/weights

// Architecture & Diagrams

1 / 3Inference Pipeline
rendering…

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

// Demo

No demo configured yet.