layer-wise-representation

Edits LLM internal representations with TruthX vectors to control truthfulness and reduce hallucinations.

75|7|Updated May 2, 2026
One-click install
npx skills add https://github.com/zjunlp/Mechanist --skill layer-wise-representation-zjunlp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: layer-wise-representation
Source: https://github.com/zjunlp/Mechanist/tree/main/skills/mechanism-skills/magnitude-analysis/layer-wise-representation
Command: npx skills add https://github.com/zjunlp/Mechanist --skill layer-wise-representation-zjunlp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, transformers, numpy, and includes scripts (resource) and references (resource) components.

What problem does it solve? Large language models often generate hallucinated or untruthful answers, and retraining them is expensive. This Skill applies TruthX, an inference-time representation editing method, to steer model outputs toward truthfulness without fine-tuning. ## Core Features & Use Cases - TruthX Representation Editing: Load TruthX checkpoints and apply editing vectors to selected model layers with configurable strength, supporting both truthful and hallucinatory modes for comparison. - TruthfulQA Benchmark Evaluation: Run MC1, MC2, and open-ended generation evaluations on the TruthfulQA dataset with few-shot prompting support. - Interactive and Batch Inference: Generate responses from TruthX-enhanced models via single prompts, batch processing, or an interactive chat loop. - Use Case: A researcher evaluating hallucination mitigation can load Llama-2-7b-chat with a TruthX checkpoint, generate baseline versus truthful versus hallucinatory responses for the same question, and quantify improvements with TruthfulQA MC1/MC2 metrics. ## Quick Start Apply TruthX editing to Llama-2-7b-chat and compare baseline, truthful, and hallucinatory responses for a sample question.

Frequently Asked Questions about layer-wise-representation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce hallucinations in LLM outputs without fine-tuning?

TruthX edits internal representations at inference time by applying pre-trained editing vectors to selected model layers. Load a TruthX checkpoint for your base model, set an edit strength, and generate responses without any weight retraining.

How do I evaluate a model on the TruthfulQA benchmark?

Use the truthfulqa_evaluation.py script with a model path and the TruthfulQA CSV dataset. It supports MC1, MC2, and open-ended generation tasks, with optional few-shot prompting, and saves metrics to a JSON file.

Which models have pre-trained TruthX checkpoints available?

Checkpoints exist for Llama-1, Alpaca, Llama-2 base and chat (7B and 13B), Vicuna v1.5, Mistral v0.1 and v0.2 variants, Baichuan2, and ChatGLM3. They are distributed via the ICTNLP Hugging Face repository.

What does the edit_strength parameter control in TruthX?

The edit_strength parameter scales the editing vectors applied to model layers, ranging from -5.0 to 5.0. Positive values steer toward truthful outputs while negative values induce hallucinatory behavior for comparison experiments.

Can TruthX editing run on CPU instead of GPU?

The scripts fall back to CPU with float32 precision when CUDA is unavailable. However, inference with 7B-scale models on CPU is significantly slower, so a CUDA-capable GPU is recommended for practical use.