Spaces:
Running
Running
Enzo Reis de Oliveira
commited on
Commit
·
6f6fe4e
1
Parent(s):
64428bf
Fixing README.md
Browse files
README.md
CHANGED
@@ -1,188 +1,15 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
3 |
-
|
4 |
-
-
|
5 |
-
pipeline_tag: feature-extraction
|
6 |
-
tags:
|
7 |
-
- chemistry
|
8 |
-
- foundation models
|
9 |
-
- AI4Science
|
10 |
-
- materials
|
11 |
-
- molecules
|
12 |
-
- safetensors
|
13 |
-
- pytorch
|
14 |
-
- transformer
|
15 |
-
- diffusers
|
16 |
-
library_name: transformers
|
17 |
---
|
18 |
-
# Introduction to IBM's Foundation Models for Materials
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
GitHub: [GitHub Link](https://github.com/IBM/materials/tree/main)
|
23 |
-
|
24 |
-
Paper: [arXiv:2407.20267](https://arxiv.org/abs/2407.20267)
|
25 |
-
|
26 |
-
# SMILES-based Transformer Encoder-Decoder (SMI-TED)
|
27 |
-
|
28 |
-

|
29 |
-
|
30 |
-
This repository provides PyTorch source code associated with our publication, "A Large Encoder-Decoder Family of Foundation Models for Chemical Language".
|
31 |
-
|
32 |
-
Paper: [Arxiv Link](https://github.com/IBM/materials/blob/main/smi-ted/paper/smi-ted_preprint.pdf)
|
33 |
-
|
34 |
-
We provide the model weights in two formats:
|
35 |
-
|
36 |
-
- PyTorch (`.pt`): [smi-ted-Light_40.pt](smi-ted-Light_40.pt)
|
37 |
-
- safetensors (`.safetensors`): [model_weights.safetensors](model_weights.safetensors)
|
38 |
-
|
39 |
-
For more information contact: [email protected] or [email protected].
|
40 |
-
|
41 |
-
## Introduction
|
42 |
-
|
43 |
-
We present a large encoder-decoder chemical foundation model, SMILES-based Transformer Encoder-Decoder (SMI-TED), pre-trained on a curated dataset of 91 million SMILES samples sourced from PubChem, equivalent to 4 billion molecular tokens. SMI-TED supports various complex tasks, including quantum property prediction, with two main variants (289M and 8X289M). Our experiments across multiple benchmark datasets demonstrate state-of-the-art performance for various tasks. For more information contact: [email protected] or [email protected].
|
44 |
-
|
45 |
-
## Table of Contents
|
46 |
-
|
47 |
-
1. [Getting Started](#getting-started)
|
48 |
-
1. [Pretrained Models and Training Logs](#pretrained-models-and-training-logs)
|
49 |
-
2. [Replicating Conda Environment](#replicating-conda-environment)
|
50 |
-
2. [Pretraining](#pretraining)
|
51 |
-
3. [Finetuning](#finetuning)
|
52 |
-
4. [Feature Extraction](#feature-extraction)
|
53 |
-
5. [Citations](#citations)
|
54 |
-
|
55 |
-
## Getting Started
|
56 |
-
|
57 |
-
**This code and environment have been tested on Nvidia V100s and Nvidia A100s**
|
58 |
-
|
59 |
-
### Pretrained Models and Training Logs
|
60 |
-
|
61 |
-
We provide checkpoints of the SMI-TED model pre-trained on a dataset of ~91M molecules curated from PubChem. The pre-trained model shows competitive performance on classification and regression benchmarks from MoleculeNet.
|
62 |
-
|
63 |
-
Add the SMI-TED `pre-trained weights.pt` to the `inference/` or `finetune/` directory according to your needs. The directory structure should look like the following:
|
64 |
-
|
65 |
-
```
|
66 |
-
inference/
|
67 |
-
├── smi_ted_light
|
68 |
-
│ ├── smi_ted_light.pt
|
69 |
-
│ ├── bert_vocab_curated.txt
|
70 |
-
│ └── load.py
|
71 |
-
```
|
72 |
-
and/or:
|
73 |
-
|
74 |
-
```
|
75 |
-
finetune/
|
76 |
-
├── smi_ted_light
|
77 |
-
│ ├── smi_ted_light.pt
|
78 |
-
│ ├── bert_vocab_curated.txt
|
79 |
-
│ └── load.py
|
80 |
-
```
|
81 |
-
|
82 |
-
### Replicating Conda Environment
|
83 |
-
|
84 |
-
Follow these steps to replicate our Conda environment and install the necessary libraries:
|
85 |
-
|
86 |
-
#### Create and Activate Conda Environment
|
87 |
-
|
88 |
-
```
|
89 |
-
conda create --name smi-ted-env python=3.10
|
90 |
-
conda activate smi-ted-env
|
91 |
-
```
|
92 |
-
|
93 |
-
#### Install Packages with Conda
|
94 |
-
|
95 |
-
```
|
96 |
-
conda install pytorch=2.1.0 pytorch-cuda=11.8 -c pytorch -c nvidia
|
97 |
-
```
|
98 |
-
|
99 |
-
#### Install Packages with Pip
|
100 |
-
|
101 |
-
```
|
102 |
-
pip install -r requirements.txt
|
103 |
-
pip install pytorch-fast-transformers
|
104 |
-
```
|
105 |
-
|
106 |
-
## Pretraining
|
107 |
-
|
108 |
-
For pretraining, we use two strategies: the masked language model method to train the encoder part and an encoder-decoder strategy to refine SMILES reconstruction and improve the generated latent space.
|
109 |
-
|
110 |
-
SMI-TED is pre-trained on canonicalized and curated 91M SMILES from PubChem with the following constraints:
|
111 |
-
|
112 |
-
- Compounds are filtered to a maximum length of 202 tokens during preprocessing.
|
113 |
-
- A 95/5/0 split is used for encoder training, with 5% of the data for decoder pretraining.
|
114 |
-
- A 100/0/0 split is also used to train the encoder and decoder directly, enhancing model performance.
|
115 |
-
|
116 |
-
The pretraining code provides examples of data processing and model training on a smaller dataset, requiring 8 A100 GPUs.
|
117 |
-
|
118 |
-
To pre-train the two variants of the SMI-TED model, run:
|
119 |
-
|
120 |
-
```
|
121 |
-
bash training/run_model_light_training.sh
|
122 |
-
```
|
123 |
-
or
|
124 |
-
```
|
125 |
-
bash training/run_model_large_training.sh
|
126 |
-
```
|
127 |
-
|
128 |
-
Use `train_model_D.py` to train only the decoder or `train_model_ED.py` to train both the encoder and decoder.
|
129 |
-
|
130 |
-
## Finetuning
|
131 |
-
|
132 |
-
The finetuning datasets and environment can be found in the [finetune](https://github.com/IBM/materials/tree/main/smi-ted/finetune) directory. After setting up the environment, you can run a finetuning task with:
|
133 |
-
|
134 |
-
```
|
135 |
-
bash finetune/smi_ted_light/esol/run_finetune_esol.sh
|
136 |
-
```
|
137 |
-
|
138 |
-
Finetuning training/checkpointing resources will be available in directories named `checkpoint_<measure_name>`.
|
139 |
-
|
140 |
-
## Feature Extraction
|
141 |
-
|
142 |
-
The example notebook [smi_ted_encoder_decoder_example.ipynb](https://github.com/IBM/materials/blob/main/smi-ted/notebooks/smi_ted_encoder_decoder_example.ipynb) contains code to load checkpoint files and use the pre-trained model for encoder and decoder tasks. It also includes examples of classification and regression tasks.
|
143 |
-
|
144 |
-
To load smi-ted, you can simply use:
|
145 |
-
|
146 |
-
```python
|
147 |
-
model = load_smi_ted(
|
148 |
-
folder='../inference/smi_ted_light',
|
149 |
-
ckpt_filename='smi_ted_light.pt'
|
150 |
-
)
|
151 |
-
```
|
152 |
-
or
|
153 |
-
|
154 |
-
```python
|
155 |
-
with open('model_weights.bin', 'rb') as f:
|
156 |
-
state_dict = torch.load(f)
|
157 |
-
model.load_state_dict(state_dict)
|
158 |
-
)
|
159 |
-
```
|
160 |
-
|
161 |
-
To encode SMILES into embeddings, you can use:
|
162 |
-
|
163 |
-
```python
|
164 |
-
with torch.no_grad():
|
165 |
-
encoded_embeddings = model.encode(df['SMILES'], return_torch=True)
|
166 |
-
```
|
167 |
-
For decoder, you can use the function, so you can return from embeddings to SMILES strings:
|
168 |
-
|
169 |
-
```python
|
170 |
-
with torch.no_grad():
|
171 |
-
decoded_smiles = model.decode(encoded_embeddings)
|
172 |
-
```
|
173 |
-
|
174 |
-
|
175 |
-
## Citations
|
176 |
-
|
177 |
-
```
|
178 |
-
@misc{soares2024largeencoderdecoderfamilyfoundation,
|
179 |
-
title={A Large Encoder-Decoder Family of Foundation Models For Chemical Language},
|
180 |
-
author={Eduardo Soares and Victor Shirasuna and Emilio Vital Brazil and Renato Cerqueira and Dmitry Zubarev and Kristin Schmidt},
|
181 |
-
year={2024},
|
182 |
-
eprint={2407.20267},
|
183 |
-
archivePrefix={arXiv},
|
184 |
-
primaryClass={cs.LG},
|
185 |
-
url={https://arxiv.org/abs/2407.20267},
|
186 |
-
}
|
187 |
-
|
188 |
-
```
|
|
|
1 |
---
|
2 |
+
title: SMI-TED-demo1
|
3 |
+
emoji: 🐢
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.4.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
license: apache-2.0
|
11 |
+
models:
|
12 |
+
- ibm/materials.smi-ted
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
---
|
|
|
14 |
|
15 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|