Tokenizer for language models to operate with molecular inputs
The tokenizer transforms molecular inputs into a new representation using a molecular vocabulary and syntax, addressing the ambiguity in language models, thereby improving the language model's performance in chemical tasks with enhanced accuracy and efficiency.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- DOW GLOBAL TECHNOLOGIES LLC
- Filing Date
- 2024-10-18
- Publication Date
- 2026-04-23
AI Technical Summary
Current language models struggle to effectively process molecular inputs due to ambiguity between molecular representations and natural language semantics, leading to issues like hallucination and disruption of the strict logical structure in chemical molecule representation, which affects tasks such as property prediction and molecule generation.
A tokenizer is developed that utilizes a molecular vocabulary and syntax, transforming molecule inputs into a new representation by incorporating atomic environments, explicit atomic positions, and forward-connecting positions, enabling language models to understand molecule semantics for chemical tasks.
The tokenizer enhances the language model's competence in chemical tasks like property prediction and molecule generation, achieving high accuracy and efficiency in training and test results, particularly with GCN1 and GCN2 encoding, outperforming existing methods like SMILES and InChI.
Smart Images

Figure PCTCN2024125675-FTAPPB-I100001 
Figure 00000028_0000 
Figure 00000029_0000
Abstract
Description
TOKENIZER FOR LANGUAGE MODELS TO OPERATE WITH MOLECULAR INPUTSTechnical Field
[0001] The present disclosure relates to a tokenizer for language models that can allow the language models to operate with molecular inputs analogously to operating with textual inputs. Such techniques can be useful to perform property prediction for a molecule not in a molecular database or to identify molecules having targeted properties.Background
[0002] Artificial neural networks (ANNs) are networks that can process information by modeling a network of neurons, such as neurons in a human brain, to process information (e.g., stimuli) that has been sensed in a particular environment. Similar to a human brain, neural networks typically include a multiple neuron topology, which can be referred to as artificial neurons or units. An ANN operation refers to an operation that processes inputs using units to perform a given task. The ANN operation may involve applying various machine learning algorithms to process the inputs. Example tasks that can be processed by performing ANN operations can include machine vision, speech recognition, machine translation, social network filtering, and medical diagnosis, among others. An ANN can perform machine learning tasks by performing a weighted combination of inputs (either from the network input or a previous layer) at each unit to generate an output. The probability weight associations can be provided by a plurality of units that comprise the ANN. The units together with weights, biases, embeddings, and / or activation functions can be used to generate an output of the ANN based on the input to the ANN. Units of the ANN can be grouped to form layers of the ANN. The ANN can implement or represent an algorithm consisting of a series of connected layers that process signals based on outputs from other ones of the series of connected layers.
[0003] A language model is a probabilistic model of a natural language, such as English, which can be used for tasks such as speech recognition, machine translation, natural language generation, optical character recognition, handwriting recognition, grammar induction, and information retrieval. Some language models take the form of recurrent neural networks (RNNs) , long short-term memory (LSTM) networks, and large language models (LLMs) . An RNN is a class of ANN for sequential data processing that, unlike feedforward neural networks, processes across multiple time steps rather than in a single pass. The RNN maintains a recurrent unit, which is essentially a form of memory with a value that is updated at each time step based on the current input and the previous state. This feedback loop allows the network to learn from previous inputs and incorporate that knowledge into current processing. RNNs can have a vanishing gradient problem, which can inhibit long-range dependencies. LSTM networks help to address this issue with RNNs via an improved insensitivity to gap length versus other RNNs. LSTM networks can include cells that remember values over time intervals, input gates, output gates, and forget gates to selectively regulate the flow of information into and out of the cells, thereby allowing the network to maintain useful long-term dependencies to make predictions. An LLM is a combination of larger datasets, feedforward neural networks, and transformers.
[0004] Machine learning and statistical analysis can be used to assist in designing chemicals and materials. Some empirical modeling methods use training data including independent variables that describe the chemical system of interest. Examples of such variables include descriptors ( “X variables” ) and the desired attributes ( “Y variables” ) of the chemical product to be produced. Various algorithms can detect and encapsulate the patterns between X and Y variables. Model tools can be developed to enable users to test hypotheses about predicted outcomes of a new set of input variables or optimize inputs to meet a desired Y variable specification for a chemical product. One task in creating such a model for materials informatics is determining what data to use as X data. In order for a machine learning algorithm to detect patterns between X and Y, the X data variables should contain relevant information about the system and how it behaves.
[0005] Summary of the Disclosure
[0006] The present disclosure relates to a tokenizer for language models that can allow the language models to operate with molecular inputs analogously to operating with textual inputs. The tokenizer can originate as a tokenizer of a language model. Because machine learning models process numbers rather than text, the text must be converted to numbers. Once a vocabulary exists, integer indices can be assigned to each vocabulary entry and an embedding can be associated with the integer index. The embedding is a representation of a word. An example of an algorithm for such embedding is byte pair encoding (BPE) . In general, it is desirable to use as few tokens as possible for a word. After a tokenizer is trained, it can tokenize text as long as the text does not contain characters not appearing in the initial dataset.
[0007] The present disclosure provides a molecular vocabulary that can be added to the tokenizer. The molecular vocabulary can include character strings as words representing atomic environments, explicit atomic positions, and forward-connecting positions based on a molecular database that includes data describing molecules and their properties. A molecular syntax can be defined for the tokenizer that represents each of the molecules as a respective molecular sentence made up of tuples corresponding to a quantity of atoms in a respective molecule and including words from the molecular vocabulary. The molecular syntax organizes the sentence of a molecule by words of atomic environment and their connected positions. As vocabulary and syntax are to natural language, the molecular vocabulary and syntax are to chemistry. The molecular vocabulary can be equated to morphemes in linguistics.
[0008] The present disclosure relates to a tokenizer that can tokenize the molecules from the database according to the molecular vocabulary and the molecular syntax. The language model can be trained to perform property prediction for molecules or to identify molecules having targeted properties using the tokenized molecules and their properties. The trained language model can perform property prediction for a molecule not in the molecular database or identify molecules having the targeted properties.
[0009] The above summary of the present disclosure is not intended to describe each disclosed embodiment or every implementation of the present disclosure. The description that follows more particularly exemplifies illustrative embodiments. In several places throughout the application, guidance is provided through lists of examples, which examples can be used in various combinations. In each instance, the recited list serves only as a representative group and should not be interpreted as an exclusive list.Brief Description of the Drawings
[0010] Figure 1 is a method flow diagram associated with a tokenizer for allowing a language model to operate with molecular inputs.
[0011] Figure 2 is another method flow diagram associated with a tokenizer for allowing a language model to operate with molecular inputs.
[0012] Figure 3 is a table illustrating an example of a molecular vocabulary.
[0013] Figure 4 is a method flow diagram for representing molecular inputs to a language model according to a molecular vocabulary and syntax.
[0014] Figure 5 is a flow diagram illustrating the conversion of a molecular input to a graph structure and first graph convolution network encoding.
[0015] Figure 6 illustrates a second graph convolution network encoding following the molecular input of Figure 5.
[0016] Figure 7 is a flow diagram illustrating the molecular input from Figure 5 and Figure 6 represented with a molecular vocabulary and molecular syntax.
[0017] Figure 8A is a graph illustrating a training loss and accuracy of training and testing of generative pretraining transformer (GPT) -2 by international chemical identifier.
[0018] Figure 8B is a graph illustrating a training loss and accuracy of training and testing of GPT-2 by small molecules input line entry system.
[0019] Figure 8C is a graph illustrating a training loss and accuracy of training and testing of GPT-2 by graph convolution network (GCN) .
[0020] Figure 8D is a graph illustrating a training loss and accuracy of training and testing of GPT-2 by GCN.
[0021] Figure 9 is an example machine within which a set of instructions, for causing the machine to perform various methodologies discussed herein, can be executed.Detailed Description
[0022] A foundational model is a machine learning model that is trained on broad data such that it can be applied across a wide range of use cases. An LLM is a type of language model with an ability to achieve general purpose language understanding and generation. LLMs acquire these abilities by using massive amounts of data to learn many parameters (e.g., hundreds of millions to hundreds of billions) during training and consuming large computational resources during training and operation. LLMs can be untrained or pretrained. The untrained LLMs, often with hundreds of millions of parameters for trials, can be classified into decoder-only (e.g., generative pretraining transformer “GPT” ) , encoder-only (e.g., bidirectional encoder representation from transformers “BERT” ) , and encoder-decoder architecture (e.g., text-to-text transfer transformer “T5” , bidirectional and auto-regressive transformer “BART” , etc. ) , among others. The pretrained models, often with hundreds of billions of parameters for natural language processing (NLP) tasks, include examples like GPT-4, large language model Meta AI (LLaMA) , and pathways language model (PaLM) . LLMs have given foundational models a broad audience. While there is interest, applications in chemical sciences have been limited.
[0023] A transformer is a deep learning architecture based on the multi-head attention mechanism. Text is converted to representations called tokens and each token is converted into a vector according to an embedding table. At each layer, each token is contextualized within the scope of the context window with other tokens via a parallel multi-head attention mechanism allowing the signal for key tokens to be amplified and less important tokens to be diminished. Transformers have no recurrent units and thus use less training time than RNNs and / or LSTMs. The parallel computation of the transformer architecture has made it particularly efficient to pretrain with a large size text corpus. The approach of pretraining and finetuning is attractive for chemistry tasks because enormous amounts of molecular structures are already known, but the availability of their property data is much more limited. It is also expensive and time consuming (even by computational chemistry) to generate property data from experiments in many cases. LLMs have demonstrated surprising generalizability to learn the complex distribution of text corpus in the pretraining stage via self-supervised learning.
[0024] When LLMs are pretrained, the text corpus input is first processed by a tokenizer that converts the sequential text into numerical tokens. Tokens represent the words or morphemes, the most basic element of grammatical hierarchy in linguistics. The attention mechanism in LLMs learns the weights connecting tokens in a context of input sequence. Subsequently, the connectivity weights hierarchically embed the semantical information of words, sentences, paragraphs, and documents, depending on the length of in-context window and the architecture of LLMs. Tokenizers of LLMs may be based on a word dictionary and enhanced by algorithms like BPE to solve the out-of-vocabulary problem. However, tokenizers are designed for processing natural languages not chemistry. Currently, the molecule inputs into LLMs are mostly in string representations like small molecules input line entry system (SMILES) . Using the tokenizer of an LLM for SMILES would likely cause ambiguity between molecular representations and natural language semantics. This would likely exacerbate the hallucination problems inherent in natural language tasks and disrupt the strict logical structure in chemical molecule representation. Such approaches have been proved unsatisfactory in chemical tasks like property prediction and molecule generation, even when the LLMs are pretrained only with a molecular database.
[0025] Different from the text corpus that inherently recognized as a representation conforming to syntactic rules of natural languages, SMILES is not recognized as a valid molecule representation. SMILES is known for syntactic problems like paired paratheses and semantic problems like valence constraints. To solve the validity problem, self-referencing embedded strings (SELFIES) was proposed and international chemical identifier (InChI) is another alternative string representation. However, after tokenization, both SELFIES and InChI are chopped into characters, meaning that the vocabulary for these molecule representations are only at character level. As a contrast, the size of vocabularies in current LLMs ranges from dozens of thousands to hundreds of thousands. If atoms are viewed as characters and molecules are viewed as sentences, then the molecular vocabulary is the key to understanding chemical language. Like sentences, molecules should be understood in terms of words, not characters or atoms. Without a vocabulary of the right size and sufficient expressivity to represent and tokenize the molecules, LLMs will not be able to understand molecular structures.
[0026] One of ordinary skill in the art will appreciate that molecular properties should be predicted by fragments rather than atoms in a molecule. Some previous approaches proposed database “fingerprints” to encode molecular fragments, such as molecular access system (MACCS) , PubChem fingerprint, BCI fingerprints, typed-graph distances (TGD) and typed-graph triangles (TGT) fingerprints, etc. Most of the molecular fragments are predefined based on a priori knowledge in specific domains like drug discovery. Later, the fragments can be generated by algorithms like the breaking of retrosynthetically interesting chemical substructures (BRICS) based on the functional groups from retrosynthesis study.
[0027] The molecular fragments can be viewed as words to constitute the vocabulary for language models. For example, vocabulary generated by BRICS has been used in motif-based graph self-supervised learning (MGSSL) , hierarchical molecular graph self-supervised learning (HiMol) , tree-based SMILES (t-SMILES) , and universal SMILES-graph representation learning (UniMAP) . However, the vocabulary generated in this way is domain dependent. Domain-agnostic vocabulary is also explored by applying a BPE algorithm. It can be done on molecular string representation like SMILES pair encoding (SMILES PE) or molecular graph representation like Graph Piece. The latter was further improved by mined connection-aware motifs (MiCaM) . However, SMILES PE is limited to the intrinsic validity problem, while Graph Piece and MiCaM are limited to graph neural networks (GNN) , which are not language models. Even though GNNs have achieved success in property prediction tasks, its over smooth problem may provide less than ideal results.
[0028] At least one embodiment described herein addresses the above and other deficiencies by providing a tokenizer built upon a vocabulary that is informed by molecular substructures (i.e., fragments, motifs, scaffolds etc. ) , and is domain agnostic. Meanwhile, the tokenizer can transform the molecule input into a new representation built on the vocabulary by a valid syntax retaining the information of molecular structures. The tokenizer enables language models to understand molecule semantics for a broad range of chemical tasks like molecule generation and property prediction.
[0029] As used herein, the singular forms “a” , “an” , and “the” include singular and plural referents unless the content clearly dictates otherwise. Furthermore, the word “may” is used throughout this application in a permissive sense (i.e., having the potential to, being able to) , not in a mandatory sense (i.e., must) . The term “include, ” and derivations thereof, mean “including, but not limited to. ” The term “coupled” means directly or indirectly connected and, unless stated otherwise, can include a wireless connection.
[0030] As will be appreciated, elements shown in the various embodiments herein can be added, exchanged, and / or eliminated so as to provide a number of additional embodiments. In addition, as will be appreciated, the proportion and the relative scale of the elements provided in the figures are intended to illustrate certain embodiments and should not be taken in a limiting sense.
[0031] Figure 1 is a method flow diagram associated with a tokenizer for allowing a language model to operate with molecular inputs. The method may be performed, in some examples, using a computing system such as those described with respect to Figure 9. The method can be performed by processing logic that can include hardware (e.g., processing device, circuitry, dedicated logic, programmable logic, microcode, hardware of a device, integrated circuit, etc. ) , software (e.g., instructions run or executed on a processing device) , or a combination thereof. Although shown in a particular sequence or order, unless otherwise specified, the order of the processes can be modified. Thus, the illustrated embodiments should be understood only as examples, and the illustrated processes can be performed in a different order, and some processes can be performed in parallel. Additionally, one or more processes can be omitted in various embodiments. Thus, not all processes are required in every embodiment. Other process flows are possible.
[0032] As illustrated at 102, the method can include adding a molecular vocabulary to a tokenizer of a language model. The molecular vocabulary can include “words” represented as character strings. The words represent atomic environments, explicit atomic positions (e.g., leading, following, preceding, etc. ) , and forward-connecting positions based on a molecular database (e.g., PubChem) that includes data describing molecules and their properties. The words of the molecular vocabulary can be equated to morphemes in linguistics. Although not specifically illustrated in Figure 1, in some embodiments the method can include creating the words representing atomic environments by representing each non-hydrogen atom of a particular molecule with graph convolution network (GCN) encoding. The atomic environment can be represented as a short length of strings obtained through GCN encoding. GCN encoding can add the neighborhood atomic environment to a preceding atom stepwise atom-by-atom. A specific example of such encoding is illustrated and described with respect to Figure 6.
[0033] The GCN encoding of a respective non-hydrogen atom can include its respective element symbol, a first number identifying its respective quantity of bonds, excluding bonds with hydrogen, and a second number identifying its respective quantity of bonds with hydrogen atoms. For example, GCN0 refers to the atomic environment (e.g., the number of non-hydrogen atoms and the number of hydrogen atoms connected to a single given atom at the initial state) . It consists of the element symbol combined with the number of connecting bonds (excluding bonds with hydrogen and not distinguishing between single and double bonds) followed by the number of hydrogen atoms. This way of encoding the atomic environment can effectively mitigate the ambiguity of bond types.
[0034] The method can further include adding a GCN encoding of each non-hydrogen atom that is immediately adjacent to the respective non-hydrogen atom to the GCN encoding of the respective non-hydrogen atom. For example, GCN1 adds the GCN0 encodings of all 1-layer atoms connected to the atom of GCN0. The method can further include adding the GCN encoding of each non-hydrogen atom that is two layers adjacent to the respective non-hydrogen atom to the GCN encoding of the respective non-hydrogen atom. For example, GCN2 adds the GCN0 encodings of all 2-layer atoms connected to the atoms of GCN1. The encoding can continue in kind until all atoms in the molecule are transversed to end with GCNx.
[0035] For some current opensource databases (e.g., PubChem) containing billions of molecular structures, the molecular vocabulary can include approximately 100 GCN0, 9,000 GCN1, and 150,000 GCN2 encodings. Constrained by the computing capability of language models, the size of vocabulary may be limited. Therefore, some embodiments use GCN0, GCN1, and GCN2 encodings to construct the molecular vocabulary. To address out-of-vocabulary problems, a BPE algorithm can be applied onto GCN1 and / or GCN2. BPE can encode strings of text into tabular form for use in downstream modeling. In short, BPE replaces pairs of bytes with a single byte as a form of compression.
[0036] The method can further include creating the words representing explicit atomic positions for each atom in a particular molecule by calculating a sequence order of the atoms within the particular molecule using a spatial algorithm. The sequence order of the atoms can be represented with a first text string indicating explicit atomic position and first sequential numbers, each first sequential number assigned to a respective atom according to the sequence. The method can further include creating the words representing explicit atomic positions for each atom in a particular molecule by including a second text string indicating forward-connecting position and second sequential numbers. Each second sequential number connects a subsequent atomic environment to a preceding atom in the sequence order of the atoms. The explicit atomic positions and the forward-connecting positions can be included in the molecular vocabulary to encode connectivity information of the atomic environment. Explicit atomic position can be generated by a sorting algorithm as a canonical order of atoms, abbreviated as POS (i) , where “i” is the sequence number equal to the number of atoms in a molecule. Forward-connecting position is the position of the preceding atom that an atomic environment is directed towards, abbreviated as CPOS (j) , where “j” is the sequence number no bigger than i, as the connection is only directed towards the preceding atom.
[0037] As illustrated at 104, the method can include defining a molecular syntax for the tokenizer that represents each of the molecules as a respective molecular sentence made up of tuples. A tuple is an ordered list of elements. A tuple having two elements is referred to as a duplet. A tuple having three elements is referred to as a triplet. The tuples correspond to a quantity of atoms in a respective molecule. The tuples include words from the molecular vocabulary. According to at least one embodiment, the tuple for a particular molecule having N-number of atoms can include a first duplet and a quantity (N-1) of triplets. The duplet can include a first word representing the explicit atomic position of a first atom of the particular molecule and a second word representing the atomic environment of the first atom. Each triplet can include a third word representing the explicit atomic position of a respective atom of the particular molecule, a fourth word representing the atomic environment of the respective atom, and a fifth word representing the forward-connecting position between the respective atom and a preceding atom in the molecular syntax.
[0038] In some embodiments, the tuples for the particular molecule further include additional duplets and triplets. A respective additional duplet includes the fifth word (defined above) and a sixth word representing a first feature connected to the preceding atom at a position indicated by a number in the fifth word. A respective additional triplet includes two fifth words and a seventh word representing a second feature connected to two preceding atoms at positions indicated by numbers in the two fifth words.
[0039] The molecular syntax to construct a valid molecule sentence with N atoms can start with one duplet followed by N-1 triplets. For example, duplet POS (1) , GCNx means atomic environment GCNx at explicit atomic position POS (1) is at the beginning of molecular sentence. Triplet POS (i) , GCNx, CPOS (j) , which means atomic environment GCNx at explicit atomic position POS (i) is connected to the preceding atomic position at POS (j) . Here, i is greater than 1 and i is greater than j. Following the canonical order of POS (i) , the triplets can be successively added until N atoms in the molecular sentence are all transversed. The beginning and the ending of the molecular sentence can be spaced by special tags, which can be part of the molecular vocabulary, as described in more detail with respect to Figure 3.
[0040] As illustrated at 106, the method can include tokenizing the molecules according to the molecular vocabulary and the molecular syntax. Before the tokenization, the molecule input should be represented by the chemical vocabulary following the molecular syntax as described above. These two steps can be incorporated into the tokenizer, which can be further incorporated into an untrained language model and / or a pretrained language model. With such a novel tokenizer, the language model is more competent for chemical tasks like property prediction and molecule generation, along with the ability of natural language comprehension. In some embodiments, tokenizing the molecules from the molecular database includes tokenizing a natural language sentence describing a particular molecule and its properties, as described in more detail with respect to Figure 5.
[0041] As illustrated at 108, the method can include training the language model to perform property prediction for molecules or to identify molecules having targeted properties using the tokenized molecules and their properties. The language model learns with the use of data inputs. Supervised learning involves training with labeled data (e.g., known molecules that have known properties) . For example, a portion of the molecular database that is not used to construct the molecular library can be used as training data for the language model. Unsupervised learning involves training without labeled data. An unsupervised learning task is one that models the underlying structure of the data without explicit labels (Y data) for each sample. Such methods can identify previously unknown patterns or features in the data. Some examples of methods for unsupervised learning include principal component analysis (PCA) , which is a dimension reduction technique that emphasizes data variance, clustering algorithms such as k-means, similarity analyses such as k-nearest neighbor, association rules mining, and anomaly detection. Semi-supervised learning involves training without labeled data, but input-label pairs can be constructed from each data point. Large scale models can be trained using self-supervised methods where the model structure identifies the learning pattern as part of the training process. As illustrated at 110, the method can include performing, by the trained language model, property prediction for a molecule not in the molecular database or identifying, by the trained language model, molecules having the targeted properties.
[0042] Figure 2 is another method flow diagram associated with a tokenizer for allowing a language model to operate with molecular inputs. The methods illustrated in Figure 1 and Figure 2 are not mutually exclusive, but are different representations of embodiments described herein with focus on different aspects. The description of Figure 2 relies on and incorporates the description of Figure 1. For example, the tokenizer for the language model, according to various embodiments, can transform a molecular input to a new representation built on the molecular vocabulary by following the molecular syntax. In contrast, natural language models do not require this extra stop of transforming or rewriting inputs. The tokenizer, as described herein, can tokenize the transformed representation of the molecular inputs based on the molecular vocabulary.
[0043] As illustrated at 212, the method can include the construction of the molecular vocabulary. The chemical vocabulary includes special tags for the beginning and ending of molecular sentences, the explicit atomic positions, the atomic environment, and the forward-connecting positions. In some embodiments, the molecular vocabulary can include characters and short length strings representing features like chiral isomerism (R / S) , cis-trans isomerism (E / Z) , dihedral angle encoding (QS) and descriptors from computational chemistry or empirical rules like total energy, free energy, atomic charge, inner atomic orbital energies, molecular (bonding) orbital energies, weak interactions, and steric effect, etc. These additional features and descriptors can be carefully segmented, encoded, and then added to the vocabulary. The special tags for the beginning and the ending of these additional features and descriptors can also be included into the molecular vocabulary.
[0044] The molecular syntax refers to the organization of the atomic environment as tuples, such as duplets and triplets. The duplet is the beginning of molecular sentence, followed by triplets that are successively added according to the sequence of atom positions. The duplet is expressed as explicit atomic position, atomic environment. The triplet is expressed as explicit atomic position, atomic environment, forward-connecting position. Additionally, the features can be organized analogously. For example, the expression for the features can include duplet (forward-connecting position, features like chiral isomerism) and triplet (forward-connecting position, features like cis-trans isomerism or dihedral angle, forward-connecting position) . A specific example is illustrated and described with respect to Figure 3.
[0045] As illustrated at 214, the method can include adding the molecular vocabulary to a language model. A non-limiting example of the language model is GPT-2 Small. GPT-2 was evaluated for ability to understand molecular structures. There are four different parameter sizes of GPT-2, including GPT-2 Small (117 million parameters) , GPT-2 Medium (345 million parameters) , GPT-2 Large (762 million parameters) , and GPT-2 XL (1.5 billion parameters) . In view of the small molecule datasets (4 elements) used in this example, GPT-2 Small was adopted. The molecular vocabulary can be added with separate token identifiers (token ID or “tokenid" ) . This process can create a specific vocabulary carrying atomic environment information that captures the molecular structural features. In some embodiments, the molecular vocabulary can be added to a pretrained large language model.
[0046] As illustrated at 216, the method can include splitting a dataset (e.g., the molecular database) into different portions for training, validating, and testing the language model having the molecular vocabulary added thereto. In some embodiments, the dataset can be split in a ratio of 8 (training) : 1 (validating) : 1 (testing) , however embodiments are not so limited. As an example, PubChem can serve as the molecular database for constructing the molecular vocabulary. 100 million small to medium-sized molecules can be utilized (containing up to 20 non-hydrogen atoms) . To constrain the scope, these molecules can be limited to those including only the elements oxygen (O) , nitrogen (N) , carbon (C) , and hydrogen (H) . Some relatively small molecules for each GCNx encoding can also be added. In one specific implementation, the dataset includes four varied sizes: 39,000 and 60,000 CH compounds, and 796,000 and 1.2 million ONCH compounds.
[0047] In computational chemistry, the Hartree-Fock (HF) method is a method of approximation for the determination of the wave function and the energy of a quantum many-body system in a stationary state. A basis set is a set of functions used to represent the electronic wave function in the HF method or density functional theory (DFT) in order to turn the partial differential equations of the model into algebraic equations more suitable for efficient implementation of a computer. Conformational searches were performed on the molecules in the molecular database using a density functional tight binding (DFTB) method employing a self-consistent charge treatment including up to third order density fluctuation terms parameterized for a number of chemical elements (DFTB3) . More specifically, a DFTB3 variant that mostly follows a global and element-specific parameters-only strategy that is parameterized to elements through radon was used. The DFTB3 variant is referred to as GFN2-xTB, which involves molecule geometries, vibrational frequencies, and non-covalent interaction energies (GFN) extended tight binding (xTB) . GFN2-xTB was followed by final optimization using DFT. The specific DFT employed was the Minnesota Functionals 2006 group of highly parameterized approximate exchange-correlation energy functionals, global hybrid functional with 54%HF exchange (M06-2X) with correlation-consistent polarized split valence double zeta basis set (cc-pVDZ) , referred to as M062X / cc-pVDZ. The calculated properties include HF energy, enthalpy change, free energy, highest occupied molecular orbital and lowest unoccupied molecular orbital (HOMO-LUMO) gap, polarity, volume, and atomic charges (for each atom) . Some results of testing are described in more detail with respect to Figures 8A-8D.
[0048] As illustrated at 218, the method can include representing a molecule input following the construction of the molecular vocabulary and defined molecular syntax. Additional detail regarding such representation is illustrated and described with respect to Figure 4. As illustrated at 220, the method can include training the language model to perform property prediction for molecules or to identify molecules having targeted properties.
[0049] Figure 3 is a table illustrating an example of a molecular vocabulary. The molecular vocabulary includes tags such as a first tag (<mol>) denoting a beginning of any molecular sentence and a second tag (< / mol>) denoting an ending of any molecular sentence. The molecular vocabular can include a third tag (<CPOS>) denoting a beginning of a first segment of any molecular sentence describing bonded atomic positions and a fourth tag (< / CPOS>) denoting an ending of the first segment. The molecular vocabulary can include a fifth tag (<EZRS>) denoting a beginning of a second segment of any molecular sentence describing cis-trans isomerism and chiral isomerism and a sixth tag (< / EZRS>) denoting an ending of the second segment. The molecular vocabulary can include a seventh tag (<QS>) denoting a beginning of a third segment of any molecular sentence describing dihedral angle and an eighth tag (< / QS>) describing an ending of the third segment.
[0050] The molecular vocabulary can also include characters representing specific encodings for features like chiral isomerism (RS) , cis-trans isomerism (EZ) , and dihedral angle (QSn) . The characters E, Z, R, S, R1, S1, R2, S2, R3, S3 represent specific cis-trans and chiral encodings within the molecule. The range Q0 through Q180 is used to encode dihedral angles, providing detailed angular information between connected atoms across the molecule. Features can also include the descriptors from computation chemistry or empirical rules like total energy, free energy, atomic charge, inner atomic orbital energies, molecular (bonding) orbital energies, weak interactions, and steric effect etc. The molecular syntax to construct valid connections of features or descriptors is also in the form of duplet or triplet. For example, the duplet CPOS (k) , R / Smeans the feature of chirality R or S is connected to the preceding atom at POS (k) . The triplet CPOS (g) , CPOS (h) , E / Z means the feature of isomerism E or Z is connected to the preceding atoms at POS (g) and POS (h) . The triplet CPOS (p) , CPOS (q) , QS means the feature of dihedral angle QS is connected to the preceding atoms at POS (p) and POS (q) . Similarly, special tags for the beginning and the ending of features and descriptors can also be included in the vocabulary.
[0051] The explicit atomic position is represented by POS (i) . More specifically, POS (i) represents the sequence order of an atom within the molecule. The sequence order can be calculated by a spatial algorithm. In some embodiments, the number of atoms is constrained not to exceed 99, so there can be 99 atomic positions available, ranging from POS (1) to POS (99) . These positions can be explicitly included in the vocabulary.
[0052] The forward-connecting position is represented by CPOS (i) . More specifically, CPOS (i) is a specialized positional marker used after the explicit atomic position POS (i) . It is employed for connecting the subsequent atomic environment to the preceding atom, as well as for connecting auxiliary structural descriptors, such as chirality, cis-trans isomerism, and dihedral angle to their preceding atoms. For embodiments in which the number of atoms is constrained not to exceed 99, there are 98 forward-connecting positions available from CPOS (1) to CPOS (98) . These positions can be explicitly included in the vocabulary.
[0053] For a given atom, the single-atom encoding GCN0 includes the element symbol combined with the number of connecting bonds (excluding bonds with hydrogen and not distinguishing between single and double bonds) followed by the number of hydrogen atoms. For example, C31 means a single C atom with 3 connections (regardless of bond types) and one H atom. As other examples, at 332, C04 means methane (CH4) , at 334, N03 means ammonia (NH3) , and at 336, O02 means water (H2O) .
[0054] Expanded 1-layer encoding (GCN1) adds the GCN0 encodings of all adjacent atoms (1-layer) connected to the atom of GCN0. GCN0 of 1-layer atoms are enclosed in square brackets, ordered by their explicit atomic positions, and separated by commas. For instance, C31[C22, C21, C13] means GCN0 C31 connected by three other GCN0 C22, C21, and C13 in the order of their explicit atomic positions.
[0055] Expanded 2-layer encoding (GCN2) adds the GCN0 encodings of all adjacent atoms (2-layer) connected to the atoms of GCN1. GCN0 of 2-layer atoms are enclosed in parentheses, ordered by their explicit atomic positions, and separated by commas. For example, GCN2 encoding of C31 [C22 (C31, C13) , C21 (C31, C21) , C13 (C31) ] is expanded from GCN1 encoding of C31 [C22, C21, C13] in which (C31, C13) is added to C22, (C31, C21) is added to C21, and (C31) is added to C13. Either GCN1 or GCN2 can be selected to construct the chemical vocabulary.
[0056] For embodiments in which atoms are restricted to the four elements O, N, C, H, the number of GCN1 encoding is approximately 9,000, and GCN2 encoding is around 150,000. When the elements are expanded to include 15 common non-metals and 15 metals typically found in organic compounds, the GCN1 encoding results in about 80,000 terms, and GCN2 encoding in about 1, 200,000 terms. These figures are derived from the current database of 100 million organic compounds. As the compound database expands, these numbers are expected to increase further.
[0057] Figure 4 is a method flow diagram for representing molecular inputs to a language model according to a molecular vocabulary and syntax. This flow provides additional detail for element 218 (represent a molecule input following the construction of the molecular vocabulary and defined molecular syntax) illustrated in Figure 2. At 442, the method can include molecular information conversion to a standard format (e.g., SMILES, InChI, etc. ) . The molecular information can originate in a different format such as natural language or a combination of other formats. Such conversion can be performed, for example, using OpenBabel or RDKit tools. OpenBabel is open source software used to convert between different chemical file formats. RDKit is an open source toolkit for cheminformatics.
[0058] At 444, the method can include conversion of molecular name or a given molecular format to a particular format and generation of three dimensional (3D) molecular structure in the particular format. By way of example, the particular format can be the MDL Molfile format, which stores information about the atoms, bonds, connectivity, and coordinates of a molecule.
[0059] At 446, the method can include ordering the atoms according to a sorting algorithm. For example, the sorting algorithm can be the Morgan algorithm, which seeks to assign a unique, sequential atom numbering for any given molecule. The first phase of the Morgan algorithm enumerates atom assignments staring with a random element as “1” and unlabeled neighboring atoms in random order with the next highest number. Each newly labeled atom is iterated in order of its label and its neighbors are numbered as described above until all atoms have been labeled. The second phase of the Morgan algorithm iteratively eliminates assignments until only one remains. Each atom is assigned an initial connectivity value equal to the number of heavy atoms attached to it. This value is updated with a sum of neighbor connectivity values in subsequent iterations. The process terminates when the number of unique connectivity values decreases from one round to the next. Another example of an appropriate sorting algorithm is the CANGEN algorithm, which is a combination of the CANON and GENES algorithms. CANON labels a molecular structure with canonical labels, treated as a graph with nodes (atoms) and edges (bonds) . Each atom is given a numerical label on the basis of its topology. GENES generates the unique SMILES notation as a tree representing the molecular graph. GENES selects the starting atom and makes branching decisions by referring to the canonical labels as needed.
[0060] At 448, the method can include extracting graph structure information and encoding it into a molecular vocabulary. The graph structure information can include nodes and edges. The information can be encoded into GCNx, POS (i) and CPOS (j) as described herein. Chiral isomerism, cis-trans isomerism, and dihedral angle information can be extracted and encoded into E, Z, R, S, and QS as described herein. At 449, the method can include transforming the molecular representation by following the molecular syntax.
[0061] Figure 5 is a flow diagram illustrating the conversion of a molecular input to a graph structure and first graph convolution network encoding. At 550, an input “The Vapor Pressure of 4-methylhex-2-ene is 207 mm Hg. ” can be received. The molecule 4-methylhex-2-ene is C7H14. At 542, the molecule in the corpus can be converted to a standard format, such as SMILES, resulting in “The Vapor Pressure of <mol>CC [C@H] (C) / C=C / C< / mol> is 207 mm Hg. ” at 552. At 544, the molecule in the SMILES format can be converted to Molfile format resulting in the presentation illustrated at 554. At 555, the molecule in the Molfile format can be converted into a graph structure, resulting in the presentation illustrated at 556. Each node (atom) can be labeled with its position 557, the number of connecting edges 558, and the number of hydrogen atoms 559. The presentation illustrated at 556 includes the POS (i) for each atom and is labeled with GCN0 encoding.
[0062] Figure 6 illustrates a second graph convolution network encoding following the molecular input of Figure 5. The graph is refined and expanded according to GCN1 encoding. The root node 661 representation is expanded to include singly connected atoms. Forward-linked positions are incorporated into the node representations as CPOS (j) 662. The root node 661 does not get a forward-linked position because it is the root. The GCN1 encoding is calculated and marked for each atom. The forward-linked position CPOS (j) is successively assigned to each atom in the order of POS (i) , to ensure that j is not greater than i.
[0063] Figure 7 is a flow diagram illustrating the molecular input from Figure 5 and Figure 6 represented with a molecular vocabulary and molecular syntax. Each atom is encoded using GCN encoding and converted to the corresponding tokened based on the predefined vocabulary. The first row 771 corresponds to the data illustrated in Figure 6, rearranged in sequential order based on POS (i) . According to the molecular syntax, the duplet POS (1) , GCN1 is written for the first atom. Also, the triplet POS (i) , GCN1, CPOS (j) is written successively from the second atom to the last atom (2-7 in this example) . The explicit directional position pairs between POS (i) and CPOS (j) is no bigger than i. The second row 772 follows the same order, but the data has been converted to the corresponding token IDs. For bonds with cis-trans isomerism (EZ) and atoms with chiral isomerism (RS) , as well as rotatable dihedral angles (Q) , a similar method should be sued to convert the relevant atomic positions and characteristics to predefined token IDs, as illustrated at row 773.
[0064] The result is the molecular sentence 774 represented with GCNx encoding. The sentence begins with token ID “52001” and ends with token ID “52002” as explained with respect to Figure 3, where the word “<mol>” corresponds to token ID “52001” and the word “< / mol>” corresponds to token ID 52002. The second token ID of the sentence “52101” corresponds to the word “POS (1) ” defined with respect to Figure 3. The remaining token IDs can be correlated and understood based on the description above. Thus, the molecular input “4-methylhex-2-ene” has been tokenized.
[0065] Standard code for the language model can be used to convert non-molecular inputs to token IDs. The token IDs for the non-molecular inputs can be sequentially merged with the tokenized molecular sentence. In this example, the non-molecular inputs are “The Vapor Pressure of” and “is 207 mm Hg. ” The merged and tokenized natural language sentence with the molecular sentence is illustrated at row 775.
[0066] Figure 8A is a graph illustrating a training loss and accuracy of training and testing of generative pretraining transformer (GPT) -2 by InChI. Figure 8B is a graph illustrating a training loss and accuracy of training and testing of GPT-2 by SMILES. Figure 8C is a graph illustrating a training loss and accuracy of training and testing of GPT-2 by GCN1. Figure 8D is a graph illustrating a training loss and accuracy of training and testing of GPT-2 by GCN2. InChI and SMILES use the tokenizer of GPT-2. GCN1 GCN2 use the novel tokenizers described herein. Accuracy is defined as the proportion of predictions where the energy prediction error is within 1 kilocalorie per mol (kcal / mol) relative to the total dataset. For GPT-2 Small model, given its size of 117 million parameters, achieving 100%training accuracy (indicative of overfitting) is typically feasible with 39,000 molecular data (approximately 3.9 million tokens) . However, the highest accuracy achieved with SMILES and InChI is only between 70%and 80%. This suggests a significant intrinsic problem for SMILES and InChI to capture the molecule information, leading to the failure for GPT-2 Small model to learn and understand molecular structure. The results for GCN1 and GCN2 encoding do not exhibit similar issues, achieving nearly 100%accuracy in training. Additionally, it is worth noting that the training efficiency of the GCN1 and GCN2 are significantly higher than SMILES and InChI, reaching the same 70%accuracy rate approximately 3 to 4 times faster. This represents a substantial advantage in training on larger datasets. In terms of test accuracy, compared to approximately 10%and 20%for SMILES and InChI respectively, GCN1 achieves about 40%accuracy. With the more complex GCN2 method, test accuracy can be further enhanced to about 50%.
[0067] Table 1 presents results of using the GPT-2 Small model using the GCN1 / GCN2 encoding described herein across various datasets and sizes.
[0068] Table 1
[0069] a. Only two types of atoms C and H
[0070] b. Four types of atoms O, N, C, H
[0071] c. Mean Absolute Error (MAE) of free energy (kcal / mol) .
[0072] d. Mean Absolute Error (MAE) of atomic charge.
[0073] In Table 1, with the same size of 796k dataset, it is clear that GCN1 is much better than the other three representations SMILES, InChI, and SELFIES. Even GCN0 can outperform the other three, indicating the effectiveness of the chemical vocabulary and molecular syntax. In Table 1, with the GCN1, overfitting occurs when the dataset size is 39k and 299k, but both training error and test error continue to decrease and start to converge when dataset size are increased to 796k and 1.2M. This indicates the overfitting problem has been mitigated at the scale of 1.2M data points (approximately 120M tokens) . The training error and testing error respectively reached 0.9 and 1.4 kcal / mol, an accuracy already on par with DFT and surpass other deep learning methods like GNN and DeePMD, indicating the potential to satisfy other needs in regression tasks like property prediction.
[0074] Figure 9 is an example machine 990 within which a set of instructions 999, for causing the machine 990 to perform various methodologies discussed herein, can be executed. The machine 990 can be connected (e.g., networked) to other machines in a LAN, an intranet, an extranet, and / or the Internet. The machine 990 can operate in the capacity of a server or a client machine in client-server network environment, as a peer machine in a peer-to-peer (or distributed) network environment, or as a server or a client machine in a cloud computing infrastructure or environment.
[0075] The machine 990 can be a personal computer (PC) , a tablet PC, a set-top box (STB) , a Personal Digital Assistant (PDA) , a cellular telephone, a web appliance, a server, a network router, a switch or bridge, or any machine capable of executing a set of instructions (sequential or otherwise) that specify actions to be taken by that machine. Further, while a single machine 990 is illustrated, the term “machine” shall also be taken to include any collection of machines that individually or jointly execute a set (or multiple sets) of instructions to perform any one or more of the methodologies discussed herein.
[0076] The example machine 990 includes a processing device 991, a main memory 992 (e.g., read-only memory (ROM) , flash memory, dynamic random access memory (DRAM) such as synchronous DRAM (SDRAM) or Rambus DRAM (RDRAM) , etc. ) , a static memory 993 (e.g., flash memory, static random access memory (SRAM) , etc. ) , and a data storage system 994, which communicate with each other via a bus 995.
[0077] The processing device 991 represents one or more general-purpose processing devices such as a microprocessor, a central processing unit (CPU) , or the like. More particularly, the processing device 991 can be a complex instruction set computing (CISC) microprocessor, reduced instruction set computing (RISC) microprocessor, very long instruction word (VLIW) microprocessor, or a processor implementing other instruction sets, or processors implementing a combination of instruction sets. The processing device 991 can also be one or more special-purpose processing devices such as an application specific integrated circuit (ASIC) , a field programmable gate array (FPGA) , a digital signal processor (DSP) , network processor, or the like. The processing device 991 is configured to execute instructions 999 for performing the operations and steps discussed herein. The machine 990 can further include a network interface device 996 to communicate over the network 997.
[0078] The data storage system 994 can include a machine-readable storage medium 998 (also known as a computer-readable medium) on which is stored one or more sets of instructions 999 or software embodying any one or more of the methodologies or functions described herein. The instructions 999 can also reside, completely or at least partially, within the main memory 992 and / or within the processing device 991 during execution thereof by the machine 990, the main memory 992 and the processing device 991 also constituting machine-readable storage media.
[0079] In one embodiment, the instructions 999 include instructions to implement functionality corresponding to the tokenizer for language models described herein. While the machine-readable storage medium 466 is shown in an example embodiment to be a single medium, the term “machine-readable storage medium” should be taken to include a single medium or multiple media that store the one or more sets of instructions. The term “machine-readable storage medium” shall also be taken to include any medium that is capable of storing or encoding a set of instructions for execution by the machine and that cause the machine to perform any one or more of the methodologies of the present disclosure. The term “machine-readable storage medium” shall accordingly be taken to include, but not be limited to, solid-state memories, optical media, and magnetic media, whether provided in a local or distributed manner (e.g., cloud storage) .
[0080] Although specific embodiments have been described above, these embodiments are not intended to limit the scope of the present disclosure, even where only a single embodiment is described with respect to a particular feature. Examples of features provided in the disclosure are intended to be illustrative rather than restrictive unless stated otherwise. The above description is intended to cover such alternatives, modifications, and equivalents as would be apparent to a person skilled in the art having the benefit of this disclosure.
[0081] The scope of the present disclosure includes any feature or combination of features disclosed herein (either explicitly or implicitly) , or any generalization thereof, whether or not it mitigates any or all of the problems addressed herein. Various advantages of the present disclosure have been described herein, but embodiments may provide some, all, or none of such advantages, or may provide other advantages.
[0082] In the foregoing Detailed Description, some features are grouped together in a single embodiment for the purpose of streamlining the disclosure. This method of disclosure is not to be interpreted as reflecting an intention that the disclosed embodiments of the present disclosure have to use more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive subject matter lies in less than all features of a single disclosed embodiment. Thus, the following claims are hereby incorporated into the Detailed Description, with each claim standing on its own as a separate embodiment.
Claims
1.A method, comprising:adding a molecular vocabulary to a tokenizer of a language model;wherein the molecular vocabulary includes words comprising character strings; andwherein the words represent atomic environments, explicit atomic positions, and forward-connecting positions based on a molecular database that includes data describing a plurality of molecules and their properties;defining a molecular syntax for the tokenizer that represents each of the plurality of molecules as a respective molecular sentence comprising a plurality of tuples;wherein the plurality of tuples correspond to a quantity of atoms in a respective molecule; andwherein the plurality of tuples include words from the molecular vocabulary;tokenizing the plurality of molecules according to the molecular vocabulary and the molecular syntax;training the language model to perform property prediction for molecules or to identify molecules having targeted properties using the tokenized plurality of molecules and their properties; andperforming, by the trained language model, property prediction for a molecule not in the molecular database or identifying, by the trained language model, molecules having the targeted properties.2.The method of claim 1, wherein the plurality of tuples for a particular molecule having N atoms include:a first duplet including:a first word representing the explicit atomic position of a first atom of the particular molecule; anda second word representing the atomic environment of the first atom; anda quantity of triplets equal to N-1, each triplet including:a third word representing the explicit atomic position of a respective atom of the particular molecule;a fourth word representing the atomic environment of the respective atom; anda fifth word representing the forward-connecting position between the respective atom and a preceding atom in the molecular syntax.3.The method of claim 2, wherein the plurality of tuples for the particular molecule further include an additional plurality of duplets and triplets;wherein a respective additional duplet includes the fifth word and a sixth word representing a first feature connected to the preceding atom at a position indicated by a number in the fifth word; andwherein a respective additional triplet includes two fifth words and a seventh word representing a second feature connected to two preceding atoms at positions indicated by numbers in the two fifth words.4.The method of claim 1, further comprising creating the words representing atomic environments by representing each non-hydrogen atom of a particular molecule with graph convolution network (GCN) encoding.5.The method of claim 4, wherein the GCN encoding of a respective non-hydrogen atom includes:its respective element symbol;a first number identifying its respective quantity of bonds, excluding bonds with hydrogen; anda second number identifying its respective quantity of bonds with hydrogen atoms.6.The method of claim 5, further comprising adding a GCN encoding of each non-hydrogen atom that is immediately adjacent to the respective non-hydrogen atom to the GCN encoding of the respective non-hydrogen atom.7.The method of claim 6, further comprising adding the GCN encoding of each non-hydrogen atom that is two layers adjacent to the respective non-hydrogen atom to the GCN encoding of the respective non-hydrogen atom.8.The method of claim 4, further comprising creating the words representing explicit atomic positions for each atom in a particular molecule by:calculating a sequence order of the atoms within the particular molecule using a spatial algorithm; andrepresenting the sequence order of the atoms with a text string indicating explicit atomic position and sequential numbers, each sequential number assigned to a respective atom according to the sequence.9.The method of claim 8, further comprising creating the words representing forward-connecting positions for each atom in a particular molecule by including a text string indicating forward-connecting position and sequential numbers;wherein each sequential number connects a subsequent atomic environment to a preceding atom in the sequence order of the atoms.10.The method of claim 1, wherein tokenizing the plurality of molecules further comprises tokenizing a natural language sentence describing a particular molecule and its properties.11.The method of claim 1, wherein the molecular vocabulary includes a plurality of tags, including a first tag denoting a beginning of any molecular sentence and a second tag denoting an ending of any molecular sentence.12.The method of claim 11, wherein the molecular vocabulary further includes a third tag denoting a beginning of a first segment of any molecular sentence describing bonded atomic positions and a fourth tag denoting an ending of the first segment.13.The method of claim 12, wherein the molecular vocabulary further includes:a fifth tag denoting a beginning of a second segment of any molecular sentence describing cis-trans and chiral isomerism;a sixth tag denoting an ending of the second segment;a seventh tag denoting a beginning of a third segment of any molecular sentence describing dihedral angle; andan eighth tag denoting an ending of the third segment.14.The method of claim 13, wherein the molecular vocabulary further includes a plurality of characters representing specific cis-trans, chiral, and dihedral angle encodings within the plurality of molecules.15.A non-transitory machine readable medium storing instructions executable by a processor to:add a molecular vocabulary to a tokenizer of a language model;wherein the molecular vocabulary includes words comprising character strings; andwherein the words represent atomic environments, explicit atomic positions, and forward-connecting positions based on a molecular database that includes data describing a plurality of molecules;define a molecular syntax for the tokenizer that represents each of the plurality of molecules and their properties as a respective molecular sentence comprising a plurality of tuples;wherein the plurality of tuples correspond to a quantity of atoms in a respective molecule; andwherein the plurality of tuples include words from the molecular vocabulary;tokenize the plurality of molecules according to the molecular vocabulary and the molecular syntax;train the language model to perform property prediction for molecules or to identify molecules having targeted properties using the tokenized plurality of molecules and their properties; andexecute the trained language model to perform property prediction for a molecule not in the molecular database or to identify molecules having the targeted properties.