aakothari commited on
Commit
cc2be94
·
verified ·
1 Parent(s): 81767a9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +114 -63
README.md CHANGED
@@ -22,27 +22,45 @@ library_name: transformers
22
  pipeline_tag: fill-mask
23
  ---
24
 
25
- # BRAIDBERTa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- A RoBERTa-style masked language model pretrained on molecules encoded in **BRAID**, a
28
- machine-native molecular line notation, together with a **SMILES-pretrained control model
29
- (SMILESBERTa)** that is identical in every respect except the input notation.
30
 
31
- The point of this repository is the *controlled comparison*, not the model. If you are
32
- looking for a strong chemical foundation model, use ChemBERTa-2 or MolFormer. If you want
33
- to know whether the choice of line notation actually changes downstream performance when
34
- everything else is held fixed, that is what this is for.
35
 
36
- **Headline result: it does not.** BRAID and SMILES are statistically indistinguishable on
37
- BBBP under matched pretraining, matched architecture, and matched finetuning protocol.
 
 
 
 
 
38
 
39
  ---
40
 
41
  ## The BRAID notation
42
 
43
  BRAID (**B**ranch-counted, **R**elative-ring, **A**ttachment-native, **I**nvalid-free,
44
- **D**ense) is a line notation built from four mechanisms, all of which are recombined prior
45
- art:
46
 
47
  | Mechanism | Syntax | Borrowed from |
48
  |---|---|---|
@@ -53,11 +71,10 @@ art:
53
 
54
  Only **atom tokens** advance the global index; `>k`, `^d`, bond symbols and `.` do not.
55
 
56
- ```bash
57
- pip install rdkit
58
- python -m braids encode "CC(=O)Oc1ccccc1C(=O)O" # -> CC>1=OOC=CC=CC=C^5C>1=OO
59
- python -m braids encode "CC(=O)Oc1ccccc1C(=O)O" --aromatic # -> CC>1=OOcccccc^5C>1=OO
60
- python -m braids decode "CC>1=OOcccccc^5C>1=OO" # -> CC(=O)Oc1ccccc1C(=O)O
61
  ```
62
 
63
  ### Novelty: none claimed
@@ -67,6 +84,7 @@ BRAID is **not novel at the mechanism level.** Relative ring closure is DeepSMIL
67
  2020) with the brackets stripped. Guaranteed-valid decoding via a valence state machine is
68
  the entire point of SELFIES. The fragment separator is SAFE (Noutahi et al., 2023).
69
 
 
70
 
71
  ### The property BRAID does have
72
 
@@ -89,59 +107,113 @@ A Markov model is far weaker than a real CLM, so treat validity% as the meaningf
89
 
90
  ---
91
 
92
- ## Models
93
 
94
- | Model | Pretraining corpus | Notation | Architecture |
95
- |---|---|---|---|
96
- | `BRAIDBERTa-v9` | ZINC 100k | BRAID | RoBERTa (MLM) |
97
- | `SMILESBERTa-v9` | ZINC 100k | SMILES | RoBERTa (MLM), identical config |
98
 
99
- The two models differ **only** in the notation used to encode the pretraining corpus and in
100
- the tokenizer trained on it. Same molecules, same architecture, same MLM objective, same
101
- pretraining budget. This is what makes the downstream comparison interpretable.
102
 
103
  ---
104
 
105
- ## Downstream ablation: BBBP
106
 
107
  Finetuned for binary classification (blood–brain barrier penetration) with a fresh 2-logit
108
- head and cross-entropy loss. Hyperparameters (learning rate, epochs) were selected per model
109
- by Optuna on the validation split, then the best configuration was retrained across 5 seeds.
110
- Reported metric is test ROC-AUC.
111
 
112
- | Model | Dataset | BBBP ROC-AUC | Seed 0 | Seed 1 | Seed 2 | Seed 3 | Seed 4 |
113
  |---|---|---|---|---|---|---|---|
114
- | BRAIDBERTa-v9 | ZINC 100k | 0.725 ± 0.017 | 0.727 | 0.710 | 0.751 | 0.710 | 0.727 |
115
- | SMILESBERTa-v9 | ZINC 100k | 0.720 ± 0.010 | 0.719 | 0.738 | 0.715 | 0.714 | 0.712 |
116
 
117
  (± is the sample standard deviation across seeds.)
