Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xai_text_classifier-0.1.2.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xai_text_classifier-0.1.2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file xai_text_classifier-0.1.2.tar.gz.

File metadata

  • Download URL: xai_text_classifier-0.1.2.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for xai_text_classifier-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f4c278379a08c09fdd9551e4e8f9fadff0f16a548826a2bb31bc3a518fccecec
MD5 d4914af4d2f1ba92ed8326b67cad585e
BLAKE2b-256 fdd9931a559c3fb53a24c942b44dd115ffbe9520dbf9472c6307ead602168ee2

See more details on using hashes here.

File details

Details for the file xai_text_classifier-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for xai_text_classifier-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0c8a88c6414f39165b3fec156c37c8b632f920c158795665fa832de081584879
MD5 bddb8fbcea2ba8224d6b72fdad2ef3ed
BLAKE2b-256 fa95010fc79fa5756f14c29a2a7067f80b3885ec008bc7f355fd4bda89c74729

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page