Uppaal commited on
Commit
4b949d2
·
verified ·
1 Parent(s): 3543324

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +120 -145
README.md CHANGED
@@ -1,199 +1,174 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
 
 
 
 
 
 
 
 
 
 
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
11
 
12
- ## Model Details
13
-
14
- ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
 
 
 
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
 
 
 
 
 
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
 
 
49
 
50
- [More Information Needed]
 
 
 
 
51
 
52
  ### Out-of-Scope Use
 
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
 
70
  ## How to Get Started with the Model
71
 
72
  Use the code below to get started with the model.
73
 
74
- [More Information Needed]
75
-
76
- ## Training Details
77
 
78
- ### Training Data
 
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
 
 
81
 
82
- [More Information Needed]
83
 
84
- ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
- #### Preprocessing [optional]
 
89
 
90
- [More Information Needed]
 
 
 
91
 
 
92
 
93
- #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
 
 
 
 
 
 
 
 
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
102
 
103
  ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
 
127
  ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
 
175
  **BibTeX:**
176
 
177
- [More Information Needed]
 
 
 
 
178
 
179
  **APA:**
180
 
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
  ---
2
  library_name: transformers
3
+ tags:
4
+ - generation
5
+ - safety
6
+ - model-editing
7
+ - editing
8
+ - activation-steering
9
+ - activation-editing
10
+ - dpo
11
+ - rlhf
12
+ - profs
13
+ - detox
14
+ - toxicity
15
+ - iclr
16
+ - iclr2025
17
+ license: mit
18
+ language:
19
+ - en
20
+ base_model:
21
+ - mistralai/Mistral-7B-v0.1
22
  ---
23
 
24
+ <p align="center">
25
+ <a href="https://arxiv.org/abs/2405.13967">
26
+ <img src="https://img.shields.io/badge/arXiv-2405.13967-B31B1B?logo=arxiv&logoColor=white" alt="arXiv">
27
+ </a>
28
+ <a href="https://uppaal.github.io/projects/profs/profs.html">
29
+ <img src="https://img.shields.io/badge/Project_Webpage-1DA1F2?logo=google-chrome&logoColor=white&color=0A4D8C" alt="Project Webpage">
30
+ </a>
31
+ <a href="https://github.com/Uppaal/detox-edit">
32
+ <img src="https://img.shields.io/badge/Code-F1C232?logo=github&logoColor=white&color=black" alt="Checkpoints">
33
+ </a>
34
+ </p>
35
 
 
36
 
37
+ # ProFS Editing for Safety
38
 
39
 
