KPMG pulled its AI report after UBS, the NHS, and others said its claims about them were made up
Back to Tutorials
aiTutorialbeginner

KPMG pulled its AI report after UBS, the NHS, and others said its claims about them were made up

June 13, 202643 views6 min read

Learn to build an AI content checker that can detect false claims in AI-generated text, similar to the KPMG case where false claims about organizations were made.

Introduction

In today's world, artificial intelligence (AI) is everywhere, from smart assistants to automated customer service. However, AI systems can sometimes produce inaccurate or false information, a problem known as "hallucinations." This tutorial will teach you how to detect and prevent AI hallucinations in your own projects. We'll build a simple AI content checker that can help identify false claims in AI-generated text, similar to what happened in the KPMG case where false claims were made about organizations.

Prerequisites

  • Basic understanding of Python programming
  • Python installed on your computer
  • Internet connection to download required packages

Step-by-Step Instructions

Step 1: Install Required Python Packages

First, we need to install the packages that will help us work with AI and text analysis. Open your terminal or command prompt and run:

pip install transformers torch

Why: The transformers library from Hugging Face provides pre-trained models that can analyze text, while torch is the deep learning framework that supports these models.

Step 2: Create a Basic AI Content Checker

Let's create a Python script that will help us detect potentially false information in AI-generated content. Create a new file called ai_checker.py:

import torch
from transformers import pipeline

# Initialize the text classification pipeline
classifier = pipeline("text-classification", model="facebook/bart-large-mnli")

def check_content(text):
    # This function will analyze the text for factual accuracy
    print(f"Analyzing: {text}")
    return "This is a basic AI content checker."

# Example usage
if __name__ == "__main__":
    sample_text = "KPMG reported that UBS uses AI for fraud detection."
    result = check_content(sample_text)
    print(result)

Why: This sets up our basic framework. We're using a pre-trained model that can classify text, which is a good starting point for detecting inconsistencies.

Step 3: Add Factual Verification Logic

Now we'll enhance our checker to look for potential false claims. Update your ai_checker.py file:

import torch
from transformers import pipeline

# Initialize the text classification pipeline
classifier = pipeline("text-classification", model="facebook/bart-large-mnli")

# Define known facts about organizations
known_facts = {
    "UBS": "UBS is a Swiss multinational investment bank and financial services company.",
    "NHS": "The National Health Service is the publicly funded healthcare system of the United Kingdom.",
    "KPMG": "KPMG is a global network of professional services firms providing audit, tax, and advisory services."
}

def check_content(text):
    print(f"Analyzing: {text}")
    
    # Check if any organization names are mentioned
    for org_name in known_facts.keys():
        if org_name.lower() in text.lower():
            print(f"Warning: Organization {org_name} mentioned in text.")
            print(f"Known fact about {org_name}: {known_facts[org_name]}")
            
    # Use AI to analyze the text
    try:
        result = classifier(text)
        print(f"AI Analysis Result: {result}")
    except Exception as e:
        print(f"Error in AI analysis: {e}")
    
    return "Analysis complete."

# Example usage
if __name__ == "__main__":
    sample_text = "KPMG reported that UBS uses AI for fraud detection."
    result = check_content(sample_text)
    print(result)

Why: This adds a database of known facts about organizations, allowing us to compare AI-generated claims against verified information. If an AI makes a claim that contradicts known facts, we can flag it.

Step 4: Implement a Simple Fact-Checking Function

Let's add a more sophisticated fact-checking mechanism:

import torch
from transformers import pipeline

# Initialize the text classification pipeline
classifier = pipeline("text-classification", model="facebook/bart-large-mnli")

# Define known facts about organizations
known_facts = {
    "UBS": "UBS is a Swiss multinational investment bank and financial services company.",
    "NHS": "The National Health Service is the publicly funded healthcare system of the United Kingdom.",
    "KPMG": "KPMG is a global network of professional services firms providing audit, tax, and advisory services."
}

# Define what we consider false claims
false_claims = [
    "UBS uses AI for fraud detection",  # This might be false
    "NHS uses AI for patient diagnosis",  # This might be false
    "KPMG uses AI for financial forecasting"  # This might be false
]

