Ismail Ben Alla

HR-Jev

GPT-2 for HR Outcome Prediction

Generative AI · Aug 2025 · Completed

A GPT-2 model that reads employee profiles and predicts four HR outcomes.

Built withPyTorchHugging Face TransformerspandasTensorBoardGradiopytest

HR-Jev — overview

Overview

HR data usually lives in tables, and tables are usually handled by classic tabular models. I wanted to test a different route: turn each employee record into a plain-English sentence and let a GPT-2 Transformer learn from it.

I wrote the GPT-2 architecture myself in PyTorch, loaded the pretrained GPT-2 weights into it, and added four task heads on top: attrition (binary), job level (5 classes), job satisfaction (4 classes), and monthly income (regression). For each task, the target attribute is removed from the sentence and the model predicts it from the final token's hidden state.

The project covers the full workflow: data cleaning and splitting, length-bucketed batching, TensorBoard logging, a pytest suite, saved test-metric reports, and an interactive Gradio app for trying out individual profiles.

The question

Can a GPT-2 Transformer learn tabular HR data if each employee record is rewritten as a plain-English sentence?

Key features

How it works

  1. Clean and split

    The raw HR table is normalized, constant columns are dropped, the targets are encoded, and the rows are split 80/10/10 with a fixed seed.

  2. Records to sentences

    Each record becomes one training sample per task: the target attribute is removed, and the remaining attributes are written as an English sentence and tokenized with the GPT-2 tokenizer.

  3. Shared Transformer backbone

    A GPT-2-style decoder, loaded with pretrained GPT-2 weights, encodes the sentence. Because attention is causal, the last token's hidden state summarizes the whole profile.

  4. Task heads

    The last-token vector goes to the head for that sample's task, either a classifier or a regressor. Classification uses label-smoothed cross-entropy and regression uses a scaled smooth-L1 loss.

  5. Evaluate and serve

    A tester script reports per-task accuracy, MAE, and MSE on the held-out split, and the Gradio app serves the best checkpoint.

Examples

Test-set metrics saved in the repository for the step-10,000 checkpoint: per-task accuracy and loss, plus MAE and MSE for monthly income.
Test-set metrics saved in the repository for the step-10,000 checkpoint: per-task accuracy and loss, plus MAE and MSE for monthly income.

Input

Age 30, business travel: rarely, department: research & development, overtime: no (other attributes omitted)

Output

The employee is 30 years old, ..., travels rarely for work, ..., works in the research & development department, ..., does not work overtime, ...

How part of a record is written as text before tokenization (abbreviated).

Tech stack

What I learned

Limitations