8000 GitHub - blei-lab/care · GitHub
[go: up one dir, main page]

Skip to content
blei-labPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

CARE: Context-Aided Representation Extraction

"Do You CARE to Generalize? Extracting Robust Concept Directions in LLMs" (NeurIPS 2026).

See below for how to cite CARE.

A concept direction is a vector in a language model's activation space that tracks a high-level concept, such as whether a prompt is harmful. A direction learned in one context often fails in another: a new prompt style, a new source dataset, a new target group. CARE treats these contexts as environments and learns a direction that decomposes into two parts:

  • a shared direction w0, common to all environments, and
  • an environment-specific residual r_e for each environment e, orthogonal to w0.

At inference time, CARE(S) uses the shared direction alone and CARE(C) adds the residual of the example's environment.

CARE decomposes concept directions into shared and environment-specific components

Figure 1 of the paper.

Repository layout

care/           The method. About 400 lines, depends only on PyTorch.
  model.py        CAREModel: the shared direction, the residuals, and the two inference modes
  losses.py       joint loss, environment signal loss, and the V-REx / IRM / GroupDRO regularizers
  trainer.py      training loop
experiments/    Everything used to produce the results in the paper (see experiments/README.md)

If you want to use CARE on your own activations, care/ is all you need.

Installation

git clone https://github.com/blei-lab/care.git
cd care
pip install -e .                  # the method only
pip install -e ".[experiments]"   # plus everything needed to reproduce the paper

Quick start

CARE takes three tensors: activations of a language model (one vector per example, taken at a fixed layer and token position), binary concept labels, and the environment of each example.

import torch
from care import CAREConfig, fit_care

activations = ...  # [N, d] float tensor
labels = ...       # [N] concept labels in {0, 1}
envs = ...         # [N] environment indices in {0, ..., E-1}

config = CAREConfig(
    joint_weight=1.0,          # joint loss
    env_signal_weight=0.3,     # environment signal loss
    regularizer="vrex",        # "none" (CARE-Base), "vrex", "irm", or "groupdro"
    regularizer_weight=0.3,
)
model = fit_care(activations, labels, envs, config, seed=0)

w0 = model.shared_direction()            # [d]     unit-norm shared direction
residuals = model.residual_directions()  # [E, d]  unit-norm residuals, each orthogonal to w0

model.logits(activations)                # CARE(S): shared direction only
model.logits(activations, envs)          # CARE(C): shared direction + residual of each example's environment

Use the directions for measurement (the sign of the logit) or for intervention (add, ablate, or patch activations along w0, and along r_e when the environment is known).

The objective

care/losses.py implements the three terms of the training objective. The names follow the paper.

Term What it does
Joint loss Classifies the concept in each environment with the shared direction plus that environment's residual.
Environment signal loss Asks each residual, by itself, to carry concept signal in its own environment.
Regularizer R Optional invariance penalty on the shared direction: V-REx, IRM, or GroupDRO. R = none gives CARE-Base.

Experiments

See experiments/README.md.

Citation

@inproceedings{karlekar2026care,
  title     = {Do You {CARE} to Generalize? Extracting Robust Concept Directions in {LLMs}},
  author    = {Karlekar, Sweta and Shi, Claudia and Manas-Puli, Aahlad and Zheng, Carolina and
               Bowlan, John and Kucer, Michal and Makar, Maggie and Blei, David},
  booktitle = {Advances in Neural Information Processing Systems},
  year      = {2026}
}

License

MIT. See LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0