Base Pretrained Models
Pretrained Model¶
PretrainedMolTransformer
¶
Bases: MoleculeTransformer
Transformer based on pretrained featurizer
Note
- When implementing a subclass of this class, you need to define the
_embed
and optionally the_convert
methods. - If your model is an instance of PretrainedModel that handles loading of the model from a store or through a complex mechanism then you can decide whether you want to preload the true underlying model. You will be in charge of handling the logic of when you need to call preload, and when you don't. Note however that by default preloading is only attempted when the featurizer is still an instance of PretrainedModel.
Attributes featurizer (object): featurizer object dtype (type, optional): Data type. Use call instead precompute_cache: (bool, optional): Whether to precompute the features into a local cache. Defaults to False. Note that due to molecular hashing, some pretrained featurizers might be better off just not using any cache as they can be faster. Furthermore, the cache is not saved when pickling the object. If you want to save the cache, you need to save the object separately. _require_mols (bool): Whether the embedding takes mols or smiles as input preload: whether to preload the pretrained model from the store (if available) during initialization.
Source code in molfeat/trans/pretrained/base.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
__getstate__()
¶
Getting state to allow pickling
Source code in molfeat/trans/pretrained/base.py
93 94 95 96 97 98 99 |
|
__setstate__(d)
¶
Setting state during reloading pickling
Source code in molfeat/trans/pretrained/base.py
101 102 103 104 |
|
preprocess(inputs, labels=None)
¶
Run preprocessing on the input data Args: inputs: list of input molecules labels: list of labels
Source code in molfeat/trans/pretrained/base.py
124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
set_cache(cache)
¶
Set the cache for the transformer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache |
DataCache
|
cache object |
required |
Source code in molfeat/trans/pretrained/base.py
62 63 64 65 66 67 68 |
|
transform(smiles, **kwargs)
¶
Perform featurization of the input molecules
The featurization process is as follow:
1. convert the input molecules into the right format, expected by the pre-trained model using _convert
2. compute embedding of the molecule using _embed
3. perform any model-specific postprocessing and cache update
The dtype returned is the native datatype of the transformer.
Use __call__
to get the dtype in the dtype
attribute format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
a list containing smiles or mol objects |
required |
Returns:
Name | Type | Description |
---|---|---|
out |
featurized molecules |
Source code in molfeat/trans/pretrained/base.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|