pydetectgpt


Namepydetectgpt JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryEasy to use Python library for detecting AI-generated text
upload_time2024-12-12 18:42:08
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Dylan-Harden3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ai detection llm pytorch
VCS
bugtrack_url
requirements torch numpy transformers
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyDetectGPT
![PyPI](https://img.shields.io/pypi/v/pydetectgpt?color=blue)
[![Downloads](https://static.pepy.tech/badge/pydetectgpt)](https://pepy.tech/project/pydetectgpt)
![License](https://img.shields.io/github/license/Dylan-Harden3/pydetectgpt?style=flat-square)
![CI](https://github.com/Dylan-Harden3/pydetectgpt/actions/workflows/ci.yml/badge.svg)


Python package for AI-generated text detection. Provides a high level api for easy adoption and more granular customization for advanced use cases.

## Quick Start
Implement an AI Plagarism detector in 4 lines of Python:
```python
from pydetectgpt import detect_ai_text

text = "text you want to check here"
result = detect_ai_text(text)
print("AI Generated" if result else "Human Written")
```

On the first run it may some time to load the model from [Hugging Face](https://huggingface.co/). After that it will be *relatively* fast.

## Usage
You can also chose different [Detection Methods](#methods), decision thresholds and use any [transformers](https://huggingface.co/docs/transformers/en/index) model for the logits:
```python
from pydetectgpt import detect_ai_text

text = "text you want to check here"
result = detect_ai_text(text, method="fastdetectgpt", threshold=1.9, model="Qwen/Qwen2.5-1.5B")
print("AI Generated" if result else "Human Written")
```
The default thresholds are:
```
"loglikelihood": -1.8,
"logrank": -0.8,
"detectllm": 2.14,
"fastdetectgpt": 1.9,
```
These were selected to minimize false positives (minimize saying its AI text when its not).

## CLI

There is also a CLI wrapper:
```bash
pydetectgpt "Your text here"
```
> "Detection Result: AI Generated" or "Detection Result: Human Written"

If you want just the 0/1 result (ex for scripting) use the `-q` flag:

```bash
pydetectgpt "Your text here" -q
```
> 0 or 1

For a full list of args see [cli.py](pydetectgpt/cli.py)

## Methods

PyDetectGPT supports four detection methods, in order of effectiveness:

1. **FastDetectGPT** (default): Implementation of [Fast-DetectGPT: Efficient Zero-Shot Detection of Machine-Generated Text][1]
2. **DetectLLM**: Implementation of [DetectLLM: Leveraging Log Rank Information for Zero-Shot Detection of Machine-Generated Text][2]
3. **LogRank**: Average log token rank
4. **LogLikelihood**: Basic log likelihood of the text

[1]: https://arxiv.org/abs/2310.05130 "Fast-DetectGPT: Efficient Zero-Shot Detection of Machine-Generated Text"
[2]: https://arxiv.org/abs/2306.05540 "DetectLLM: Leveraging Log Rank Information for Zero-Shot Detection of Machine-Generated Text"

## Acknowledgements

- [Fast-DetectGPT: Efficient Zero-Shot Detection of Machine-Generated Text][1] (Bao et al., ICLR 2024)
- [DetectLLM: Leveraging Log Rank Information for Zero-Shot Detection of Machine-Generated Text][2] (Su et al., 2023)

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pydetectgpt",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "ai, detection, llm, pytorch",
    "author": null,
    "author_email": "Dylan Harden <dylanharden33@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a6/b2/c24bc4765a6dd80ac821d7bcd93f8b6f9e11c9860dc2dda44837928e50ea/pydetectgpt-0.1.1.tar.gz",
    "platform": null,
    "description": "# PyDetectGPT\r\n![PyPI](https://img.shields.io/pypi/v/pydetectgpt?color=blue)\r\n[![Downloads](https://static.pepy.tech/badge/pydetectgpt)](https://pepy.tech/project/pydetectgpt)\r\n![License](https://img.shields.io/github/license/Dylan-Harden3/pydetectgpt?style=flat-square)\r\n![CI](https://github.com/Dylan-Harden3/pydetectgpt/actions/workflows/ci.yml/badge.svg)\r\n\r\n\r\nPython package for AI-generated text detection. Provides a high level api for easy adoption and more granular customization for advanced use cases.\r\n\r\n## Quick Start\r\nImplement an AI Plagarism detector in 4 lines of Python:\r\n```python\r\nfrom pydetectgpt import detect_ai_text\r\n\r\ntext = \"text you want to check here\"\r\nresult = detect_ai_text(text)\r\nprint(\"AI Generated\" if result else \"Human Written\")\r\n```\r\n\r\nOn the first run it may some time to load the model from [Hugging Face](https://huggingface.co/). After that it will be *relatively* fast.\r\n\r\n## Usage\r\nYou can also chose different [Detection Methods](#methods), decision thresholds and use any [transformers](https://huggingface.co/docs/transformers/en/index) model for the logits:\r\n```python\r\nfrom pydetectgpt import detect_ai_text\r\n\r\ntext = \"text you want to check here\"\r\nresult = detect_ai_text(text, method=\"fastdetectgpt\", threshold=1.9, model=\"Qwen/Qwen2.5-1.5B\")\r\nprint(\"AI Generated\" if result else \"Human Written\")\r\n```\r\nThe default thresholds are:\r\n```\r\n\"loglikelihood\": -1.8,\r\n\"logrank\": -0.8,\r\n\"detectllm\": 2.14,\r\n\"fastdetectgpt\": 1.9,\r\n```\r\nThese were selected to minimize false positives (minimize saying its AI text when its not).\r\n\r\n## CLI\r\n\r\nThere is also a CLI wrapper:\r\n```bash\r\npydetectgpt \"Your text here\"\r\n```\r\n> \"Detection Result: AI Generated\" or \"Detection Result: Human Written\"\r\n\r\nIf you want just the 0/1 result (ex for scripting) use the `-q` flag:\r\n\r\n```bash\r\npydetectgpt \"Your text here\" -q\r\n```\r\n> 0 or 1\r\n\r\nFor a full list of args see [cli.py](pydetectgpt/cli.py)\r\n\r\n## Methods\r\n\r\nPyDetectGPT supports four detection methods, in order of effectiveness:\r\n\r\n1. **FastDetectGPT** (default): Implementation of [Fast-DetectGPT: Efficient Zero-Shot Detection of Machine-Generated Text][1]\r\n2. **DetectLLM**: Implementation of [DetectLLM: Leveraging Log Rank Information for Zero-Shot Detection of Machine-Generated Text][2]\r\n3. **LogRank**: Average log token rank\r\n4. **LogLikelihood**: Basic log likelihood of the text\r\n\r\n[1]: https://arxiv.org/abs/2310.05130 \"Fast-DetectGPT: Efficient Zero-Shot Detection of Machine-Generated Text\"\r\n[2]: https://arxiv.org/abs/2306.05540 \"DetectLLM: Leveraging Log Rank Information for Zero-Shot Detection of Machine-Generated Text\"\r\n\r\n## Acknowledgements\r\n\r\n- [Fast-DetectGPT: Efficient Zero-Shot Detection of Machine-Generated Text][1] (Bao et al., ICLR 2024)\r\n- [DetectLLM: Leveraging Log Rank Information for Zero-Shot Detection of Machine-Generated Text][2] (Su et al., 2023)\r\n\r\n## License\r\n\r\nMIT\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Dylan-Harden3  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Easy to use Python library for detecting AI-generated text",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/Dylan-Harden3/PyDetectGPT",
        "Repository": "https://github.com/Dylan-Harden3/PyDetectGPT"
    },
    "split_keywords": [
        "ai",
        " detection",
        " llm",
        " pytorch"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27e17f6a7c5f026e2687b3eb5a0337241dbcffadc98f14943cb0b144deb53fe5",
                "md5": "e1a0294ef64ce2aad6c6231b75385751",
                "sha256": "282e7c70885714e6b3c7fa9bc6ac54d6d669a07500f09a7d93aba4e8296543bb"
            },
            "downloads": -1,
            "filename": "pydetectgpt-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e1a0294ef64ce2aad6c6231b75385751",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 8701,
            "upload_time": "2024-12-12T18:42:06",
            "upload_time_iso_8601": "2024-12-12T18:42:06.926300Z",
            "url": "https://files.pythonhosted.org/packages/27/e1/7f6a7c5f026e2687b3eb5a0337241dbcffadc98f14943cb0b144deb53fe5/pydetectgpt-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6b2c24bc4765a6dd80ac821d7bcd93f8b6f9e11c9860dc2dda44837928e50ea",
                "md5": "0eca9dfe13651d9b4300fdd830430938",
                "sha256": "7f630d8e6e94e51f12a83beb80677bd32c6b896e40c92a4c121d8ded360395f0"
            },
            "downloads": -1,
            "filename": "pydetectgpt-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0eca9dfe13651d9b4300fdd830430938",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9614,
            "upload_time": "2024-12-12T18:42:08",
            "upload_time_iso_8601": "2024-12-12T18:42:08.056872Z",
            "url": "https://files.pythonhosted.org/packages/a6/b2/c24bc4765a6dd80ac821d7bcd93f8b6f9e11c9860dc2dda44837928e50ea/pydetectgpt-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-12 18:42:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Dylan-Harden3",
    "github_project": "PyDetectGPT",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "torch",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "transformers",
            "specs": []
        }
    ],
    "lcname": "pydetectgpt"
}
        
Elapsed time: 0.42266s