This repository provides a machine learning pipeline for predicting the Big Five personality traits (OCEAN) from text input. It combines DistilBERT embeddings, LIWC-style linguistic features, and a set of Random Forest classifiers — one for each trait — trained on annotated personality data.
Each trait is predicted as a categorical label: low, medium, or high.
distilbert/distilbert-base-cased-distilled-squad.output.dic).from personality_model import PersonalityClassifier
model = PersonalityClassifier()
text = "I enjoy solving challenging problems and thinking about philosophical questions."
predictions = model.predict_all_traits(text)
print(predictions)
# Output:
# {
# 'Openness': 'high',
# 'Conscientiousness': 'medium',
# 'Extraversion': 'low',
# 'Agreeableness': 'medium',
# 'Emotional stability': 'low'
# }
After cloning the project, you can run two files to get the predictions:
For a demo use test_personality_model.py A text passage is provided inside the script that will be used for getting predictions.
For working with structured data with text, use predict_from_csv.ipynb Change the input and output path to path to test data. The script will extract texts under Q1, Q2 and Q3, concatenate them and passes the full text into the PersonalityClassifier(). It will automatically replace (or pass) model predictions for the five personalities. All the other columns of the CSV file will be untouched. The output is the same CSV file with labels for the OCEAN traits.
We recommend creating a conda environment. Clone the repository and install dependencies:
git clone https://huggingface.co/Arash-Alborz/personality-trait-predictor
cd personality-trait-predictor
# Create a conda environment
conda create -n personality_env python=3.9
conda activate personality_env
# Install dependencies
pip install -r requirements.txt
personality-trait-predictor/
├── personality_model.py # Main class for prediction
├── requirements.txt
├── README.md
├── .gitignore
├── .gitattributes
├── models/
│ ├── feature_scaler.pkl # StandardScaler for feature scaling
│ ├── output.dic # LIWC-style dictionary
│ ├── openness_classifier.pkl # Classifiers ...
│ ├── conscientiousness_classifier.pkl
│ ├── extraversion_classifier.pkl
│ ├── agreeableness_classifier.pkl
│ ├── emotional_stability_classifier.pkl
├── feature_extraction/
│ ├── __init__.py
│ ├── embedding_from_text.py # Embeddings extraction with BERT
│ ├── liwc_from_text.py # LIWC feature extraction
DistilBERT (CLS token from distilbert-base-cased-distilled-squad)RandomForestClassifier per trait, tuned with custom hyperparametersStandardScalerlow, medium, or highn_estimators, max_depth) were manually optimized per trait for best F1-score.For more information about evaluation, visit our project GitHub page
| Trait | Accuracy | Macro F1-score |
|---|---|---|
| Openness | 0.62 | 0.47 |
| Conscientiousness | 0.62 | 0.48 |
| Extraversion | 0.47 | 0.44 |
| Agreeableness | 0.38 | 0.36 |
| Emotional stability | 0.53 | 0.47 |
pipeline() interface because it integrates custom feature engineering steps.PersonalityClassifier directly to use the model.Dependencies include:
University of Antwerp – "Digital Text Analysis", AMIV-NLP-2025
This project is licensed under the MIT License.