118
 
 
 
 
 
 
 
 
 
119
  ### Interpretation
120
 
121
  **The two are statistically indistinguishable.** Welch's *t*-test on the five seeds per
122
- model gives *t* ≈ 0.61, *p* ≈ 0.56. The 0.005 gap in favour of BRAID is well within seed
123
- noise, and the per-seed ranges overlap almost completely (BRAID 0.710–0.751, SMILES
124
  0.712–0.738).
125
 
126
  The correct reading is **not** "BRAID beats SMILES." It is:
127
 
128
- > Under matched pretraining and finetuning, BRAID's guaranteed-validity property is obtained
129
  > **at no measurable cost to downstream predictive performance** on BBBP.
130
 
131
  That is the useful claim. A notation that buys 100% generative validity while leaving
132
  property prediction unchanged is worth having; a notation that claims a 0.005 AUC win on
133
- n=5 is not.
 
 
 
 
 
 
 
 
 
 
134
 
135
- Note also that the seed-to-seed spread (±0.017) is larger than the between-model difference.
136
- Any comparison at this scale that reports a single seed is measuring noise.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  ---
139
 
140
  ## Limitations
141
 
142
  1. **Not actually more compact.** The "D" in BRAID is aspirational. BRAID is never the
143
- shortest of the four notations — `>k` and `^d` are two characters where SMILES uses one.
144
- Aromatic mode reaches parity with SMILES, not dominance.
145
 
146
  | molecule | SMILES | DeepSMILES | SELFIES(tok) | BRAID(kekulé) | BRAID(aromatic) |
147
  |---|--:|--:|--:|--:|--:|
@@ -171,7 +243,7 @@ Any comparison at this scale that reports a single seed is measuring noise.
171
  7. **Depends on RDKit** for parsing and sanitization. This is a reference implementation,
172
  not a self-contained spec.
173
 
174
- ### Limitations of the ablation specifically
175
 
176
  - **One dataset, one split.** BBBP only. No claim is made about BACE, HIV, Tox21, SIDER, or
177
  ClinTox. Results on a single scaffold split of a ~2k-molecule dataset are fragile.
@@ -185,31 +257,10 @@ Any comparison at this scale that reports a single seed is measuring noise.
185
 
186
  ---
187
 
188
- ## Usage
189
-
190
- ```python
191
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
192
-
193
- tok = AutoTokenizer.from_pretrained("<your-org>/BRAIDBERTa-v9")
194
- model = AutoModelForSequenceClassification.from_pretrained(
195
- "<your-org>/BRAIDBERTa-v9", num_labels=2
196
- )
197
-
198
- from braids import smiles_to_braid
199
- braid = smiles_to_braid("CC(=O)Oc1ccccc1C(=O)O")
200
- inputs = tok(braid, return_tensors="pt", truncation=True, max_length=128)
201
- logits = model(**inputs).logits
202
- ```
203
-
204
- **Inputs must be BRAID strings, not SMILES.** The tokenizer is a BPE vocabulary trained on
205
- BRAID; feeding it raw SMILES will not error — BPE always backs off to characters — it will
206
- simply produce meaningless tokenizations and a plausible-looking, wrong prediction. Encode
207
- with `braids.smiles_to_braid` first.
208
-
209
  ## Citation
210
 
211
  BRAID is a recombination of published mechanisms and should not be cited as a novel
212
- notation. Please cite the underlying work instead:
213
 
214
  - O'Boyle, N. & Dalke, A. *DeepSMILES: An Adaptation of SMILES for Use in Machine-Learning
215
  of Chemical Structures.* ChemRxiv, 2018.
 
22
  pipeline_tag: fill-mask
23
  ---
24
 
25
+ ---
26
+ license: mit
27
+ language:
28
+ - en
29
+ tags:
30
+ - chemistry
31
+ - molecular-property-prediction
32
+ - cheminformatics
33
+ - roberta
34
+ - smiles
35
+ - deepsmiles
36
+ - selfies
37
+ - molecular-representation
38
+ datasets:
39
+ - zinc
40
+ library_name: transformers
41
+ pipeline_tag: fill-mask
42
+ ---
43
 
44
+ # BRAIDBERTa-v9
 
 
45
 
46
+ A RoBERTa-style masked language model pretrained on ZINC 100k, with molecules encoded in
47
+ **BRAID** a machine-native molecular line notation in which every string decodes to a
48
+ valid molecule.
 
