LIME paper: Recurrent Neural Network for Solubility Prediciton
Import packages and set up RNN
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import tensorflow as tf
import selfies as sf
import exmol
from dataclasses import dataclass
from rdkit.Chem.Draw import rdDepictor, MolsToGridImage
from rdkit.Chem import MolFromSmiles
import random
rdDepictor.SetPreferCoordGen(True)
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import urllib.request
urllib.request.urlretrieve(
"https://github.com/google/fonts/raw/main/ofl/ibmplexmono/IBMPlexMono-Regular.ttf",
"IBMPlexMono-Regular.ttf",
)
fe = font_manager.FontEntry(fname="IBMPlexMono-Regular.ttf", name="plexmono")
font_manager.fontManager.ttflist.append(fe)
plt.rcParams.update(
{
"axes.facecolor": "#f5f4e9",
"grid.color": "#AAAAAA",
"axes.edgecolor": "#333333",
"figure.facecolor": "#FFFFFF",
"axes.grid": False,
"axes.prop_cycle": plt.cycler("color", plt.cm.Dark2.colors),
"font.family": fe.name,
"figure.figsize": (3.5, 3.5 / 1.2),
"ytick.left": True,
"xtick.bottom": True,
}
)
mpl.rcParams["font.size"] = 12
soldata = pd.read_csv(
"https://github.com/whitead/dmol-book/raw/main/data/curated-solubility-dataset.csv"
)
features_start_at = list(soldata.columns).index("MolWt")
np.random.seed(0)
random.seed(0)
2024-11-22 07:13:32.428658: I external/local_xla/xla/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.
2024-11-22 07:13:32.432002: I external/local_xla/xla/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.
2024-11-22 07:13:32.440875: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
E0000 00:00:1732259612.455619 23296 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
E0000 00:00:1732259612.459896 23296 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-11-22 07:13:32.476191: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
# scramble them
soldata = soldata.sample(frac=0.01, random_state=0).reset_index(drop=True)
soldata.head()
ID | Name | InChI | InChIKey | SMILES | Solubility | SD | Ocurrences | Group | MolWt | ... | NumRotatableBonds | NumValenceElectrons | NumAromaticRings | NumSaturatedRings | NumAliphaticRings | RingCount | TPSA | LabuteASA | BalabanJ | BertzCT | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | B-4206 | diuron | InChI=1S/C9H10Cl2N2O/c1-13(2)9(14)12-6-3-4-7(1... | XMTQQYYKAHVGBJ-UHFFFAOYSA-N | CN(C)C(=O)Nc1ccc(Cl)c(Cl)c1 | -3.744300 | 1.227164 | 5 | G4 | 233.098 | ... | 1.0 | 76.0 | 1.0 | 0.0 | 0.0 | 1.0 | 32.34 | 92.603980 | 2.781208 | 352.665233 |
1 | F-988 | 7-(3-amino-3-methylazetidin-1-yl)-8-chloro-1-c... | InChI=1S/C17H17ClFN3O3/c1-17(20)6-21(7-17)14-1... | DUNZFXZSFJLIKR-UHFFFAOYSA-N | CC1(N)CN(C2=C(Cl)C3=C(C=C2F)C(=O)C(C(=O)O)=CN3... | -5.330000 | 0.000000 | 1 | G1 | 365.792 | ... | 3.0 | 132.0 | 2.0 | 2.0 | 2.0 | 4.0 | 88.56 | 147.136366 | 2.001398 | 973.487509 |
2 | C-1996 | 4-acetoxybiphenyl; 4-biphenylyl acetate | InChI=1S/C14H12O2/c1-11(15)16-14-9-7-13(8-10-1... | MISFQCBPASYYGV-UHFFFAOYSA-N | CC(=O)OC1=CC=C(C=C1)C2=CC=CC=C2 | -4.400000 | 0.000000 | 1 | G1 | 212.248 | ... | 2.0 | 80.0 | 2.0 | 0.0 | 0.0 | 2.0 | 26.30 | 94.493449 | 2.228677 | 471.848345 |
3 | A-3055 | methane dimolybdenum | InChI=1S/CH4.2Mo/h1H4;; | JAGQSESDQXCFCH-UHFFFAOYSA-N | C.[Mo].[Mo] | -3.420275 | 0.409223 | 2 | G3 | 207.923 | ... | 0.0 | 20.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.00 | 49.515427 | -0.000000 | 2.754888 |
4 | A-2575 | ethyl 4-[[(methylphenylamino)methylene]amino]b... | InChI=1S/C17H18N2O2/c1-3-21-17(20)14-9-11-15(1... | GNGYPJUKIKDJQT-UHFFFAOYSA-N | CCOC(=O)c1ccc(cc1)N=CN(C)c2ccccc2 | -5.450777 | 0.000000 | 1 | G1 | 282.343 | ... | 5.0 | 108.0 | 2.0 | 0.0 | 0.0 | 2.0 | 41.90 | 124.243431 | 2.028889 | 606.447052 |
5 rows × 26 columns
from rdkit.Chem import MolToSmiles
def _randomize_smiles(mol, isomericSmiles=True):
return MolToSmiles(
mol,
canonical=False,
doRandom=True,
isomericSmiles=isomericSmiles,
kekuleSmiles=random.random() < 0.5,
)
smiles = list(soldata["SMILES"])
solubilities = list(soldata["Solubility"])
aug_data = 10
def largest_mol(smiles):
ss = smiles.split(".")
ss.sort(key=lambda a: len(a))
return ss[-1]
aug_smiles = []
aug_solubilities = []
for sml, sol in zip(smiles, solubilities):
sml = largest_mol(sml)
if len(sml) <= 4:
continue # ion or metal
new_smls = []
new_smls.append(sml)
aug_solubilities.append(sol)
for _ in range(aug_data):
try:
new_sml = _randomize_smiles(MolFromSmiles(sml))
if new_sml not in new_smls:
new_smls.append(new_sml)
aug_solubilities.append(sol)
except:
continue
aug_smiles.extend(new_smls)
aug_df_AqSolDB = pd.DataFrame(
data={"SMILES": aug_smiles, "Solubility": aug_solubilities}
)
print(f"The dataset was augmented from {len(soldata)} to {len(aug_df_AqSolDB)}.")
The dataset was augmented from 100 to 990.
selfies_list = []
for s in aug_df_AqSolDB.SMILES:
try:
selfies_list.append(sf.encoder(exmol.sanitize_smiles(s)[1]))
except sf.EncoderError:
selfies_list.append(None)
len(selfies_list)
990
basic = set(exmol.get_basic_alphabet())
data_vocab = set(
sf.get_alphabet_from_selfies([s for s in selfies_list if s is not None])
)
vocab = ["[nop]"]
vocab.extend(list(data_vocab.union(basic)))
vocab_stoi = {o: i for o, i in zip(vocab, range(len(vocab)))}
def selfies2ints(s):
result = []
for token in sf.split_selfies(s):
if token in vocab_stoi:
result.append(vocab_stoi[token])
else:
result.append(np.nan)
# print('Warning')
return result
def ints2selfies(v):
return "".join([vocab[i] for i in v])
# test them out
s = selfies_list[0]
print("selfies:", s)
v = selfies2ints(s)
print("selfies2ints:", v)
so = ints2selfies(v)
selfies: [C][N][Branch1][C][C][C][=Branch1][C][=O][N][C][=C][C][=C][Branch1][C][Cl][C][Branch1][C][Cl][=C][Ring1][Branch2]
selfies2ints: [8, 37, 46, 8, 8, 8, 26, 8, 28, 37, 8, 19, 8, 19, 46, 8, 27, 8, 46, 8, 27, 19, 47, 23]
# creating an object
@dataclass
class Config:
vocab_size: int
example_number: int
batch_size: int
buffer_size: int
embedding_dim: int
rnn_units: int
hidden_dim: int
drop_rate: float
config = Config(
vocab_size=len(vocab),
example_number=len(selfies_list),
batch_size=128,
buffer_size=10000,
embedding_dim=64,
hidden_dim=32,
rnn_units=64,
drop_rate=0.20,
)
# now get sequences
encoded = [selfies2ints(s) for s in selfies_list if s is not None]
# check for non-Nones
dsolubilities = aug_df_AqSolDB.Solubility.values[[s is not None for s in selfies_list]]
padded_seqs = tf.keras.preprocessing.sequence.pad_sequences(encoded, padding="post")
# Should be shuffled from the beginning, so no worries
N = len(padded_seqs)
split = int(0.1 * N)
# Now build dataset
test_data = tf.data.Dataset.from_tensor_slices(
(padded_seqs[:split], dsolubilities[:split])
).batch(config.batch_size)
nontest = tf.data.Dataset.from_tensor_slices(
(
padded_seqs[split:],
dsolubilities[split:],
)
)
val_data, train_data = nontest.take(split).batch(config.batch_size), nontest.skip(
split
).shuffle(config.buffer_size).batch(config.batch_size).prefetch(
tf.data.experimental.AUTOTUNE
)
2024-11-22 07:13:36.299792: E external/local_xla/xla/stream_executor/cuda/cuda_driver.cc:152] failed call to cuInit: INTERNAL: CUDA error: Failed call to cuInit: UNKNOWN ERROR (303)
model = tf.keras.Sequential()
# make embedding and indicate that 0 should be treated as padding mask
model.add(
tf.keras.layers.Embedding(
input_dim=config.vocab_size, output_dim=config.embedding_dim, mask_zero=True
)
)
model.add(tf.keras.layers.Dropout(config.drop_rate))
# RNN layer
model.add(tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(config.rnn_units)))
model.add(tf.keras.layers.Dropout(config.drop_rate))
# a dense hidden layer
model.add(tf.keras.layers.Dense(config.hidden_dim, activation="relu"))
model.add(tf.keras.layers.Dropout(config.drop_rate))
# regression, so no activation
model.add(tf.keras.layers.Dense(1))
model.summary()
Model: "sequential"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ Layer (type) ┃ Output Shape ┃ Param # ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ embedding (Embedding) │ ? │ 0 (unbuilt) │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ dropout (Dropout) │ ? │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ bidirectional (Bidirectional) │ ? │ 0 (unbuilt) │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ dropout_1 (Dropout) │ ? │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ dense (Dense) │ ? │ 0 (unbuilt) │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ dropout_2 (Dropout) │ ? │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ dense_1 (Dense) │ ? │ 0 (unbuilt) │ └─────────────────────────────────┴────────────────────────┴───────────────┘
Total params: 0 (0.00 B)
Trainable params: 0 (0.00 B)
Non-trainable params: 0 (0.00 B)
model.compile(tf.optimizers.Adam(1e-3), loss="mean_squared_error")
# verbose=0 silences output, to get progress bar set verbose=1
result = model.fit(train_data, validation_data=val_data, epochs=50)
Epoch 1/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 20s 3s/step - loss: 15.0685
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 14.5936
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 14.1256
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 13.8193
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 13.5470
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 13.3304
7/7 ━━━━━━━━━━━━━━━━━━━━ 4s 141ms/step - loss: 13.0483 - val_loss: 2.8211
Epoch 2/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 7.0953
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 93ms/step - loss: 7.0001
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 6.7939
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 6.5524
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 6.3525
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 6.2091
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 89ms/step - loss: 6.0394 - val_loss: 2.7968
Epoch 3/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 4s 723ms/step - loss: 4.9196
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 4.7438
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 4.6067
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 4.5616
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 4.5204
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 4.4938
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 4.4655 - val_loss: 0.6939
Epoch 4/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 5.3539
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 4.7330
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 4.5435
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 4.4911
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 4.4875
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 4.4717
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 4.4460 - val_loss: 0.8536
Epoch 5/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 3.2194
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 3.7311
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 3.8330
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 3.8705
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 3.9283
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 3.9366
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 3.9382 - val_loss: 1.0549
Epoch 6/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 4s 721ms/step - loss: 4.7328
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 4.7387
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 4.4897
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 4.3443
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 4.2456
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 4.1544
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 4.0274 - val_loss: 0.5568
Epoch 7/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.5036
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 2.8442
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 2.9153
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 2.9524
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.9758
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 2.9879
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 3.0103 - val_loss: 1.9184
Epoch 8/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 2.8965
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 93ms/step - loss: 3.0031
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 3.0334
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 3.0219
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 3.0276
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 3.0321
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 3.0358 - val_loss: 0.7619
Epoch 9/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 2.2019
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 100ms/step - loss: 2.4006
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 2.5066
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.5196
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.5244
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.5058
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 2.4761 - val_loss: 1.1086
Epoch 10/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.8922
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 2.0952
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 2.1656
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 2.2139
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 2.2423
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.2607
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 2.2786 - val_loss: 1.2569
Epoch 11/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 2.0837
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 2.0542
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 2.0204
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.9994
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.9910
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.9820
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 1.9868 - val_loss: 0.8532
Epoch 12/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 2.0918
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 2.0388
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 2.0487
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.0515
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.0485
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 2.0491
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 2.0510 - val_loss: 0.7945
Epoch 13/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 2.2396
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 2.2821
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.2266
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.1806
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.1594
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.1341
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 2.1043 - val_loss: 1.0119
Epoch 14/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 4s 715ms/step - loss: 2.3958
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.2164
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 2.1315
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 2.0780
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 2.0380
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 2.0035
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 94ms/step - loss: 1.9537 - val_loss: 0.7287
Epoch 15/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 1.8084
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.7963
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.7970
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.7806
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.7662
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.7620
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 1.7517 - val_loss: 0.8935
Epoch 16/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.3415
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 101ms/step - loss: 1.4663
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.4724
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.5053
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.5297
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.5546
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.5890 - val_loss: 1.3552
Epoch 17/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 2.1050
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 2.0225
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.9360
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.8799
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.8519
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.8315
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.8080 - val_loss: 0.6823
Epoch 18/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 4s 720ms/step - loss: 1.5372
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.5007
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.5123
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.5141
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.5428
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.5540
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.5684 - val_loss: 0.6643
Epoch 19/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.6614
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.5875
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.5780
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5802
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5891
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5940
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 1.6049 - val_loss: 0.7406
Epoch 20/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 101ms/step - loss: 1.6424
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.5655
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5435
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5392
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5378
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5345
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 1.5372 - val_loss: 0.6090
Epoch 21/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1777
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.2508
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.2864
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.3065
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.3346
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.3601
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.3895 - val_loss: 0.6761
Epoch 22/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.6181
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.5600
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.5438
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.5425
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.5477
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.5453
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.5437 - val_loss: 0.9787
Epoch 23/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 4s 712ms/step - loss: 1.4135
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4427
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.4779
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4799
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4765
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4734
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.4665 - val_loss: 0.8246
Epoch 24/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.1981
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.2827
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.2968
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.3035
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.3239
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.3386
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 1.3590 - val_loss: 0.6465
Epoch 25/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.1293
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.2107
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.2657
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.2910
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.3006
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.3091
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.3221 - val_loss: 0.6166
Epoch 26/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.7039
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.6657
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.6138
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5710
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5421
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.5379
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 1.5239 - val_loss: 0.7815
Epoch 27/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4160
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 102ms/step - loss: 1.5260
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.5299
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.5304
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.5189
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.5089
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.4958 - val_loss: 0.6223
Epoch 28/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.4940
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 93ms/step - loss: 1.4566
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.4527
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.4570
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4511
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.4447
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.4349 - val_loss: 0.6110
Epoch 29/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.3136
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.3863
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.3791
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.3837
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.3888
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.3877
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.3878 - val_loss: 0.6839
Epoch 30/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.3471
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.4065
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.4591
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.4801
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.4769
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.4635
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.4426 - val_loss: 0.8191
Epoch 31/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.0090
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 93ms/step - loss: 1.1230
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.1925
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.2389
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.2549
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.2641
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.2730 - val_loss: 0.9004
Epoch 32/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1535
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 93ms/step - loss: 1.1279
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.1549
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1764
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1954
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.2087
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 1.2284 - val_loss: 1.3872
Epoch 33/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.4570
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.4403
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4128
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.3931
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.3870
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.3780
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.3618 - val_loss: 1.6115
Epoch 34/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.5032
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.4386
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.4043
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.3783
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.3649
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.3520
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 89ms/step - loss: 1.3356 - val_loss: 1.0871
Epoch 35/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 1.1222
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 103ms/step - loss: 1.1727
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 1.1566
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 1.1651
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.1564
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.1586
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.1649 - val_loss: 1.1651
Epoch 36/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.0249
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.0438
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.0302
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0595
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0773
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.0959
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.1158 - val_loss: 0.7573
Epoch 37/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 1.0536
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.0813
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1041
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.1284
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1470
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.1487
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.1488 - val_loss: 0.7867
Epoch 38/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 100ms/step - loss: 1.3943
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.3849
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 1.3710
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.3336
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.3171
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.3008
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.2771 - val_loss: 0.7565
Epoch 39/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.6180
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.5450
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.5101
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4820
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4655
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.4531
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.4335 - val_loss: 0.7326
Epoch 40/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 4s 713ms/step - loss: 1.0324
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.1118
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1263
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.1355
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.1461
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.1507
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.1582 - val_loss: 0.8682
Epoch 41/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.2134
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.2024
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.1982
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.2055
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.2105
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.2134
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 1.2152 - val_loss: 0.8564
Epoch 42/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.0058
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 101ms/step - loss: 1.0005
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.0278
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.0529
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.0743
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0904
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.1093 - val_loss: 0.7754
Epoch 43/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.2488
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.1581
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1196
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1103
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1047
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.1080
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.1156 - val_loss: 1.0258
Epoch 44/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.1956
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.1210
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0996
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0757
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0565
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0513
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.0486 - val_loss: 0.7387
Epoch 45/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.0102
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 0.9663
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 99ms/step - loss: 0.9599
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 0.9688
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 0.9871
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 0.9985
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.0173 - val_loss: 0.8220
Epoch 46/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 101ms/step - loss: 1.0829
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.0854
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0758
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0718
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0711
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.0670
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 1.0589 - val_loss: 0.9502
Epoch 47/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 103ms/step - loss: 1.1879
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0967
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0817
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.0773
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.0739
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.0708
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 90ms/step - loss: 1.0632 - val_loss: 1.3549
Epoch 48/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.3558
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 94ms/step - loss: 1.2995
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 1.2660
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 1.2371
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.2140
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.2002
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.1815 - val_loss: 0.8171
Epoch 49/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 0.8329
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 0.8932
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 0.9361
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 0.9476
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 95ms/step - loss: 0.9602
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 96ms/step - loss: 0.9715
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 91ms/step - loss: 0.9888 - val_loss: 0.6786
Epoch 50/50
1/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.3286
2/7 ━━━━━━━━━━━━━━━━━━━━ 0s 102ms/step - loss: 1.3050
3/7 ━━━━━━━━━━━━━━━━━━━━ 0s 100ms/step - loss: 1.2773
4/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.2473
5/7 ━━━━━━━━━━━━━━━━━━━━ 0s 98ms/step - loss: 1.2213
6/7 ━━━━━━━━━━━━━━━━━━━━ 0s 97ms/step - loss: 1.2014
7/7 ━━━━━━━━━━━━━━━━━━━━ 1s 92ms/step - loss: 1.1739 - val_loss: 0.8127
model.save("solubility-rnn-accurate")
# model = tf.keras.models.load_model('solubility-rnn-accurate/')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[11], line 1
----> 1 model.save("solubility-rnn-accurate")
2 # model = tf.keras.models.load_model('solubility-rnn-accurate/')
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.__traceback__)
120 # To get the full stack trace, call:
121 # `keras.config.disable_traceback_filtering()`
--> 122 raise e.with_traceback(filtered_tb) from None
123 finally:
124 del filtered_tb
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/keras/src/saving/saving_api.py:114, in save_model(model, filepath, overwrite, zipped, **kwargs)
110 if str(filepath).endswith((".h5", ".hdf5")):
111 return legacy_h5_format.save_model_to_hdf5(
112 model, filepath, overwrite, include_optimizer
113 )
--> 114 raise ValueError(
115 "Invalid filepath extension for saving. "
116 "Please add either a `.keras` extension for the native Keras "
117 f"format (recommended) or a `.h5` extension. "
118 "Use `model.export(filepath)` if you want to export a SavedModel "
119 "for use with TFLite/TFServing/etc. "
120 f"Received: filepath={filepath}."
121 )
ValueError: Invalid filepath extension for saving. Please add either a `.keras` extension for the native Keras format (recommended) or a `.h5` extension. Use `model.export(filepath)` if you want to export a SavedModel for use with TFLite/TFServing/etc. Received: filepath=solubility-rnn-accurate.
plt.figure(figsize=(5, 3.5))
plt.plot(result.history["loss"], label="training")
plt.plot(result.history["val_loss"], label="validation")
plt.legend()
plt.xlabel("Epoch")
plt.ylabel("Loss")
plt.savefig("rnn-loss.png", bbox_inches="tight", dpi=300)
plt.show()
yhat = []
test_y = []
for x, y in test_data:
yhat.extend(model(x).numpy().flatten())
test_y.extend(y.numpy().flatten())
yhat = np.array(yhat)
test_y = np.array(test_y)
# plot test data
plt.figure(figsize=(5, 3.5))
plt.plot(test_y, test_y, ":")
plt.plot(test_y, yhat, ".")
plt.text(
max(test_y) - 6,
min(test_y) + 1,
f"correlation = {np.corrcoef(test_y, yhat)[0,1]:.3f}",
)
plt.text(
max(test_y) - 6, min(test_y), f"loss = {np.sqrt(np.mean((test_y - yhat)**2)):.3f}"
)
plt.xlabel(r"$y$")
plt.ylabel(r"$\hat{y}$")
plt.title("Testing Data")
plt.savefig("rnn-fit.png", dpi=300, bbox_inches="tight")
plt.show()
LIME explanations
In the following example, we find out what descriptors influence solubility of a molecules. For example, let’s say we have a molecule with LogS=1.5. We create a perturbed chemical space around that molecule using stoned
method and then use lime
to find out which descriptors affect solubility predictions for that molecule.
Wrapper function for RNN, to use in STONED
# Predictor function is used as input to sample_space function
def predictor_function(smile_list, selfies):
encoded = [selfies2ints(s) for s in selfies]
# check for nans
valid = [1.0 if sum(e) > 0 else np.nan for e in encoded]
encoded = [np.nan_to_num(e, nan=0) for e in encoded]
padded_seqs = tf.keras.preprocessing.sequence.pad_sequences(encoded, padding="post")
labels = np.reshape(model(padded_seqs, training=False), (-1))
return labels * valid
Descriptor explanations
# Make sure SMILES doesn't contain multiple fragments
smi = "CCCCC(=O)N(CC1=CC=C(C=C1)C2=C(C=CC=C2)C3=NN=N[NH]3)C(C(C)C)C(O)=O" # mol1 - not soluble
# smi = "CC(CC(=O)NC1=CC=CC=C1)C(=O)O" #mol2 - highly soluble
af = exmol.get_basic_alphabet()
stoned_kwargs = {
"num_samples": 5000,
"alphabet": af,
"max_mutations": 2,
}
space = exmol.sample_space(
smi, predictor_function, stoned_kwargs=stoned_kwargs, quiet=True
)
print(len(space))
from IPython.display import display, SVG
desc_type = ["Classic", "ecfp", "maccs"]
for d in desc_type:
beta = exmol.lime_explain(space, descriptor_type=d)
if d == "ecfp":
display(
SVG(
exmol.plot_descriptors(
space, output_file=f"{d}_mol2.svg", return_svg=True
)
)
)
plt.close()
else:
exmol.plot_descriptors(space, output_file=f"{d}_mol2.svg")
Text explanations
exmol.lime_explain(space, "ecfp")
s1_ecfp = exmol.text_explain(space, "ecfp")
explanation = exmol.text_explain_generate(s1_ecfp, "aqueous solubility")
print(explanation)
Similarity map
beta = exmol.lime_explain(space, "ecfp")
svg = exmol.plot_utils.similarity_map_using_tstats(space[0], return_svg=True)
display(SVG(svg))
# Write figure to file
with open("ecfp_similarity_map_mol2.svg", "w") as f:
f.write(svg)
# Inspect space
MolsToGridImage(
[MolFromSmiles(m.smiles) for m in space],
legends=[f"yhat = {m.yhat:.3}" for m in space],
molsPerRow=10,
maxMols=100,
)
How’s the fit?
fkw = {"figsize": (6, 4)}
font = {"family": "normal", "weight": "normal", "size": 16}
fig = plt.figure(figsize=(10, 5))
mpl.rc("axes", titlesize=12)
mpl.rc("font", size=16)
ax_dict = fig.subplot_mosaic("AABBB")
# Plot space by fit
svg = exmol.plot_utils.plot_space_by_fit(
space,
[space[0]],
figure_kwargs=fkw,
mol_size=(200, 200),
offset=1,
ax=ax_dict["B"],
beta=beta,
)
# Compute y_wls
w = np.array([1 / (1 + (1 / (e.similarity + 0.000001) - 1) ** 5) for e in space])
non_zero = w > 10 ** (-6)
w = w[non_zero]
N = w.shape[0]
ys = np.array([e.yhat for e in space])[non_zero].reshape(N).astype(float)
x_mat = np.array([list(e.descriptors.descriptors) for e in space])[non_zero].reshape(
N, -1
)
y_wls = x_mat @ beta
y_wls += np.mean(ys)
lower = np.min(ys)
higher = np.max(ys)
# set transparency using w
norm = plt.Normalize(min(w), max(w))
cmap = plt.cm.Oranges(w)
cmap[:, -1] = w
def weighted_mean(x, w):
return np.sum(x * w) / np.sum(w)
def weighted_cov(x, y, w):
return np.sum(w * (x - weighted_mean(x, w)) * (y - weighted_mean(y, w))) / np.sum(w)
def weighted_correlation(x, y, w):
return weighted_cov(x, y, w) / np.sqrt(
weighted_cov(x, x, w) * weighted_cov(y, y, w)
)
corr = weighted_correlation(ys, y_wls, w)
ax_dict["A"].plot(
np.linspace(lower, higher, 100), np.linspace(lower, higher, 100), "--", linewidth=2
)
sc = ax_dict["A"].scatter(ys, y_wls, s=50, marker=".", c=cmap, cmap=cmap)
ax_dict["A"].text(max(ys) - 3, min(ys) + 1, f"weighted \ncorrelation = {corr:.3f}")
ax_dict["A"].set_xlabel(r"$\hat{y}$")
ax_dict["A"].set_ylabel(r"$g$")
ax_dict["A"].set_title("Weighted Least Squares Fit")
ax_dict["A"].set_xlim(lower, higher)
ax_dict["A"].set_ylim(lower, higher)
ax_dict["A"].set_aspect(1.0 / ax_dict["A"].get_data_ratio(), adjustable="box")
sm = plt.cm.ScalarMappable(cmap=plt.cm.Oranges, norm=norm)
cbar = plt.colorbar(sm, orientation="horizontal", pad=0.15, ax=ax_dict["A"])
cbar.set_label("Chemical similarity")
plt.tight_layout()
plt.savefig("weighted_fit.svg", dpi=300, bbox_inches="tight", transparent=False)
Robustness to incomplete sampling
We first sample a reference chemical space, and then subsample smaller chemical spaces from this reference. Rank correlation is computed between important descriptors for the smaller subspaces and the reference space.
# Sample a big space
stoned_kwargs = {
"num_samples": 5000,
"alphabet": exmol.get_basic_alphabet(),
"max_mutations": 2,
}
space = exmol.sample_space(
smi, predictor_function, stoned_kwargs=stoned_kwargs, quiet=True
)
len(space)
# get descriptor attributions
exmol.lime_explain(space, "MACCS", return_beta=False)
# Assign feature ids for rank comparison
features = features = {
a: b
for a, b in zip(
space[0].descriptors.descriptor_names,
np.arange(len(space[0].descriptors.descriptors)),
)
}
# Get set of ranks for the reference space
baseline_imp = {
a: b
for a, b in zip(space[0].descriptors.descriptor_names, space[0].descriptors.tstats)
if not np.isnan(b)
}
baseline_imp = dict(
sorted(baseline_imp.items(), key=lambda item: abs(item[1]), reverse=True)
)
baseline_set = [features[x] for x in baseline_imp.keys()]
# Get subsets and calculate lime importances - subsample - get rank correlation
from scipy.stats import spearmanr
plt.figure(figsize=(4, 3))
N = len(space)
size = np.arange(500, N, 1000)
rank_corr = {N: 1}
for i, f in enumerate(size):
# subsample space
rank_corr[f] = []
for _ in range(10):
# subsample space of size f
idx = np.random.choice(np.arange(N), size=f, replace=False)
subspace = [space[i] for i in idx]
# get desc attributions
ss_beta = exmol.lime_explain(subspace, descriptor_type="MACCS")
ss_imp = {
a: b
for a, b in zip(
subspace[0].descriptors.descriptor_names, subspace[0].descriptors.tstats
)
if not np.isnan(b)
}
ss_imp = dict(
sorted(ss_imp.items(), key=lambda item: abs(item[1]), reverse=True)
)
ss_set = [features[x] for x in ss_imp.keys()]
# Get ranks for subsampled space and compare with reference
ranks = {a: [b] for a, b in zip(baseline_set[:5], np.arange(1, 6))}
for j, s in enumerate(ss_set):
if s in ranks:
ranks[s].append(j + 1)
# compute rank correlation
r = spearmanr(np.arange(1, 6), [ranks[x][1] for x in ranks])
rank_corr[f].append(r.correlation)
plt.scatter(f, np.mean(rank_corr[f]), color="#13254a", marker="o")
plt.scatter(N, 1.0, color="red", marker="o")
plt.axvline(x=N, linestyle=":", color="red")
plt.xlabel("Size of chemical space")
plt.ylabel("Rank correlation")
plt.tight_layout()
plt.savefig("rank correlation.svg", dpi=300, bbox_inches="tight")
Effect of mutation number, alphabet and size of chemical space
# Mutation
desc_type = ["Classic"]
muts = [1, 2, 3]
for i in muts:
stoned_kwargs = {
"num_samples": 2500,
"alphabet": exmol.get_basic_alphabet(),
"min_mutations": i,
"max_mutations": i,
}
space = exmol.sample_space(
smi, predictor_function, stoned_kwargs=stoned_kwargs, quiet=True
)
for d in desc_type:
exmol.lime_explain(space, descriptor_type=d)
exmol.plot_descriptors(space, title=f"Mutations={i}")
# Alphabet
basic = exmol.get_basic_alphabet()
train = sf.get_alphabet_from_selfies([s for s in selfies_list if s is not None])
wide = sf.get_semantic_robust_alphabet()
desc_type = ["MACCS"]
alphs = {"Basic": basic, "Training Data": train, "SELFIES": wide}
for a in alphs:
stoned_kwargs = {"num_samples": 2500, "alphabet": alphs[a], "max_mutations": 2}
space = exmol.sample_space(
smi, predictor_function, stoned_kwargs=stoned_kwargs, quiet=True
)
for d in desc_type:
exmol.lime_explain(space, descriptor_type=d)
exmol.plot_descriptors(space, title=f"Alphabet: {a}")
# Size of space
desc_type = ["MACCS"]
space_size = [1500, 2000, 2500]
for s in space_size:
stoned_kwargs = {
"num_samples": s,
"alphabet": exmol.get_basic_alphabet(),
"max_mutations": 2,
}
space = exmol.sample_space(
smi, predictor_function, stoned_kwargs=stoned_kwargs, quiet=True
)
for d in desc_type:
exmol.lime_explain(space, descriptor_type=d)
exmol.plot_descriptors(
space,
title=f"Chemical space size={s}",
)