A library to explain whether text is AI-generated or human-written using SHAP
Project description
XAI Text Classifier
A library to explain whether text is AI-generated or human-written using SHAP (SHapley Additive exPlanations).
Features
- AI vs Human Text Classification: Distinguish between AI-generated and human-written text
- Explainability: Uses SHAP to provide detailed feature importance explanations
- Multiple Models: Includes XGBoost and Random Forest models for robust predictions
- Comprehensive Feature Analysis: Analyzes 40+ linguistic features including:
- Readability metrics
- Sentiment analysis
- Syntactic complexity
- Stylistic patterns
- And more
Installation
pip install xai-text-classifier
Or install from source:
git clone <repository-url>
cd xai-text-classifier
pip install -e .
Usage
from xai import shap_explainer
# Analyze text
text = "Your text here..."
result = shap_explainer(text)
# Returns:
# {
# "prediction": 0 or 1, # 0 = Human, 1 = AI
# "features": {
# "feature_name": {
# "value": feature_value,
# "shap_value": shap_contribution,
# "importance": relative_importance
# },
# ...
# }
# }
Requirements
- Python >= 3.8
- joblib
- shap
- xgboost
- spacy
- language-tool-python
- textblob
- pandas
- numpy
- scikit-learn
- nltk
- textstat
- matplotlib
- scipy
Development
Install development dependencies:
pip install -e ".[dev]"
Run tests:
pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use this library in your research, please cite:
@software{xai_text_classifier,
title={XAI Text Classifier},
year={2025},
url={<repository-url>}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xai_text_classifier-0.1.3.tar.gz.
File metadata
- Download URL: xai_text_classifier-0.1.3.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d39fddfb8a6c871a6453760c423f3cc1720bc6479d2d9a0b21ad4a7e2e42d4d
|
|
| MD5 |
d24e91d9a1ea7e044d7a0bdccacd5d5b
|
|
| BLAKE2b-256 |
84c307211236c98696ce1fbec77c3ce224a626b80f4c671bb2207b424eee1b6c
|
File details
Details for the file xai_text_classifier-0.1.3-py3-none-any.whl.
File metadata
- Download URL: xai_text_classifier-0.1.3-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f33018d38288aa82e40df4fa2b29c389c5d40cc8cdd11ff9afe28b36fff7a2f3
|
|
| MD5 |
6656cd506eb97cb88f57f871647ff242
|
|
| BLAKE2b-256 |
aab8be106d1592b4b201b1ece5f5a116ac3846fed8f813cc1ee459aef8dced1e
|