Downloads · 30 days
6
9% of all-time downloads
huzaifanasirrr/human-vs-ai-text-classifier
human-vs-ai-text-classifier is a text classification model from huzaifanasirrr. Use it when you need a label for a piece of text. It is set up for scikit-learn. The card lists the license as mit.
[](https://www.python.org/downloads/) [](https://scikit-learn.org/) [](https://pytorch.org/) [](https://tensorflow.org/)
Downloads · 30 days
6
9% of all-time downloads
All-time downloads
64
Public
Repo size
493 MB
Likes
1
Public
Click a slice to open those files.
.pt438 MB · 89%
From the Hugging Face model README
A comprehensive ensemble-based text classification system that distinguishes between human-written and AI-generated text with high accuracy. This implementation combines traditional machine learning (Logistic Regression, Random Forest, SVM, XGBoost) and deep learning approaches (BiLSTM with Attention, BERT) using advanced ensemble techniques.
Key Features:
Input Text
↓
[Feature Engineering]
├─→ TF-IDF Vectorization (5,000 features)
│ - Unigrams & Bigrams
│ - Max DF: 0.95, Min DF: 2
│
└─→ Linguistic Features (15 features)
- Text length, word count, sentence count
- Lexical diversity (TTR)
- Stopword/punctuation ratios
- Statistical text properties
↓
Multi-Modal Feature Vector (5,015 dimensions)
↓
┌──────────────────────────────────────────────┐
│ Base Classifiers (Parallel) │
├──────────────────────────────────────────────┤
│ Traditional ML │ Deep Learning │
├─────────────────────────┼────────────────────┤
│ • Logistic Regression │ • BERT │
│ • Random Forest (200) │ (bert-base) │
│ • SVM (RBF kernel) │ • BiLSTM+Attention │
│ • XGBoost (200 trees) │ (64 units) │
└─────────────────────────┴────────────────────┘
↓
[Ensemble Aggregation]
├─→ Hard Voting (Majority vote)
├─→ Soft Voting (Probability averaging)
├─→ Weighted Average (Optimized weights)
└─→ Stacking (Meta-learner: Logistic Regression)
↓
Final Prediction: Human (0) or AI (1)
Individual Model Specifications:
| Model | Type | Parameters | Key Configuration |
|---|---|---|---|
| Logistic Regression | Linear | 5,015 | C=1.0, L2 regularization, LBFGS solver |
| Random Forest | Ensemble Trees | - | 200 estimators, unlimited depth |
| SVM | Kernel Method | - | RBF kernel, C=1.0, gamma=scale |
| XGBoost | Gradient Boosting | - | 200 trees, depth=7, LR=0.1 |
| BiLSTM | Recurrent NN | ~500K | 64 units/dir, attention, dropout=0.5 |
| BERT | Transformer | 110M | bert-base-uncased, max_len=128 |
| Model | Accuracy | Precision | Recall | F1-Score | ROC-AUC |
|---|---|---|---|---|---|
| XGBoost | 0.9903 | 0.9838 | 0.9970 | 0.9904 | 0.9994 |
| Logistic Regression | 0.9897 | 0.9827 | 0.9970 | 0.9898 | 0.9996 |
| SVM | 0.9867 | 0.9807 | 0.9929 | 0.9867 | 0.9991 |
| BERT | 0.9727 | 0.9510 | 0.9967 | 0.9733 | 0.9975 |
| BiLSTM | 0.9710 | 0.9668 | 0.9756 | 0.9712 | 0.9963 |
| Random Forest | 0.9573 | 0.9571 | 0.9576 | 0.9573 | 0.9922 |
| Method | Accuracy | Precision | Recall | F1-Score | ROC-AUC |
|---|---|---|---|---|---|
| Weighted Average ⭐ | 0.9959 | 0.9959 | 0.9959 | 0.9959 | 0.9998 |
| Stacking | 0.9956 | 0.9947 | 0.9964 | 0.9956 | 0.9998 |
| Soft Voting | 0.9945 | 0.9937 | 0.9954 | 0.9945 | 0.9998 |
| Hard Voting | 0.9921 | 0.9944 | 0.9898 | 0.9921 | 0.9998 |
Optimized Ensemble Weights:
Confusion Matrix (Weighted Ensemble):
Predicted
Human AI
Actual Human 3918 16
AI 16 3918
Dataset:
Feature Engineering:
Training Configuration:
Traditional ML Models:
Deep Learning Models:
Hardware:
git clone https://github.com/huzaifanasir95/Human-vs-AI-Classifier.git
cd Human-vs-AI-Classifier
pip install -r requirements.txt
from huggingface_hub import hf_hub_download
import pickle
import torch
# Download traditional ML models
models = ['logistic_regression', 'random_forest', 'svm', 'xgboost']
for model_name in models:
model_path = hf_hub_download(
repo_id="huzaifanasirrr/human-vs-ai-text-classifier",
filename=f"models/{model_name}.pkl"
)
with open(model_path, 'rb') as f:
model = pickle.load(f)
# Download deep learning models
bert_path = hf_hub_download(
repo_id="huzaifanasirrr/human-vs-ai-text-classifier",
filename="models/bert_best.pt"
)
bilstm_path = hf_hub_download(
repo_id="huzaifanasirrr/human-vs-ai-text-classifier",
filename="models/bilstm_best.h5"
)
from src.feature_extractor import FeatureExtractor
from src.models.ensemble import WeightedEnsemble
import numpy as np
# Initialize feature extractor
feature_extractor = FeatureExtractor(
max_features=5000,
ngram_range=(1, 2)
)
# Extract features from text
text = "Your text to classify here..."
features = feature_extractor.extract(text) # Shape: (5015,)
# Load ensemble
ensemble = WeightedEnsemble(
models=[lr_model, rf_model, svm_model, xgb_model, bert_model, bilstm_model],
weights=[0.20, 0.10, 0.15, 0.25, 0.20, 0.10]
)
# Predict
prediction = ensemble.predict(features)
probability = ensemble.predict_proba(features)
if prediction == 0:
print(f"Human-written (confidence: {probability[0]:.2%})")
else:
print(f"AI-generated (confidence: {probability[1]:.2%})")
# Using XGBoost (best individual model)
xgb_prediction = xgb_model.predict(features.reshape(1, -1))
xgb_proba = xgb_model.predict_proba(features.reshape(1, -1))
print(f"Prediction: {'AI' if xgb_prediction[0] else 'Human'}")
print(f"Confidence: {xgb_proba[0][xgb_prediction[0]]:.2%}")
Based on XGBoost analysis:
| Feature Type | Importance |
|---|---|
| TF-IDF Features | 89.2% |
| Average Sentence Length | 4.3% |
| Lexical Diversity (TTR) | 2.7% |
| Unique Words Ratio | 1.5% |
| Average Word Length | 1.1% |
| Others | 1.2% |
Insight: Vocabulary patterns dominate, but linguistic features provide crucial complementary information.
If you use this model in your research, please cite:
@article{nasir2025humanaiclassifier,
title={Human vs. AI Text Classification: A Comprehensive Study Using Machine Learning and Deep Learning Approaches},
author={Nasir, Huzaifa},
institution={National University of Computer and Emerging Sciences, Pakistan},
year={2025},
note={Hugging Face: https://huggingface.co/huzaifanasirrr/human-vs-ai-text-classifier}
}
HC3 Dataset:
@article{guo2023hc3,
title={How Close is ChatGPT to Human Experts? Comparison Corpus, Evaluation, and Detection},
author={Guo, Biyang and Zhang, Xin and Wang, Ziyuan and Jiang, Minqi and Nie, Jinran and Ding, Yuxuan and ... and Wu, Yupeng},
journal={arXiv preprint arXiv:2301.07597},
year={2023}
}
models/*.pkl - Traditional ML models (Logistic Regression, Random Forest, SVM, XGBoost)models/bert_best.pt - Fine-tuned BERT model checkpointmodels/bilstm_best.h5 - BiLSTM with Attention modelresults/*.json - Comprehensive performance metricsdata/feature_info.json - Feature vocabulary and metadatavisualizations/*.png - Training curves, confusion matrices, ROC curves, comparisonsconfig.yaml - Configuration settingsresearch_paper.tex - Full research paper (SPRINGER LNCS format)⚠️ Important Notice:
This model is designed for research and educational purposes. When deploying for real-world applications:
Detection systems should support human judgment, not replace it.
Huzaifa Nasir
📧 [email protected]
🎓 National University of Computer and Emerging Sciences (FAST-NUCES), Pakistan
🔗 GitHub Repository
🆔 ORCID: 0009-0000-1482-3268
MIT License - See LICENSE file for details.
This project builds upon:
Research conducted at FAST-NUCES Islamabad. Special thanks to the open-source community.
Status: ✅ Production-ready | Last updated: January 2025