Create a program to detect A.I. in written documents
2023-3-5 03:15:43 Author: krypt3ia.wordpress.com(查看原文) 阅读量:3 收藏

This article is part of an ongoing experiment with the use of ChatGPT for developing primers on cyber security topics.

As an AI language model myself, I must clarify that detecting AI in written documents could have multiple meanings, such as:

  1. Detecting the presence of AI-related terms and technologies in a document.
  2. Determining whether the text has been written by a human or an AI language model.
  3. Identifying the intent behind the text to assess whether it has been generated by an AI system.

Here’s an example program to detect the presence of AI-related terms and technologies in a document:

pythonCopy codeimport re

def detect_ai(text):
    # Define a list of AI-related terms and technologies
    ai_terms = ['AI', 'Artificial Intelligence', 'Machine Learning', 'Neural Networks', 'Deep Learning', 'NLP', 'Robotics']

    # Use regular expressions to find any occurrence of AI terms in the text
    pattern = re.compile('|'.join(ai_terms), re.IGNORECASE)
    matches = pattern.findall(text)

    # Return True if there is at least one match, False otherwise
    if len(matches) > 0:
        return True
    else:
        return False

Here’s an example program to determine whether the text has been written by a human or an AI language model:

pythonCopy codeimport openai
import re

openai.api_key = "YOUR_API_KEY"

def detect_ai(text):
    # Use the OpenAI GPT-3 language model to generate text based on the input
    response = openai.Completion.create(
      engine="davinci",
      prompt=text,
      max_tokens=1,
      n=1,
      stop=None,
      temperature=0.0
    )

    # Use regular expressions to check whether the response contains machine-generated text
    pattern = re.compile('[^\x00-\x7F]')
    matches = pattern.findall(response.choices[0].text)

    # Return True if the response contains non-ASCII characters, False otherwise
    if len(matches) > 0:
        return True
    else:
        return False

Note that this second program requires an API key from OpenAI to use their GPT-3 language model. Also, it should be noted that this program has limitations, as some human-written text can be very similar to text generated by an AI language model.

Finally, here’s an example program to identify the intent behind the text to assess whether it has been generated by an AI system:

pythonCopy codeimport openai
import re

openai.api_key = "YOUR_API_KEY"

def detect_ai(text):
    # Use the OpenAI GPT-3 language model to generate text based on the input
    response = openai.Completion.create(
      engine="davinci",
      prompt=text,
      max_tokens=1,
      n=1,
      stop=None,
      temperature=0.0
    )

    # Use regular expressions to check whether the response contains certain keywords or phrases
    pattern = re.compile('(I think|In my opinion|Based on my analysis|According to my calculations)', re.IGNORECASE)
    matches = pattern.findall(response.choices[0].text)

    # Return True if the response contains one of the specified phrases, False otherwise
    if len(matches) > 0:
        return True
    else:
        return False

This program assumes that AI-generated text is more likely to contain phrases that indicate a lack of human subjectivity or emotion, such as “According to my calculations.” Again, this program has limitations and may not always accurately identify text generated by an AI system.

Krypt3ia generated this text with ChatGPT, OpenAI’s large-scale language-generation model. This author reviewed, edited, and revised the language to my own liking and takes ultimate responsibility for the content of this publication


文章来源: https://krypt3ia.wordpress.com/2023/03/04/create-a-program-to-detect-a-i-in-written-documents/
如有侵权请联系:admin#unsafe.sh