representation-engineering

Detect and steer LLM internal representations using RepReading and RepControl pipelines.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Monitoring and controlling what happens inside large language models is difficult with black-box prompting alone. This Skill implements Representation Engineering (RepE), letting you read internal activations to detect concepts like honesty or emotion, and inject direction vectors to steer model behavior at the representation level. ## Core Features & Use Cases - RepReading Pipeline: Train linear probes (PCA or cluster-mean directions) on contrastive prompt pairs to classify internal representations across model layers for honesty, emotions, fairness, memorization, and harmlessness. - RepControl Pipeline: Inject scaled direction vectors into hidden states during generation to steer outputs toward or away from target concepts, integrated with HuggingFace pipelines. - Evaluation & Finetuning: Use the RepE_eval framework as an alternative to zero-shot/few-shot baselines, and LoRRA finetuning for representation-aware training. - Use Case: Build a truthfulness monitor for a LLaMA-2 chat model by training a rep reader on true/false statement pairs, then score new generations layer-by-layer to flag deceptive outputs. ## Quick Start Ask the assistant to train a RepReading honesty detector on a HuggingFace causal model using contrastive true/false statement pairs and then steer generation with the resulting direction vector.

Frequently Asked Questions about representation-engineering

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

FAQPage Schema
How do I detect honesty in LLM outputs with representation engineering?

Build a contrastive dataset of honest versus dishonest prompt framings, then call get_directions on the rep-reading pipeline with PCA to find the honesty direction per layer. Score new inputs by passing them through the pipeline with the trained RepReader.

How to steer LLM generation using RepControl?

Create a rep-control pipeline specifying target layers and block_name, then pass an activations dict mapping layer indices to direction vectors scaled by a control coefficient. Positive coefficients steer toward the concept; negative values steer away.

Which models work with the RepE rep-reading pipeline?

Any HuggingFace causal language model with decoder layers works, including LLaMA-2-7b/13b-chat, Mistral-7B-Instruct, and LLaMA-3-8B-Instruct. You must match the user_tag and assistant_tag to the model's chat template.

What is the difference between PCA and cluster_mean direction methods?

PCA finds the principal component of variation between contrastive representation pairs and is the default, most robust option. Cluster_mean uses the difference between class centroids instead, which is simpler but can be less stable on noisy data.

Why does RepControl degrade generation fluency?

Large control coefficients over-perturb hidden states, producing incoherent text. Start with small magnitudes around 10 to 20, inject into middle-to-late layers only, and tune the coefficient while monitoring output quality.