πŸ” Text Fluoroscopy: Detecting LLM-Generated Text through Intrinsic Features (EMNLP 2024 Main Track)

February 21, 2025 Β· View on GitHub

Paper GitHub Stars Python 3.8+

Text Fluoroscopy: we propose Text Fluoroscopy, a black-box method for LLM-generated text detection through intrinsic features. Our method captures the text’s intrinsic features by identifying the layer with the largest distribution difference from the last and first layers when projected to the vocabulary space.

Text Fluoroscopy Architecture

πŸ“‹ Overview

Most LLM detection methods focus on either semantic features (from the last layer) or simple linguistic features (from early layers). Text Fluoroscopy takes a different approach by:

  1. Finding the model layer with the largest distribution difference from both first and last layers
  2. Extracting intrinsic text features that reveal the actual "fingerprints" of AI generation
  3. Achieving superior generalization and robustness across different domains and against paraphrase attacks

πŸš€ Getting Started

Prerequisites

  • Python 3.8+
  • PyTorch 1.10+
  • CUDA-compatible GPU

Installation

git clone https://github.com/Fish-and-Sheep/Text-Fluoroscopy.git
cd Text-Fluoroscopy
pip install -r requirements.txt

Step 1: Download the LLM Model

huggingface-cli download --resume-download Alibaba-NLP/gte-Qwen1.5-7B-instruct \
  --local-dir ../huggingface_model/gte-Qwen1.5-7B-instruct \
  --cache-dir ../huggingface_model/gte-Qwen1.5-7B-instruct \
  --local-dir-use-symlinks False

Step 2: Extract Features and Calculate KL Divergence

python gte-qwen/save_KL_with_first_and_last_layer.py

python gte-qwen/save_embedding.py

Step 3: Train Classifier and Test

python embedding_classify/classify_with_max_KL_layer.py

⚑ Optimization Strategies

Although our dynamic layer-selection method is effective, the computational overhead of examining each layer introduces time delays. To address this limitation, we provide an alternative approach:

MethodsChatGPTGPT-4Claude3
Detection with the Last Layer0.07s0.09s0.08s
Text Fluoroscopy0.52s0.51s0.49s
Detection with the 30-th layer0.08s0.08s0.07s

As shown above:

  • We identified that using the fixed 30th layer offers an excellent balance between accuracy and speed
  • This optimization reduces processing time by ~6.5Γ— with less than 0.7% accuracy reduction
  • The 30th layer approach maintains the core benefits of our method while being nearly as fast as last-layer-only methods
Results

πŸ”„ Applicability Across LLMs

Text Fluoroscopy is not limited to a specific encoder model. We tested our approach with multiple LLMs to demonstrate its broad applicability:

LLMLayerChatGPTGPT-4Claude3
XSumWritingPubMedAvg.XSumWritingPubMedAvg.XSumWritingPubMedAvg.
gte-Qwen2-7BLast0.96580.97100.61860.85180.97110.97580.68470.87720.94720.98360.80110.9106
Middle0.99880.98340.77440.91890.99960.98720.84160.94280.99940.99530.93730.9773
stella_en_1.5B_v5Last0.89280.98020.69660.85650.89960.97080.72930.86660.89710.97580.86460.9125
Middle1.00000.99210.66110.88441.00000.98730.69550.89430.99970.98340.89550.9595
GPT-neo-2.7BLast0.62700.71900.60790.65130.73170.79700.48830.67240.96740.99810.87690.9475
Middle0.85680.89160.60790.78540.90050.91370.50270.77230.99450.99330.93500.9743

As shown in the table above:

  • Our method consistently outperforms the last-layer approach across different encoder architectures
  • We tested with both advanced models (gte-Qwen2-7B, stella_en_1.5B_v5) and classical models (GPT-neo-2.7B)
  • The improvement is especially significant when detecting ChatGPT and GPT-4 generated content
  • This demonstrates that Text Fluoroscopy's core principle of leveraging intrinsic features from middle layers is valid across LLM architectures

πŸ“š Citation

If you find our work useful, please consider citing our paper:

@inproceedings{yu2024textfluoroscopy,
    title={Text Fluoroscopy: Detecting LLM-Generated Text through Intrinsic Features},
    author={Yu, Xiao and Chen, Kejiang and Yang, Qi and Zhang, Weiming and Yu, Nenghai},
    booktitle={Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing (EMNLP)},
    year={2024},
    url={https://aclanthology.org/2024.emnlp-main.885.pdf}
}

πŸ“¬ Contact

For questions or feedback, please open an issue or contact us at Xiao Yu.