49
 
50
+ BRAIDBERTa exists to answer one question: does a guaranteed-validity notation cost you
51
+ anything on downstream property prediction? Against a matched-budget SMILES control, the
52
+ answer is **no** — the two are statistically indistinguishable on BBBP.
53
+
54
+ This is a research model. If you want a strong chemical foundation model, use ChemBERTa-2 or
55
+ MolFormer. If you want a model whose input notation cannot represent an invalid molecule,
56
+ this is that.
57
 
58
  ---
59
 
60
  ## The BRAID notation
61
 
62
  BRAID (**B**ranch-counted, **R**elative-ring, **A**ttachment-native, **I**nvalid-free,
63
+ **D**ense) is built from four mechanisms, all of which are recombined prior art:
 
64
 
65
  | Mechanism | Syntax | Borrowed from |
66
  |---|---|---|
 
71
 
72
  Only **atom tokens** advance the global index; `>k`, `^d`, bond symbols and `.` do not.
73
 
74
+ ```
75
+ aspirin SMILES CC(=O)Oc1ccccc1C(=O)O
76
+ BRAID CC>1=OOcccccc^5C>1=OO (aromatic mode)
77
+ BRAID CC>1=OOC=CC=CC=C^5C>1=OO (kekulé mode, default)
 
78
  ```
79
 
80
  ### Novelty: none claimed
 
84
  2020) with the brackets stripped. Guaranteed-valid decoding via a valence state machine is
85
  the entire point of SELFIES. The fragment separator is SAFE (Noutahi et al., 2023).
86
 
87
+ Please treat BRAID as a recombination, and do not cite it as a new notation.
88
 
89
  ### The property BRAID does have
90
 
 
107
 
108
  ---
109
 
110
+ ## Model details
111
 
112
+ - **Architecture:** RoBERTa (masked language modelling)
113
+ - **Pretraining corpus:** ZINC 100k, encoded in BRAID
114
+ - **Tokenizer:** BPE trained on the BRAID corpus
115
+ - **Objective:** MLM
116
 
117
+ <!-- TODO: fill in layers / heads / hidden size / vocab size / pretraining steps -->
 
 
118
 
119
  ---
120
 
121
+ ## Downstream evaluation: BBBP
122
 
123
  Finetuned for binary classification (blood–brain barrier penetration) with a fresh 2-logit
124
+ head and cross-entropy loss. Hyperparameters (learning rate, epochs) were selected by Optuna
125
+ on the validation split, then the best configuration was retrained across 5 seeds. Metric is
126
+ test ROC-AUC.
127
 
128
+ | Model | Notation | BBBP ROC-AUC | Seed 0 | Seed 1 | Seed 2 | Seed 3 | Seed 4 |
129
  |---|---|---|---|---|---|---|---|
130
+ | **BRAIDBERTa-v9** | BRAID | **0.725 ± 0.017** | 0.727 | 0.710 | 0.751 | 0.710 | 0.727 |
131
+ | *SMILES control* | SMILES | *0.720 ± 0.010* | 0.719 | 0.738 | 0.715 | 0.714 | 0.712 |
132
 
133
  (± is the sample standard deviation across seeds.)
134
 
135
+ ### The SMILES control
136
+
137
+ The control is an internal baseline, **not a released model.** It is identical to
138
+ BRAIDBERTa in every respect — same ZINC 100k molecules, same RoBERTa architecture and
139
+ config, same MLM objective, same pretraining budget, same finetuning protocol — differing
140
+ only in the notation used to encode the corpus and the tokenizer trained on it. It is
141
+ reported here solely to make the BRAID number interpretable.
142
+
143
  ### Interpretation
144
 
145
  **The two are statistically indistinguishable.** Welch's *t*-test on the five seeds per
146
+ model gives *t* ≈ 0.61, *p* ≈ 0.56. The 0.005 gap in favour of BRAID sits well inside seed
147
+ noise, and the per-seed ranges overlap almost completely (BRAID 0.710–0.751, control
148
  0.712–0.738).
149
 
150
  The correct reading is **not** "BRAID beats SMILES." It is:
151
 
152
+ > Under matched pretraining and finetuning, BRAID's guaranteed-validity property comes
153
  > **at no measurable cost to downstream predictive performance** on BBBP.
154
 
