Skip to main content

A library to explain whether text is AI-generated or human-written using SHAP

Project description

Detect and explain AI generated text

A library to detect and 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 explain_ai_generated_text

Or install from source:

git clone <repository-url>
cd explain_ai_generated_text
pip install -e .

Usage

from explain_ai_generated_text 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{explain_ai_generated_text,
  title={Explainable AI Generated Text Detection},
  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

explain_ai_generated_text-0.1.1.1.7.tar.gz (5.3 MB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file explain_ai_generated_text-0.1.1.1.7.tar.gz.

File metadata

File hashes

Hashes for explain_ai_generated_text-0.1.1.1.7.tar.gz
Algorithm Hash digest
SHA256 0426caaf3e79b5a017939be7bdd30f3dc9f72904c03037de2fb0db1b33d44a7e
MD5 87028196386efa58cc502fd8f9bdd2ee
BLAKE2b-256 cde518bb17db7859f0b62374c855694342e1984773cdd0165db5d3ca0751f985

See more details on using hashes here.

File details

Details for the file explain_ai_generated_text-0.1.1.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for explain_ai_generated_text-0.1.1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3ddc6c63e3ffdfacb992bbfa5f79589c0078a552ceee9eae1bcc5e4ceeb8332d
MD5 e58d15bcd7704ea3301d23288d5a6874
BLAKE2b-256 d7724b2065630357f4c73bdd400b3e33292ef285487902e9f8cc1ce6e313a4db

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