{"id":19428916,"url":"https://github.com/eleutherai/ccs","last_synced_at":"2025-04-24T18:31:38.878Z","repository":{"id":195667488,"uuid":"693403351","full_name":"EleutherAI/ccs","owner":"EleutherAI","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-09T19:09:34.000Z","size":27327,"stargazers_count":3,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-02-09T20:26:19.524Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EleutherAI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-09-19T00:59:48.000Z","updated_at":"2024-02-09T20:26:20.055Z","dependencies_parsed_at":"2024-01-24T20:41:19.106Z","dependency_job_id":null,"html_url":"https://github.com/EleutherAI/ccs","commit_stats":null,"previous_names":["eleutherai/ccs"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EleutherAI%2Fccs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EleutherAI%2Fccs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EleutherAI%2Fccs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EleutherAI%2Fccs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EleutherAI","download_url":"https://codeload.github.com/EleutherAI/ccs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223961111,"owners_count":17232251,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T14:17:11.385Z","updated_at":"2024-11-10T14:17:11.861Z","avatar_url":"https://github.com/EleutherAI.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Introduction\n\n**WIP: This codebase is under active development**\n\nBecause language models are trained to predict the next token in naturally occurring text, they often reproduce common\nhuman errors and misconceptions, even when they \"know better\" in some sense. More worryingly, when models are trained to\ngenerate text that's rated highly by humans, they may learn to output false statements that human evaluators can't\ndetect. We aim to circumvent this issue by directly [**eliciting latent knowledge\n**](https://docs.google.com/document/d/1WwsnJQstPq91_Yh-Ch2XRL8H_EpsnjrC1dwZXR37PC8/edit) (ELK) inside the activations\nof a language model.\n\nSpecifically, we're building on the **Contrastive Representation Clustering** (CRC) method described in the\npaper [Discovering Latent Knowledge in Language Models Without Supervision](https://arxiv.org/abs/2212.03827) by Burns\net al. (2022). In CRC, we search for features in the hidden states of a language model which satisfy certain logical\nconsistency requirements. It turns out that these features are often useful for question-answering and text\nclassification tasks, even though the features are trained without labels.\n\n### Quick **Start**\n\nOur code is based on [PyTorch](http://pytorch.org)\nand [Huggingface Transformers](https://huggingface.co/docs/transformers/index). We test the code on Python 3.10 and\n3.11.\n\nFirst install the package with `pip install -e .` in the root directory. Use `pip install -e .[dev]` if you'd like to contribute to the project (see **Development** section below). This should install all the necessary dependencies.\n\nTo fit reporters for the HuggingFace model `model` and dataset `dataset`, just run:\n\n```bash\nccs elicit microsoft/deberta-v2-xxlarge-mnli imdb\n```\n\nThis will automatically download the model and dataset, run the model and extract the relevant representations if they\naren't cached on disk, fit reporters on them, and save the reporter checkpoints to the `ccs-reporters` folder in your\nhome directory. It will also evaluate the reporter classification performance on a held out test set and save it to a\nCSV file in the same folder.\n\nThe following will generate a CCS (Contrast Consistent Search) reporter instead of the CRC-based reporter, which is the\ndefault.\n\n```bash\nccs elicit microsoft/deberta-v2-xxlarge-mnli imdb --net ccs\n```\n\nThe following command will evaluate the probe from the run naughty-northcutt on the hidden states extracted from the\nmodel deberta-v2-xxlarge-mnli for the imdb dataset. It will result in an `eval.csv` and `cfg.yaml` file, which are\nstored under a subfolder in `ccs-reporters/naughty-northcutt/transfer_eval`.\n\n```bash\nccs eval naughty-northcutt microsoft/deberta-v2-xxlarge-mnli imdb\n```\n\nThe following runs `elicit` on the Cartesian product of the listed models and datasets, storing it in a special folder\nCCS_DIR/sweeps/\u003cmemorable_name\u003e. Moreover, `--add_pooled` adds an additional dataset that pools all of the datasets\ntogether. You can also add a `--visualize` flag to visualize the results of the sweep.\n\n```bash\nccs sweep --models gpt2-{medium,large,xl} --datasets imdb amazon_polarity --add_pooled\n```\n\nIf you just do `ccs plot`, it will plot the results from the most recent sweep.\nIf you want to plot a specific sweep, you can do so with:\n\n```bash\nccs plot {sweep_name}\n```\n\n## Caching\n\nThe hidden states resulting from `ccs elicit` are cached as a HuggingFace dataset to avoid having to recompute them\nevery time we want to train a probe. The cache is stored in the same place as all other HuggingFace datasets, which is\nusually `~/.cache/huggingface/datasets`.\n\n## Development\n\nUse `pip install pre-commit \u0026\u0026 pre-commit install` in the root folder before your first commit.\n\n### Devcontainer\n\n[\n![Open in Remote - Containers](\nhttps://img.shields.io/static/v1?label=Remote%20-%20Containers\u0026message=Open\u0026color=blue\u0026logo=visualstudiocode\n)\n](\nhttps://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/EleutherAI/ccs\n)\n\n### Run tests\n\n```bash\npytest\n```\n\n### Run type checking\n\nWe use [pyright](https://github.com/microsoft/pyright), which is built into the VSCode editor. If you'd like to run it\nas a standalone tool, it requires a [nodejs installation.](https://nodejs.org/en/download/)\n\n```bash\npyright\n```\n\n### Run the linter\n\nWe use [ruff](https://beta.ruff.rs/docs/). It is installed as a pre-commit hook, so you don't have to run it manually.\nIf you want to run it manually, you can do so with:\n\n```bash\nruff . --fix\n```\n\n### Contributing to this repository\n\nIf you work on a new feature / fix or some other code task, make sure to create an issue and assign it to yourself (\nMaybe, even share it in the elk channel of Eleuther's Discord with a small note). In this way, others know you are\nworking on the issue and people won't do the same thing twice 👍 Also others can contact you easily.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feleutherai%2Fccs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feleutherai%2Fccs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feleutherai%2Fccs/lists"}