155
  That is the useful claim. A notation that buys 100% generative validity while leaving
156
  property prediction unchanged is worth having; a notation that claims a 0.005 AUC win on
157
+ n = 5 is not.
158
+
159
+ Note that seed-to-seed spread (±0.017) exceeds the between-model difference. Any comparison
160
+ at this scale reporting a single seed is measuring noise.
161
+
162
+ ---
163
+
164
+ ## Usage
165
+
166
+ The model consumes **BRAID strings, not SMILES.** You must encode first. The codec is
167
+ vendored into this repository so the snippet below runs standalone:
168
 
169
+ ```python
170
+ import importlib.util
171
+ from huggingface_hub import hf_hub_download
172
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
173
+
174
+ # load the BRAID codec shipped with this repo (requires: pip install rdkit)
175
+ path = hf_hub_download("aakothari/BRAIDBERTa-v9", "braids_codec.py")
176
+ spec = importlib.util.spec_from_file_location("braids_codec", path)
177
+ braids = importlib.util.module_from_spec(spec)
178
+ spec.loader.exec_module(braids)
179
+
180
+ tok = AutoTokenizer.from_pretrained("aakothari/BRAIDBERTa-v9")
181
+ model = AutoModelForSequenceClassification.from_pretrained(
182
+ "aakothari/BRAIDBERTa-v9", num_labels=2
183
+ )
184
+
185
+ braid = braids.smiles_to_braid("CC(=O)Oc1ccccc1C(=O)O") # encode SMILES -> BRAID
186
+ inputs = tok(braid, return_tensors="pt", truncation=True, max_length=128)
187
+ logits = model(**inputs).logits
188
+ ```
189
+
190
+ > **Do not feed raw SMILES to this tokenizer.** It will not error — BPE always backs off to
191
+ > characters — it will simply produce a meaningless tokenization and a plausible-looking,
192
+ > wrong prediction. Always encode with `smiles_to_braid` first.
193
+
194
+ The full reference implementation (encoder, decoder, valence state machine, stereo handling,
195
+ tokenizer/`Vocab` builder, and the test suites) lives at:
196
+
197
+ <!-- TODO: link the GitHub repo, or delete this line if the vendored codec is the only distribution -->
198
+
199
+ ### Verified codec behaviour
200
+
201
+ - **Round-trip:** 42/42 molecules recover their constitution in both Kekulé and aromatic
202
+ modes — including fused/bridged systems (naphthalene, indole, adamantane, caffeine,
203
+ purine, quinoline, nicotine) and ions (nitromethane, acetate, ammonium, Na⁺·Cl⁻).
204
+ - **Stereo:** 26/26 chiral / E-Z molecules round-trip in both modes — L-alanine,
205
+ (S)-ibuprofen, meso vs. L-tartaric acid, menthol, L-DOPA, adrenaline, carvone,
206
+ fumaric/maleic acid, conjugated dienes, mixed chiral + E/Z.
207
+ - **Validity:** 10,000/10,000 random and mutated strings decode to a sanitizable molecule
208
+ with 0 crashes.
209
 
210
  ---
211
 
212
  ## Limitations
213
 
214
  1. **Not actually more compact.** The "D" in BRAID is aspirational. BRAID is never the
215
+ shortest notation — `>k` and `^d` are two characters where SMILES uses one. Aromatic mode
216
+ reaches parity with SMILES, not dominance.
217
 
218
  | molecule | SMILES | DeepSMILES | SELFIES(tok) | BRAID(kekulé) | BRAID(aromatic) |
219
  |---|--:|--:|--:|--:|--:|
 
243
  7. **Depends on RDKit** for parsing and sanitization. This is a reference implementation,
244
  not a self-contained spec.
245
 
246
+ ### Limitations of the evaluation specifically
247
 
248
  - **One dataset, one split.** BBBP only. No claim is made about BACE, HIV, Tox21, SIDER, or
249
  ClinTox. Results on a single scaffold split of a ~2k-molecule dataset are fragile.
 
257
 
258
  ---
259
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  ## Citation
261
 
262
  BRAID is a recombination of published mechanisms and should not be cited as a novel
263
+ notation. Please cite the underlying work:
264
 
265
  - O'Boyle, N. & Dalke, A. *DeepSMILES: An Adaptation of SMILES for Use in Machine-Learning
266
  of Chemical Structures.* ChemRxiv, 2018.