def check_content(text):
    print(f"Analyzing: {text}")
    
    # Check for organization mentions
    for org_name in known_facts.keys():
        if org_name.lower() in text.lower():
            print(f"Warning: Organization {org_name} mentioned in text.")
            print(f"Known fact about {org_name}: {known_facts[org_name]}")
            
    # Check for false claims
    for claim in false_claims:
        if claim.lower() in text.lower():
            print(f"\n❌ Potential false claim detected: {claim}")
            print("This claim may not be accurate based on known facts.")
            
    # Use AI to analyze the text
    try:
        result = classifier(text)
        print(f"\nAI Analysis Result: {result}")
    except Exception as e:
        print(f"Error in AI analysis: {e}")
    
    return "Analysis complete."

# Example usage
if __name__ == "__main__":
    sample_text = "KPMG reported that UBS uses AI for fraud detection."
    result = check_content(sample_text)
    print(f"\n{result}")

Why: This creates a database of known facts and false claims, allowing our checker to compare AI-generated text against verified information. This is crucial for detecting the type of misinformation that led to KPMG's report being pulled.

Step 5: Test Your AI Checker

Run your script to see how it handles different inputs:

python ai_checker.py

Try different inputs to see how your checker responds:

  1. "KPMG reported that UBS uses AI for fraud detection."
  2. "KPMG is a global network of professional services firms providing audit, tax, and advisory services."
  3. "NHS uses AI for patient diagnosis."

Why: Testing with various inputs helps you understand how your checker works and where it might need improvement.

Step 6: Enhance Your Checker with External APIs

For a more advanced version, we can integrate with external fact-checking APIs. Here's an example:

import requests
import torch
from transformers import pipeline

# Initialize the text classification pipeline
classifier = pipeline("text-classification", model="facebook/bart-large-mnli")

# Define known facts about organizations
known_facts = {
    "UBS": "UBS is a Swiss multinational investment bank and financial services company.",
    "NHS": "The National Health Service is the publicly funded healthcare system of the United Kingdom.",
    "KPMG": "KPMG is a global network of professional services firms providing audit, tax, and advisory services."
}

def check_external_fact(url):
    # This would call an external fact-checking API
    try:
        response = requests.get(url)
        if response.status_code == 200:
            return response.json()
        else:
            return "Error fetching fact-checking data"
    except Exception as e:
        return f"Error: {e}"

def check_content(text):
    print(f"Analyzing: {text}")
    
    # Check for organization mentions
    for org_name in known_facts.keys():
        if org_name.lower() in text.lower():
            print(f"Warning: Organization {org_name} mentioned in text.")
            print(f"Known fact about {org_name}: {known_facts[org_name]}")
            
    # Check for false claims
    false_claims = [
        "UBS uses AI for fraud detection",
        "NHS uses AI for patient diagnosis",
        "KPMG uses AI for financial forecasting"
    ]
    
    for claim in false_claims:
        if claim.lower() in text.lower():
            print(f"\n❌ Potential false claim detected: {claim}")
            print("This claim may not be accurate based on known facts.")
            
    # Use AI to analyze the text
    try:
        result = classifier(text)
        print(f"\nAI Analysis Result: {result}")
    except Exception as e:
        print(f"Error in AI analysis: {e}")
    
    return "Analysis complete."

# Example usage
if __name__ == "__main__":
    sample_text = "KPMG reported that UBS uses AI for fraud detection."
    result = check_content(sample_text)
    print(f"\n{result}")

Why: Integrating with external APIs allows your checker to access real-time, verified information, making it more accurate at detecting misinformation.

Summary

In this tutorial, you've learned how to create a basic AI content checker that can help detect false claims in AI-generated text. You've built a system that:

  • Uses pre-trained AI models to analyze text
  • Checks for organization mentions
  • Compares claims against known facts
  • Flags potential false information

This is similar to what happened with KPMG's AI report, where false claims were made about organizations. By building tools like this, you can help ensure that AI-generated content is accurate and reliable. As AI continues to evolve, tools for detecting misinformation become increasingly important to maintain trust in AI systems.

Source: TNW Neural

Related Articles