AI Text Detection in Python: How to Identify AI-Generated Content
Have you ever wondered how Medium and other publications might be detecting the text if it is AI generated content or not??
Well, worry not. This article would help you build a basic AI text analyzer after which you can modify this code with yours to make it advanced analyzer.
Author’s note:
Author assumes you understand python and know how to use JupyterLab
Now, let’s get started!
Prerequisites
Run JupyterLab
C:\Users\MyProgram\Files\Jupyter> jupyter lab
Import Libraries
The first step here is to import necessary libraries
Calculate Entropy
Entropy, in ML, means identifying the randomness or unpredictability in a dataset.
This has two values: Low and High.
Low entropy means the text is more predictable, often with repeated patterns.
High entropy means the text is more unpredictable, with a more random texts.
Detect AI?Patterns
Since we are building a basic analyzer, we would use some static text and see if our code detects the text and labels it as AI generated or not.
Identify AI-Generated Content
By using the above two methods, we would define if the text entered is AI generated or not.
领英推荐
For this we need to set the entropy threshold to 3.5.
Entropy between 3 and 4 is often considered to be a threshold entropy value.
Call Our?Methods!
It’s time to call our methods.
Output
To check if our model is working, we would first go to ChatGPT, ask him to generate a sentence for us and then paste that in our example.
Here is the prompt:
Go to your JupyterLab run your code.
It will ask you to enter a prompt to check if it is AI-generated:
Paste the prompt from ChatGPT and see what you get.
Did you get this answer!? Isn’t that great!
Now, try typing something on your own, and see what output it gives.?
Remember, your input may match AI input. In that case it would detect as AI-generated. Try to use some alternative words for it in such cases.
If you get this output pat yourself on your back because we have just created our own basic AI analyzer! Woohoo!! ??
You might need to change the entropy value based on your text complexity. It can be higher than 4 as well.?
You can try testing with whatever value you like just if you are curious to know what happens if you set higher entropy value.
Thank you for reading ??
If you enjoyed reading, be sure to give it a like! Follow and don’t miss out on any of my future posts.
Also, don't forget to comment if you want to share your thoughts on this article or give some suggestions!
Interesting insight Asp.net with c#!