File size: 34,706 Bytes
8869ef6 c12461a 53c6043 8869ef6 c12461a 8869ef6 c12461a 8869ef6 c12461a 8869ef6 c12461a 8869ef6 c12461a 8869ef6 c12461a 8869ef6 c12461a 8869ef6 c12461a 8869ef6 403e4e4 c12461a 8869ef6 156d655 8869ef6 f9bf7a6 847f3bc 8869ef6 156d655 8869ef6 7c5ae3f 8869ef6 7c5ae3f 8869ef6 57b5fd0 1310a2f 57b5fd0 1310a2f 57b5fd0 1310a2f 57b5fd0 1310a2f 57b5fd0 1310a2f 8ee5602 57b5fd0 1310a2f 57b5fd0 8869ef6 227c1b1 8869ef6 fb74285 2c69219 fb74285 2c69219 fb74285 2c69219 fb74285 2c69219 fb74285 2c69219 fb74285 2c69219 7aedee9 2c69219 7aedee9 2c69219 9e8a1b3 8ee5602 c8e44c2 7aedee9 8869ef6 27358a3 68c3463 27358a3 73fe99b 2bf549f c12461a f9bf7a6 c12461a 8869ef6 2c69219 8869ef6 2c69219 c8e44c2 8869ef6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
---
library_name: sentence-transformers
metrics:
- pearson_cosine
- spearman_cosine
- pearson_manhattan
- spearman_manhattan
- pearson_euclidean
- spearman_euclidean
- pearson_dot
- spearman_dot
- pearson_max
- spearman_max
pipeline_tag: sentence-similarity
tags:
- sentence-transformers
- sentence-similarity
- feature-extraction
- loss:MatryoshkaLoss
- loss:CosineSimilarityLoss
- chemistry
- biology
- drug-discovery
- herbal
- coconutdb
- chembl34
- selfies
- drugs
- molecules
- compounds
widget:
- source_sentence: >-
[N] [C] [=N] [C] [=N] [C] [=C] [Ring1] [=Branch1] [S] [C] [=C]
[C] [Branch1] [=Branch2] [C] [=C] [C] [=C] [C] [=C] [Ring1]
[=Branch1] [=C] [C] [=C] [Ring1] [N] [Ring1] [#C]
sentences:
- >-
[C] [C] [C] [C] [C@H1] [Branch2] [#Branch2] [Branch2] [N] [C]
[=Branch1] [C] [=O] [C@@H1] [C] [C] [C] [C] [N] [C] [=Branch1]
[C] [=O] [C] [C] [C@H1] [Branch2] [=Branch1] [S] [N] [C]
[=Branch1] [C] [=O] [C@H1] [Branch1] [#Branch2] [C] [C] [C] [N]
[=C] [Branch1] [C] [N] [N] [N] [C] [=Branch1] [C] [=O] [C@H1]
[Branch1] [#Branch1] [C] [C] [Branch1] [C] [C] [C] [N] [C]
[=Branch1] [C] [=O] [C@H1] [Branch1] [#Branch1] [C] [C] [Branch1]
[C] [C] [C] [N] [C] [=Branch1] [C] [=O] [C@H1] [Branch1]
[=Branch2] [C] [C] [=C] [NH1] [C] [=N] [Ring1] [Branch1] [N] [C]
[=Branch1] [C] [=O] [C@H1] [Branch1] [C] [N] [C] [C] [=C] [C]
[=C] [C] [=C] [Ring1] [=Branch1] [C] [=Branch1] [C] [=O] [N]
[C@@H1] [Branch1] [=Branch1] [C] [Branch1] [C] [C] [C] [C]
[=Branch1] [C] [=O] [N] [C@H1] [Branch1] [#Branch1] [C] [C]
[Branch1] [C] [C] [C] [C] [=Branch1] [C] [=O] [N] [Ring2]
[=Branch1] [=C] [C] [=Branch1] [C] [=O] [N] [C@@H1] [Branch1] [C]
[C] [C] [=Branch1] [C] [=O] [N] [C@@H1] [Branch1] [#Branch2] [C]
[C] [C] [N] [=C] [Branch1] [C] [N] [N] [C] [=Branch1] [C] [=O]
[N] [C@@H1] [Branch1] [C] [C] [C] [=Branch1] [C] [=O] [N] [C@@H1]
[Branch1] [Branch2] [C] [C] [C] [=Branch1] [C] [=O] [O] [C]
[=Branch1] [C] [=O] [N] [C@@H1] [Branch1] [Branch2] [C] [C] [C]
[Branch1] [C] [N] [=O] [C] [=Branch1] [C] [=O] [N] [C@@H1]
[Branch1] [#Branch1] [C] [C] [Branch1] [C] [C] [C] [C] [=Branch1]
[C] [=O] [N] [C@@H1] [Branch1] [C] [C] [C] [=Branch1] [C] [=O]
[N] [C@@H1] [Branch1] [Branch2] [C] [C] [C] [Branch1] [C] [N]
[=O] [C] [=Branch1] [C] [=O] [N] [C@@H1] [Branch1] [Branch2] [C]
[C] [C] [Branch1] [C] [N] [=O] [C] [=Branch1] [C] [=O] [N]
[C@@H1] [Branch1] [C] [C] [C] [=Branch1] [C] [=O] [N] [C@@H1]
[Branch1] [=Branch2] [C] [C] [=C] [NH1] [C] [=N] [Ring1] [Branch1]
[C] [=Branch1] [C] [=O] [N] [C@@H1] [Branch1] [Ring1] [C] [O] [C]
[=Branch1] [C] [=O] [N] [C@@H1] [Branch1] [#Branch1] [C] [C]
[Branch1] [C] [N] [=O] [C] [=Branch1] [C] [=O] [N] [C@@H1]
[Branch1] [#Branch2] [C] [C] [C] [N] [=C] [Branch1] [C] [N] [N]
[C] [=Branch1] [C] [=O] [N] [C@@H1] [Branch1] [=Branch1] [C] [C]
[C] [C] [N] [C] [=Branch1] [C] [=O] [N] [C@@H1] [Branch1]
[#Branch1] [C] [C] [Branch1] [C] [C] [C] [C] [=Branch1] [C] [=O]
[N] [C@@H1] [Branch1] [Branch1] [C] [C] [C] [C] [C] [=Branch1]
[C] [=O] [N] [C@@H1] [Branch1] [Branch2] [C] [C] [C] [=Branch1]
[C] [=O] [O] [C] [=Branch1] [C] [=O] [N] [C@H1] [Branch2] [Ring1]
[Ring2] [C] [=Branch1] [C] [=O] [N] [C@H1] [Branch1] [=Branch1]
[C] [Branch1] [C] [N] [=O] [C@@H1] [Branch1] [C] [C] [C] [C]
[C@@H1] [Branch1] [C] [C] [C] [C]
- >-
[C] [C] [=Branch1] [C] [=O] [N] [C@H1] [C@H1] [Branch2] [Ring2]
[#Branch2] [O] [C@H1] [C@@H1] [Branch1] [C] [O] [C@@H1] [Branch1]
[Ring1] [C] [O] [O] [C@@H1] [Branch2] [Ring1] [Branch1] [O] [C@H1]
[C@H1] [Branch1] [C] [O] [C@@H1] [Branch1] [C] [O] [C@H1]
[Branch1] [C] [O] [O] [C@@H1] [Ring1] [=Branch2] [C] [O] [C@@H1]
[Ring2] [Ring1] [Branch1] [O] [O] [C@H1] [Branch1] [Ring1] [C] [O]
[C@@H1] [Branch1] [C] [O] [C@@H1] [Ring2] [Ring1] [S] [O] [C@@H1]
[O] [C@H1] [Branch1] [Ring1] [C] [O] [C@H1] [Branch1] [C] [O]
[C@H1] [Branch1] [C] [O] [C@H1] [Ring1] [#Branch2] [O]
- >-
[C] [C] [=C] [C] [=C] [C] [Branch2] [Ring1] [Ring1] [N] [C]
[=Branch1] [C] [=O] [C] [O] [C] [=C] [C] [=C] [C] [Branch1] [C]
[C] [=C] [Ring1] [#Branch1] [=C] [Ring2] [Ring1] [C]
- source_sentence: >-
[O] [=C] [Branch1] [C] [O] [C] [O] [C] [Branch2] [O] [=C] [O]
[C] [C] [C] [C] [Branch1] [C] [C] [C] [Branch2] [#Branch2]
[#Branch2] [C] [C] [C] [Branch1] [C] [C] [C] [Ring1] [Branch2]
[C] [C] [=C] [C] [C] [C] [Branch1] [C] [C] [Branch1] [C] [C]
[C] [C] [C] [Ring1] [Branch2] [Branch2] [#Branch1] [S] [C]
[=Branch1] [C] [=O] [O] [C] [O] [C] [C] [Branch1] [C] [O] [C]
[Branch1] [C] [O] [C] [Ring1] [Branch2] [O] [C] [O] [C] [Branch1]
[C] [C] [C] [Branch2] [Ring1] [S] [O] [C] [O] [C] [C] [Branch1]
[C] [O] [C] [Branch1] [P] [O] [C] [O] [C] [C] [Branch1] [C] [O]
[Branch1] [Ring1] [C] [O] [C] [Ring1] [Branch2] [O] [C] [Ring1]
[P] [O] [C] [Branch2] [Ring1] [#Branch2] [O] [C] [O] [C]
[Branch1] [Branch2] [C] [O] [C] [=Branch1] [C] [=O] [C] [C]
[Branch1] [C] [O] [C] [Branch1] [C] [O] [C] [Ring1] [=N] [O] [C]
[Ring2] [Ring2] [=Branch2] [O] [C] [Branch1] [C] [O] [C] [C]
[Ring2] [=Branch1] [Branch2] [Ring2] [=Branch1] [Ring1] [C] [C]
[Ring2] [#Branch1] [C] [Branch1] [C] [C] [C] [C] [Branch1] [C]
[O] [C] [Branch1] [C] [O] [C] [Ring2] [#Branch1] [=N] [O]
sentences:
- >-
[C] [C] [=C] [C] [Branch1] [C] [C] [=C] [Branch1] [S] [N] [C]
[=C] [C] [Branch1] [C] [F] [=C] [C] [Branch1] [C] [F] [=C]
[Ring1] [Branch2] [C] [Branch1] [C] [C] [=C] [Ring1] [P]
- >-
[N] [C] [=N] [C] [=N] [C] [=C] [Ring1] [=Branch1] [N] [=C] [N]
[Ring1] [Branch1] [C@@H1] [O] [C@H1] [Branch2] [=Branch2] [O] [C]
[O] [P] [=Branch1] [C] [=O] [Branch1] [C] [O] [O] [C@H1] [C@@H1]
[Branch1] [C] [O] [C@H1] [Branch1] [S] [N] [C] [=C] [Branch1] [C]
[I] [C] [=Branch1] [C] [=O] [NH1] [C] [Ring1] [Branch2] [=O] [O]
[C@@H1] [Ring1] [#C] [C] [O] [P] [=Branch1] [C] [=O] [Branch1]
[C] [O] [O] [C@H1] [C@@H1] [Branch1] [C] [O] [C@H1] [Branch1] [S]
[N] [C] [=C] [Branch1] [C] [F] [C] [=Branch1] [C] [=O] [NH1] [C]
[Ring1] [Branch2] [=O] [O] [C@@H1] [Ring1] [#C] [C] [O] [P]
[=Branch1] [C] [=O] [Branch1] [C] [O] [O] [C@H1] [C@@H1] [Branch1]
[C] [O] [C@H1] [Branch1] [P] [N] [C] [=N] [C] [=C] [Branch1] [C]
[N] [N] [=C] [N] [=C] [Ring1] [#Branch1] [Ring1] [#Branch2] [O]
[C@@H1] [Ring1] [S] [C] [O] [P] [=Branch1] [C] [=O] [Branch1] [C]
[O] [O] [C@@H1] [Branch1] [C] [O] [C@H1] [Ring2] [=Branch1] [N]
[O]
- >-
[C] [C] [C] [Branch1] [C] [C] [C] [C] [C] [C] [C] [C] [#C]
[/C] [=C] [\O] [C] [C@@H1] [Branch1] [C] [O] [C] [O]
- source_sentence: >-
[O] [=C] [N] [=C] [Branch1] [C] [NH1-1] [N] [=C] [C] [Ring1]
[#Branch1] [=N] [C] [NH1+1] [Ring1] [Branch1] [C] [=N] [C] [=C]
[N] [Ring1] [Branch1] [C] [C] [=C] [C] [=C] [Branch2] [Ring2]
[=Branch2] [O] [C] [=C] [Ring1] [=Branch1] [C] [Branch1] [Ring1]
[O] [C] [=C] [C] [Branch2] [Ring1] [Ring2] [O] [C] [Branch1]
[Ring2] [C] [Ring1] [Branch1] [C] [Branch1] [C] [O] [Branch1] [C]
[C] [C] [C] [C] [C] [O] [=C] [Ring2] [Ring1] [Ring1] [C] [O]
[C] [=Branch1] [C] [=O] [O] [C] [C]
sentences:
- >-
[O] [=C] [Branch2] [#Branch1] [=Branch1] [O] [C] [Branch1] [C] [C]
[C] [C] [=C] [C] [S] [S] [C] [C] [N] [Branch2] [Branch1] [=N]
[C] [=Branch1] [C] [=O] [C] [C] [=C] [N] [=C] [Branch1] [C] [N]
[C] [=C] [Ring1] [#Branch1] [C] [Ring2] [Ring1] [C] [C] [Ring2]
[Ring1] [#Branch1] [O] [C] [=C] [C] [O] [C] [=Branch1] [C] [=O]
[C] [=Branch1] [N] [=C] [C] [=Ring1] [#Branch1] [C] [=C] [Ring1]
[O] [C] [Ring1] [=C] [C] [Branch1] [Ring2] [C] [C] [O] [C] [C]
[C] [C] [C] [Ring1] [=Branch2] [C] [C] [Ring2] [Ring2] [=Branch1]
[C] [N] [C] [C] [=Branch1] [Ring1] [=C] [C] [C]
- >-
[N] [C] [=C] [C] [=C] [Branch1] [C] [Cl] [C] [=C] [Ring1]
[#Branch1] [C] [=O]
- >-
[O] [=P] [Branch1] [C] [O] [Branch1] [C] [O] [O] [P] [=Branch1]
[C] [=O] [Branch1] [C] [O] [O] [C] [C] [=C] [C] [C] [C] [C]
[Ring1] [=Branch1]
- source_sentence: >-
[C] [C] [O] [/N] [=C] [/C] [N] [Branch2] [Ring2] [C] [C] [=C]
[Branch1] [C] [F] [C] [=C] [C] [=Branch1] [C] [=O] [C] [Branch1]
[=Branch1] [C] [=Branch1] [C] [=O] [O] [=C] [N] [C] [Ring1]
[#Branch2] [=C] [Ring1] [#C] [O] [C] [C@@H1] [Ring1] [=Branch1]
[C] [C] [C] [Ring2] [Ring1] [Branch2] [Branch1] [C] [C] [C] [N]
[C] [C] [C] [Ring1] [Ring1]
sentences:
- >-
[O] [=C] [C@H1] [Branch1] [C] [O] [C@@H1] [Branch1] [C] [O]
[C@H1] [Branch1] [C] [O] [C@H1] [Branch1] [C] [S] [C] [O]
- >-
[C] [C] [O] [C] [=C] [C] [=C] [C] [=C] [Ring1] [=Branch1] [C]
[N] [C] [C] [N] [C] [=Branch1] [C] [=O] [C] [Ring1] [#Branch1]
[C] [C] [=Branch1] [C] [=O] [N] [C] [C] [C] [C] [C] [C] [Ring1]
[=Branch1]
- >-
[C] [C] [=N] [C] [=C] [N] [Ring1] [Branch1] [C] [C] [N] [C] [C]
[O] [C] [C] [Ring1] [=Branch1]
- source_sentence: >-
[C] [C] [=C] [C] [=C] [Branch2] [Ring2] [S] [C] [C] [N] [C]
[=Branch1] [C] [=O] [C] [=C] [N] [Branch1] [C] [C] [C] [=C] [C]
[=C] [Branch2] [Ring1] [Ring1] [S] [=Branch1] [C] [=O] [=Branch1]
[C] [=O] [N] [C] [C] [C] [Branch1] [C] [C] [C] [C] [Ring1]
[#Branch1] [C] [=C] [Ring1] [S] [C] [Ring2] [Ring1] [Branch1] [=O]
[C] [=C] [Ring2] [Ring1] [P]
sentences:
- >-
[C] [N] [C] [=N] [C] [Branch2] [Branch1] [C] [S] [=Branch1] [C]
[=O] [=Branch1] [C] [=O] [N] [Branch1] [#Branch2] [C] [C] [C] [C]
[N] [C] [C] [Ring1] [=Branch1] [C] [C] [C] [=C] [C] [Branch1]
[Ring1] [C] [#N] [=C] [C] [=C] [Ring1] [Branch2] [N] [Branch1]
[#Branch2] [C] [C] [=C] [N] [=C] [N] [Ring1] [Branch1] [C] [C]
[Ring2] [Ring1] [Ring1] [=C] [Ring2] [Ring2] [Ring1]
- >-
[O] [=C] [Branch1] [C] [O] [C] [C] [C] [C] [=C] [C] [=C] [C]
[=C] [C] [=C] [C] [=C]
- >-
[C] [C] [C] [C] [C@@H1] [C] [N] [Branch2] [Ring2] [#C] [C@H1]
[Branch1] [S] [C] [C] [=C] [C] [=C] [C] [=C] [C] [=C] [C]
[Ring1] [=Branch1] [=C] [Ring1] [#Branch2] [C] [N] [C] [C] [C]
[C] [Ring1] [Branch1] [C] [N] [C] [Branch1] [C] [N] [=N] [C]
[C@@H1] [Ring1] [=Branch1] [C] [C] [=C] [C] [=C] [C] [=C] [Ring1]
[=Branch1] [C] [=Branch1] [C] [=N] [N] [Ring2] [Ring2] [=Branch1]
[C] [C] [Branch1] [C] [C] [C] [=C] [C] [=C] [Branch1] [#Branch1]
[C] [C] [Branch1] [C] [C] [C] [C] [=C] [Ring1] [#Branch2]
model-index:
- name: SentenceTransformer
results:
- task:
type: semantic-similarity
name: Semantic Similarity
dataset:
name: combined test
type: combined-test
metrics:
- type: pearson_cosine
value: 0.960544
name: Pearson Cosine
- type: spearman_cosine
value: 0.951972
name: Spearman Cosine
- type: pearson_manhattan
value: 0.878769
name: Pearson Manhattan
- type: spearman_manhattan
value: 0.85873
name: Spearman Manhattan
- type: pearson_euclidean
value: 0.881126
name: Pearson Euclidean
- type: spearman_euclidean
value: 0.86117
name: Spearman Euclidean
- type: pearson_dot
value: 0.841371
name: Pearson Dot
- type: spearman_dot
value: 0.842071
name: Spearman Dot
- type: pearson_max
value: 0.960544
name: Pearson Max
- type: spearman_max
value: 0.951972
name: Spearman Max
base_model: gbyuvd/chemselfies-base-bertmlm
base_model_relation: finetune
license: cc-by-nc-sa-4.0
---
# ChemFIE-BED (ChemSELFIES Embedding)
ChemFIE-BED is a [sentence-transformers](https://www.SBERT.net) based on [gbyuvd/chemselfies-base-bertmlm](https://huggingface.co/gbyuvd/chemselfies-base-bertmlm) fine-tuned on around (for now) 2 million pairs of valid molecules' SELFIES (Krenn et al. 2020) taken from COCONUTDB (Sorokina et al. 2021) and ChemBL34 [(Zdrazil et al. 2023)](https://ftp.ebi.ac.uk/pub/databases/chembl/ChEMBLdb/latest/). It maps compounds' *Self-Referencing Embedded Strings* (SELFIES) into a 320-dimensional dense vector space, potentially can be used for chemical similarity, similarity search, classification, clustering, and more.
Although there is more data for the model to train on, the test metrics on unseen data of combined natural products and bioactives are already sufficient for now.
This model is the full implementation of [Tom Aarsen](https://huggingface.co/tomaarsen)'s [suggestions](https://huggingface.co/gbyuvd/ChemEmbed-v01/discussions/1) on previous [prototype model](https://huggingface.co/gbyuvd/ChemEmbed-v01), now using my own pre-trained BERT and Matryoshka embeddings. For the latter, the model uses 320, 160, and 80 dimension that you can truncate depending on your needs.
For more informations:
- On SELFIES:
- [blogpost](https://aspuru.substack.com/p/molecular-graph-representations-and) or check out [their github.](https://github.com/aspuru-guzik-group/selfies)
- On Sentence Transformer:
- [blogpost](https://huggingface.co/blog/train-sentence-transformers)
- On Matryoshka embedding model:
- [blogpost](https://huggingface.co/blog/matryoshka)

[](https://ko-fi.com/O4O710GFBZ)
## Model Details
### Model Description
- **Model Type:** Sentence Transformer
- **Base model:** [gbyuvd/chemselfies-base-bertmlm](https://huggingface.co/gbyuvd/chemselfies-base-bertmlm) <!-- at revision 082d953770b1f7a102912c200877f99b0fb947f0 -->
- **Maximum Sequence Length:** 512 tokens
- **Output Dimensionality:** 320 tokens
- **Similarity Function:** Cosine Similarity
- **Pooling:** Mean pooling
- **Training Dataset:** SELFIES pairs generated from COCONUTDB and ChemBL34
- **Language:** SELFIES
- **License:** CC-BY-NC-SA 4.0
### Full Model Architecture
```
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 320, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': False})
)
```
## Usage
### [Demo for Fast Molecular Similarity Search on SuperNatural3 dataset](https://github.com/gbyuvd/ChemFIE-BED-faiss-demo)
[See this JupyterNotebook demo](https://github.com/gbyuvd/ChemFIE-BED-faiss-demo) for an example of using the above model to perform fast searches for structurally similar compounds within a pre-embedded SELFIES-converted SuperNatural3 dataset (Gallo et al. 2023) (~1 million molecules) using Meta's FAISS.
### Direct Usage (Sentence Transformers)
First install the Sentence Transformers library:
```bash
pip install -U sentence-transformers
```
Then you can load this model and run inference.
```python
from sentence_transformers import SentenceTransformer
# Specify preffered dimensions
# 320, 160, or 80
dimensions = 320
# Download the model from the 🤗 Hub
model = SentenceTransformer("gbyuvd/chembed-chemselfies-bed", truncate_dim=dimensions)
# Run inference
sentences = [
'[C] [C] [=C] [C] [=C] [Branch2] [Ring2] [S] [C] [C] [N] [C] [=Branch1] [C] [=O] [C] [=C] [N] [Branch1] [C] [C] [C] [=C] [C] [=C] [Branch2] [Ring1] [Ring1] [S] [=Branch1] [C] [=O] [=Branch1] [C] [=O] [N] [C] [C] [C] [Branch1] [C] [C] [C] [C] [Ring1] [#Branch1] [C] [=C] [Ring1] [S] [C] [Ring2] [Ring1] [Branch1] [=O] [C] [=C] [Ring2] [Ring1] [P]',
'[O] [=C] [Branch1] [C] [O] [C] [C] [C] [C] [=C] [C] [=C] [C] [=C] [C] [=C] [C] [=C]',
'[C] [N] [C] [=N] [C] [Branch2] [Branch1] [C] [S] [=Branch1] [C] [=O] [=Branch1] [C] [=O] [N] [Branch1] [#Branch2] [C] [C] [C] [C] [N] [C] [C] [Ring1] [=Branch1] [C] [C] [C] [=C] [C] [Branch1] [Ring1] [C] [#N] [=C] [C] [=C] [Ring1] [Branch2] [N] [Branch1] [#Branch2] [C] [C] [=C] [N] [=C] [N] [Ring1] [Branch1] [C] [C] [Ring2] [Ring1] [Ring1] [=C] [Ring2] [Ring2] [Ring1]',
]
"""
0: CHEMBL1885710
1: CID78383937
2: CHEMBL234161
"""
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 320]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
```
## Dataset
| Dataset | Reference | Total Number of Pairs |
| :---------------- | :----------------------------------------------------------------------------------- | :-------------------- |
| COCONUTDB | [(Sorokina et al. 2021)](https://coconut.naturalproducts.net/) | 1,183,186 |
| ChemBL34 (Part I) | [(Zdrazil et al. 2023)](https://ftp.ebi.ac.uk/pub/databases/chembl/ChEMBLdb/latest/) | 1,064,858 |
### Data Preparation and Labeling
The dataset was prepared using various methods to create informative molecule pairs and labels for training a SELFIES-based sentence transformer.
The process involved the following steps:
1. **Data Collection**: Raw data was gathered from COCONUTDB and ChemBL34.
2. **Data Preprocessing**:
- Internal duplicates were removed.
- Molecules were converted to SELFIES representation.
- Molecules were filtered to ensure token length ≤ 510 (512 - 2 special tokens)
- SELFIES were converted back to SMILES.
3. **Data Merging**:
- The processed datasets were merged into a combined dataset.
- Duplicates were removed again.
4. **Tokenization and Encoding**:
- A custom tokenizer was trained on the SELFIES representations.
- SELFIES were encoded into numerical vectors.
5. **Complexity Score Calculation**:
- A ratio was calculated for each molecule: sum of encoded IDs / length of SELFIES.
- This ratio serves as a simple complexity score (similar to what was done in the base model)
6. **Binning**:
- The complexity scores were log-transformed to reduce skewness.
- Sturges' formula was used to determine the optimal number of bins.
- Molecules were assigned to bins based on their log-transformed complexity scores.
7. **Pair Generation**:
- A target size for each bin was calculated based on the average bin size.
- For in-strata pairs:
- Molecules from the same bin were paired.
- Bins larger than the target size were undersampled.
- Bins smaller than the target size were oversampled.
- For inter-strata pairs:
- Pairs were created between bins with an absolute difference > 3.
- The pairing process aimed to balance the distribution across complexity levels.
- Empty subsets were handled to ensure robust processing.
8. **Similarity Labeling**:
- MACCS fingerprints were generated for each molecule using RDKit.
- Cosine similarity between the MACCS fingerprints was calculated using CuPy for GPU acceleration.
- Error handling was implemented for cases where molecules couldn't be processed.
- The labels were resampled to ensure a balanced range of examples ([0,1])
- The similarity scores were rounded to two decimal places for training.
9. **Splitting**:
- The dataset was split into 80% for training, 10% for validation, and 10% for testing.
- For the Natural Products set (NP), the test set is labeled "NP-iso-base" because the SMILES strings were not canonicalized (isomeric forms were retained).
- The test set from ChemBL34 was then combined with the NP test set, and this combined set is referred to as "combined."
This methodology aims to provide a diverse set of molecule pairs with labels indicating structural similarity. The combination of complexity binning, balanced inter- and intra-strata sampling, and MACCS fingerprint similarity labeling is intended to capture a range of molecular complexities while providing chemically relevant labels for model training.
## Evaluation
### Metrics
#### Semantic Similarity
* Dataset: `combined-test`
* Number of test pairs: 898,980
* Evaluated with [<code>EmbeddingSimilarityEvaluator</code>](https://sbert.net/docs/package_reference/sentence_transformer/evaluation.html#sentence_transformers.evaluation.EmbeddingSimilarityEvaluator)
| Metric | Value |
|:--------------------|:-----------|
| pearson_cosine | 0.9605 |
| **spearman_cosine** | **0.9520** |
| pearson_manhattan | 0.8788 |
| spearman_manhattan | 0.8587 |
| pearson_euclidean | 0.8802 |
| spearman_euclidean | 0.8612 |
| pearson_dot | 0.8414 |
| spearman_dot | 0.8421 |
| pearson_max | 0.9605 |
| spearman_max | 0.9520 |
### Recommendations
To fully utilize the model capabitilities on a large dataset for similarity search, I'd recommend using Meta's [FAISS](https://github.com/facebookresearch/faiss) for rapid results or any of your preferred document retrieval framework.
## Training Details
### Training Hyperparameters
- `optimizer` : AdamW
- `eval_strategy`: epoch
- `per_device_train_batch_size`: 64
- `per_device_eval_batch_size`: 32
- `weight_decay`: 0.01
- `num_train_epochs`: 1
- `warmup_ratio`: 0.1
- `dataloader_num_workers`: 8
* Loss: [<code>MatryoshkaLoss</code>](https://sbert.net/docs/package_reference/sentence_transformer/losses.html#matryoshkaloss) with these parameters:
```json
{
"loss": "CosineSimilarityLoss",
"matryoshka_dims": [
320,
160,
80
],
"matryoshka_weights": [
1,
1,
1
],
"n_dims_per_step": -1
}
```
### Training Logs
#### Natural Products
| Epoch | Step | Training Loss | loss | NPiso-base-test_spearman_cosine |
|:------:|:-----:|:-------------:|:------:|:-------------------------------:|
| 0.2771 | 4099 | 0.0243 | - | - |
| 0.5543 | 8198 | 0.0099 | - | - |
| 0.8314 | 12297 | 0.0083 | - | - |
| 1.0 | 14790 | - | 0.0074 | 0.9548 |
#### Combined I
| Epoch | Step | Training Loss | loss | All-base-test_spearman_cosine |
|:------:|:-----:|:-------------:|:------:|:-----------------------------:|
| 0.2737 | 4099 | 0.0111 | - | - |
| 0.5474 | 8198 | 0.0086 | - | - |
| 0.8212 | 12297 | 0.0077 | - | - |
| 1.0 | 14975 | - | 0.0072 | 0.9516 |
## Testing The Generated Embedding to Find Similar Molecules
### Using Cosine Similarity
#### Single Input
Using Varenicline (CID5310966), a nAChR α4β2 partial agonist, as the query molecule, I conducted a similarity search to find structurally related compounds. The search utilized Varenicline's canonical SMILES representation (though isomeric SMILES could also be used) as the input.
I employed FAISS (Facebook AI Similarity Search) to identify the top 10 most similar molecules from a set of 1 million compounds in the Supernatural3 database [(Gallo et al. 2023)](https://doi.org/10.1093%2Fnar%2Fgkac1008). The search was based on cosine similarities of pre-embedded SELFIES representations of these molecules.
The embeddings for the Supernatural3 database subset were generated using my laptop's NVIDIA GeForce 930M GPU, with a batch size of 64, so do for search.
Varenicline:

top 10 (returned in 7.7s with visualization):

| Rank | Cosine Similarity (%) | MW (Da) | Name | SMILES |
| :--: | :-------------------: | :-----: | :-----------: | ---------------------------------------------------------- |
| 1 | 92.23 | 212.13 | SN0325329 | c1cc2c3c(c[nH]c3c1)CC1NCCCC21 |
| 2 | 91.39 | 267.17 | SN0232374 | c1ccc2c3c([nH]c2c1)C1CCN2CCCC2N1CC3 |
| 3 | 91.36 | 212.13 | SN0325329-01 | c1cc2c3c(c[nH]c3c1)C[[C@H](mailto:C@H)]1NCCC[C@H]21 |
| 4 | 91.35 | 226.15 | SN0275712-02 | c1ccc2c3c([nH]c2c1)[[C@H](mailto:C@H)]1CCCCN1CC3 |
| 5 | 91.33 | 226.15 | SN0275712 | c1ccc2c3c([nH]c2c1)C1CCCCN1CC3 |
| 6 | 91.27 | 184.10 | SN0027447 | CC1=C2N=c3ccccc3=C2CCN1 |
| 7 | 90.93 | 226.15 | SN0275712-01 | c1ccc2c3c([nH]c2c1)[C@@H]1CCCCN1CC3 |
| 8 | 90.66 | 240.16 | SN0048348 | c1ccc2c(c1)N1CCC[N+]=C1C21CCCCC1 |
| 9 | 90.59 | 267.17 | 'SN0232374-01 | c1ccc2c3c([nH]c2c1)[[C@H](mailto:C@H)]1CCN2CCC[C@@H]2N1CC3 |
| 10 | 90.57 | 267.17 | 'SN0232374-02 | c1ccc2c3c([nH]c2c1)[C@@H]1CCN2CCC[C@@H]2N1CC3 |
#### Multiple Inputs by Averaging Embeddings
You can take multiple inputs then average their embeddings to find those most similar.
For example, using 3 known nAChR α4β2 partial agonists: varenicline, SW4 (Zhang et al. 2012), and cytisine (using their isomeric SMILES)

then query similars based on the average embeddings (returned in 3.5s):

| Rank | Cosine Similarity (%) | MW (Da) | Name | SMILES |
| :--: | :-------------------: | :-----: | :----------: | --------------------------------------------------------------- |
| 1 | 89.37 | 219.10 | SN0171732 | CN1C(=O)c2cccnc2OC2CNCC21 |
| 2 | 89.07 | 219.10 | SN0171732-01 | CN1C(=O)c2cccnc2O[[C@H](mailto:C@H)]2CNC[C@H]21 |
| 3 | 88.75 | 218.14 | SN0181055-02 | CCN1C[C@@H]2C[C@@H](C1)c1cccc(=O)n1C2 |
| 4 | 88.74 | 226.15 | SN0157407-02 | Cc1ccc2c(c1)c1c3n2CCN[[C@H](mailto:C@H)]3CCC1 |
| 5 | 88.65 | 218.14 | SN0181055-01 | CCN1C[[C@H](mailto:C@H)]2C[C@@H](C1)c1cccc(=O)n1C2 |
| 6 | 88.62 | 226.15 | SN0157407-01 | Cc1ccc2c(c1)c1c3n2CCN[C@@H]3CCC1 |
| 7 | 88.51 | 218.14 | SN0181055-03 | CCN1C[C@@H]2C[[C@H](mailto:C@H)](C1)c1cccc(=O)n1C2 |
| 8 | 88.50 | 294.17 | SN0126266-01 | C/C=C1/CN2CC[C@]34C=C(CO)[C@@H]1C[C@]23Nc1ccccc14 |
| 9 | 88.35 | 294.17 | SN0126266-04 | C/C=C1\\CN2CC[C@]34C=C(CO)[[C@H](mailto:C@H)]1C[C@]23Nc1ccccc14 |
| 10 | 88.19 | 242.14 | SN0095524-01 | OCc1ccc2c(c1)c1c3n2CCN[C@@H]3CCC1 |
### Using L2 Distance
(WIP)
## Validation by Docking-based Virtual Screening
Validation by Docking-based Virtual Screening (DBVS) is finished, showing promising hit rates — ranging from 26% to 58% within the top 100 similar compounds from SuperNatural3 using the averaged embeddings of nAChR α4β2 partial agonists, depending on the threshold applied.
However, some of the methods used are adapted from my undergraduate thesis, which is still in progress and pending publication.
Detailed results and methodologies will be fully disclosed after the thesis is published.
## Testing Generated Embeddings' Clusters
The plot below shows how the model's embeddings (at this stage) cluster different classes of compounds, compared to using MACCS fingerprints.
Using perplexity of 20 over 5500 iterations.
2D:


For a more simple separation between two classes, for example active natural nAChR-α4β2 agonists vs anticoagulants (perplexity = 5):

### Framework Versions
- Python: 3.9.13
- Sentence Transformers: 3.0.1
- Transformers: 4.42.4
- PyTorch: 2.3.1+cu121
- Accelerate: 0.33.0
- Datasets: 2.20.0
- Tokenizers: 0.19.1
- RDKit: 2024.3.3
## Citation
### BibTeX
#### ChemFIE-Base
```bibtex
@software{chemfie_basebertmlm,
author = {GP Bayu},
title = {{ChemFIE Base}: Pretraining A Lightweight BERT-like model on Molecular SELFIES},
url = {https://huggingface.co/gbyuvd/chemselfies-base-bertmlm},
version = {1.0},
year = {2024},
}
```
#### Sentence Transformers
```bibtex
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
```
#### MatryoshkaLoss
```bibtex
@misc{kusupati2024matryoshka,
title={Matryoshka Representation Learning},
author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
year={2024},
eprint={2205.13147},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
```
#### COCONUTDB
```bibtex
@article{sorokina2021coconut,
title={COCONUT online: Collection of Open Natural Products database},
author={Sorokina, Maria and Merseburger, Peter and Rajan, Kohulan and Yirik, Mehmet Aziz and Steinbeck, Christoph},
journal={Journal of Cheminformatics},
volume={13},
number={1},
pages={2},
year={2021},
doi={10.1186/s13321-020-00478-9}
}
```
#### ChemBL34
```bibtex
@article{zdrazil2023chembl,
title={The ChEMBL Database in 2023: a drug discovery platform spanning multiple bioactivity data types and time periods},
author={Zdrazil, Barbara and Felix, Eloy and Hunter, Fiona and Manners, Emma J and Blackshaw, James and Corbett, Sybilla and de Veij, Marleen and Ioannidis, Harris and Lopez, David Mendez and Mosquera, Juan F and Magarinos, Maria Paula and Bosc, Nicolas and Arcila, Ricardo and Kizil{\"o}ren, Tevfik and Gaulton, Anna and Bento, A Patr{\'i}cia and Adasme, Melissa F and Monecke, Peter and Landrum, Gregory A and Leach, Andrew R},
journal={Nucleic Acids Research},
year={2023},
volume={gkad1004},
doi={10.1093/nar/gkad1004}
}
@misc{chembl34,
title={ChemBL34},
year={2023},
doi={10.6019/CHEMBL.database.34}
}
```
#### SuperNatural3
```bibtex
@article{Gallo2023,
author = {Gallo, K and Kemmler, E and Goede, A and Becker, F and Dunkel, M and Preissner, R and Banerjee, P},
title = {{SuperNatural 3.0-a database of natural products and natural product-based derivatives}},
journal = {Nucleic Acids Research},
year = {2023},
month = jan,
day = {6},
volume = {51},
number = {D1},
pages = {D654-D659},
doi = {10.1093/nar/gkac1008}
}
```
### Partial Agonism of SW4
```bibtex
@article{Zhang2012,
author = {Zhang, H. and Eaton, J. B. and Yu, L. and Nys, M. and Mazzolari, A. and Van Elk, R. and Smit, A. B. and Alexandrov, V. and Hanania, T. and Sabath, E. and Fedolak, A. and Brunner, D. and Lukas, R. J. and Vistoli, G. and Ulens, C. and Kozikowski, A. P.},
title = {Insights Into the Structural Determinants Required for High-Affinity Binding of Chiral Cyclopropane-Containing Ligands to Alpha4Beta2-Nicotinic Acetylcholine Receptors: An Integrated Approach to Behaviorally Active Nicotinic Ligands},
journal = {Journal of Medicinal Chemistry},
year = {2012},
volume = {55},
pages = {8028},
doi = {10.1021/jm3008739}
}
```
## Contact & Support My Work
G Bayu (gbyuvd@proton.me)
This project has been quiet a journey for me, I’ve dedicated hours on this and I would like to improve myself, this model, and future projects. However, financial and computational constraints can be challenging.
If you find my work valuable and would like to support my journey, please consider supporting me [here](https://ko-fi.com/gbyuvd). Your support will help me cover costs for computational resources, data acquisition, and further development of this project. Any amount, big or small, is greatly appreciated and will enable me to continue learning and explore more.
Thank you for checking out this model, I am more than happy to receive any feedback, so that I can improve myself and the future model/projects I will be working on. |