40
+ This model accompanies the paper [Model Editing as a Robust and Denoised Variant of DPO: A Case Study on Toxicity](https://arxiv.org/abs/2405.13967)
41
+ published at ICLR 2025 (previously released under the preprint title “DeTox: Toxic Subspace Projection for Model Editing”; both refer to the same work).
 
42
 
43
+ ProFS (Projection Filter for Subspaces) is a tuning-free alignment method that removes undesired behaviors—such as toxicity—by identifying and projecting out harmful subspaces in model weights.
44
 
45
+ **Key Features:**
46
 
47
+ - Training-free & plug-and-play: edits weights directly, no gradient steps or architectural changes needed.
48
+ - Data-efficient: achieves strong alignment effects using only hundreds (not thousands) of preference pairs.
49
+ - Label-robust: maintains performance even under substantial label noise, since projection directions remain stable.
50
+ - Fast & lightweight: produces an edited model that runs at the same inference speed as the base model.
51
+ - Theoretically grounded: shown to be a denoised, single-step approximation of Direct Preference Optimization (DPO)—bridging editing-based and tuning-based alignment.
 
 
52
 
53
+ <div align="center">
54
+ <img src="ProFS Method.png" width="950">
55
+ <i><b>Figure.</b> Schematic of ProFS (previously called DeTox). Toxic directions (in red) are projected out of the model’s MLP-value matrices, leaving other representational directions intact. </i>
56
+ </div>
57
 
 
58
 
 
 
 
 
 
59
 
 
60
 
61
+ ## Model Details
 
 
62
 
63
+ - **Model type:** Edited Causal Language Model (LLM)
64
+ - **Base model:** [`mistralai/Mistral-7B-v0.1`](https://huggingface.co/mistralai/Mistral-7B-v0.1)
65
+ - **Language(s) (NLP):** English
66
+ - **License:** MIT
67
+ - **Repository:** [GitHub](https://github.com/Uppaal/detox-edit)
68
+ - **Paper:** [Model Editing as a Robust and Denoised variant of DPO: A Case Study on Toxicity](https://arxiv.org/abs/2405.13967)
69
 
70
+ ## Uses
71
 
72
+ ### Direct Use
73
+ ProFS-edited GPT-2 can be used for:
74
+ - Safe text generation and alignment research
75
+ - Studying lightweight alignment via model editing rather than fine-tuning
76
+ - Interpretability studies of activation subspaces and toxicity directions
77
 
78
+ ### Downstream Use
79
+ ProFS serves as a reproducible starting point for work on:
80
+ - Safety alignment without gradient updates
81
+ - Robustness to label noise and limited data regimes
82
+ - Educational demonstrations of representation-level interventions
83
 
84
  ### Out-of-Scope Use
85
+ Not a fully aligned conversational model.
86
+ Not evaluated for fairness or demographic bias beyond toxicity.
87
 
 
 
 
 
 
 
 
 
 
 
 
88
 
 
 
 
89
 
90
  ## How to Get Started with the Model
91
 
92
  Use the code below to get started with the model.
93
 
94
+ ```
95
+ from transformers import AutoTokenizer, AutoModelForCausalLM
96
+ model_id = "Uppaal/Mistral-ProFS-toxicity"
97
 
98
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
99
+ model = AutoModelForCausalLM.from_pretrained(model_id)
100
 
101
+ prompt = "The internet has changed the way people communicate by"
102
+ out = model.generate(**tokenizer(prompt, return_tensors="pt"), max_new_tokens=20)
103
+ print(tokenizer.decode(out[0], skip_special_tokens=True))
104
+ ```
105
 
 
106
 
 
107
 
108
+ ## Training (Editing) Details
109
 
110
+ ### Data
111
+ We use the pairwise toxicity preference dataset introduced by [Lee et al. (2024)](https://arxiv.org/abs/2401.01967).
112
 
113
+ - Non-toxic sequences: sampled from WikiText-2.
114
+ - Toxic counterparts: generated using the Plug-and-Play Language Model (PPLM) method to inject toxic content.
115
+ - Data format: (toxic, non-toxic) sentence pairs.
116
+ - Sample size: 500 pairs for ProFS editing (compared to 2,000 pairs used for DPO fine-tuning).
117
 
118
+ ### Preprocessing
119
 
120
+ No preprocessing or filtering was applied beyond tokenization by the base model tokenizer.
121
 
122
+ ### Editing Hyperparameters
123
 
124
+ - Top-k singular vectors:
125
+ - GPT-2: k = 2
126
+ - Mistral, Mistral-SFT, OPT, GPT-J: k = 10
127
+ - Selected via ScreeNot and validated with cross-validation.
128
+ - Edited layers:
129
+ - GPT-2 / GPT-J: layers 11–24
130
+ - Mistral, Mistral-SFT, OPT: layers 15–L
131
+ - Projection step: edit applied once to the MLP-Value matrices only.
132
+ - Centering: mean vector of non-toxic embeddings removed before SVD to preserve syntactic knowledge.
133
 
 
134
 
 
135
 
136
  ## Evaluation
137
 
138
+ ### Metrics and Testing Data
 
 
 
 
 
 
 
 
 
 
139
 
140
+ - Perplexity (fluency): evaluated on the WikiText-2 dev split.
141
+ - Toxicity: measured on the [Real Toxicity Prompts](https://huggingface.co/datasets/allenai/real-toxicity-prompts) challenge subset. Scored using [Detoxify](https://github.com/unitaryai/detoxify). Lower Detoxify score = lower toxicity.
142
+ - Capability (for larger models): zero-shot accuracy across 7 EleutherAI LM Harness tasks: BoolQ, RTE, HellaSwag, WinoGrande, ARC-Easy, ARC-Challenge, and OpenBookQA.
 
 
 
 
 
 
143
 
144
  ### Results
145
+ | **Model** | **Method** | **Toxicity ↓** | **Perplexity ↓** | **Capability ↑** |
146
+ |:-----------|:------------|:---------------|:-----------------|:-----------------|
147
+ | **GPT-2 Medium** | Original | 48.00 (0.00) | 29.70 (0.00) | – |
148
+ | | DPO | 36.36 (0.58) | 29.86 (0.22) | – |
149
+ | | **ProFS** | **26.83 (0.89)** | 32.50 (0.28) | – |
150
+ | **Mistral 7B** | Original | 42.45 (0.00) | 7.49 (0.00) | 64.23 |
151
+ | | DPO | 36.42 (0.62) | 7.52 (0.26) | 65.32 |
152
+ | | **ProFS** | **30.40 (0.71)** | 7.99 (0.21) | 63.59 |
153
+ | **Mistral-SFT 7B** | Original | 33.45 (0.00) | 8.22 (0.00) | 63.59 |
154
+ | | DPO | 23.96 (0.50) | 8.38 (0.34) | 63.66 |
155
+ | | **ProFS** | **26.03 (1.25)** | 8.83 (0.57) | 63.23 |
156
+ | **OPT 6.7B** | Original | 46.47 (0.00) | 14.67 (0.00) | 51.57 |
157
+ | | DPO | 45.31 (0.74) | 14.37 (0.61) | 51.55 |
158
+ | | **ProFS** | **43.49 (1.38)** | 13.83 (0.46) | 51.80 |
159
+ | **GPT-J 6B** | Original | 45.31 (0.00) | 13.24 (0.00) | 51.92 |
160
+ | | DPO | 43.67 (1.11) | 13.96 (0.53) | 52.46 |
161
+ | | **ProFS** | **37.36 (2.28)** | 14.53 (0.30) | 52.48 |
162
+ ## Citation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
  **BibTeX:**
165
 
166
+ @inproceedings{uppaalmodel,
167
+ title={Model Editing as a Robust and Denoised variant of DPO: A Case Study on Toxicity},
168
+ author={Uppaal, Rheeya and Dey, Apratim and He, Yiting and Zhong, Yiqiao and Hu, Junjie},
169
+ booktitle={The Thirteenth International Conference on Learning Representations}
170
+ }
171
 
172
  **APA:**
173
 
174
+ Uppaal, R., Dey, A., He, Y., Zhong, Y., & Hu, J. Model Editing as a Robust and Denoised variant of DPO: A Case Study on Toxicity. In The Thirteenth International Conference on Learning Representations.