SELFIES (SELF-referencIng Embedded Strings) is a molecular string representation designed with a formal grammar that guarantees 100% syntactic and semantic validity. Unlike SMILES, where arbitrary character mutations frequently produce invalid molecular graphs, every syntactically valid SELFIES string maps unambiguously to a valid molecule. This is achieved through a derivation rule system where each symbol encodes a state transition, ensuring that the string's construction inherently respects valence constraints and bonding rules.
Glossary
SELFIES

What is SELFIES?
A 100% robust molecular string representation where every syntactically valid string corresponds to a valid molecular graph, eliminating the invalid outputs common with SMILES-based generative models.
This robustness makes SELFIES ideal for generative models like variational autoencoders and language models, as the output space is entirely valid, eliminating the need for post-hoc sanitization. Derived from a formal context-free grammar, SELFIES represents atoms and bonds as a sequence of tokens that self-reference the current valence state, enabling direct mutation and crossover operations in genetic algorithms without producing chemical nonsense.
Key Features of SELFIES
SELFIES (SELF-referencIng Embedded Strings) is a 100% robust molecular string representation where every syntactically valid string corresponds to a valid molecular graph, eliminating the invalid outputs common with SMILES-based generative models.
100% Syntactic Robustness
The defining feature of SELFIES is its guaranteed validity: every string generated from the SELFIES grammar corresponds to a valid molecular graph. This is achieved through a formal context-free grammar where derivation rules enforce valence constraints and bonding rules at the token level. Unlike SMILES, where a single misplaced character can produce an invalid molecule, SELFIES eliminates the need for post-hoc validity checks or rejection sampling during generative modeling.
Semantically Invalid SELFIES
While all SELFIES strings are syntactically valid, they can be semantically invalid. This occurs when a string represents a chemically unreasonable molecule, such as one with strained rings, charged species with missing counterions, or violations of the octet rule. The distinction is critical: syntactic validity guarantees a molecular graph exists, but semantic validity requires additional chemical filters or property predictors to assess drug-likeness or synthetic accessibility.
Derivation Rules and Grammar
SELFIES uses a formal grammar with derivation rules that map each symbol to a specific graph-construction operation. Key rule types include:
- Atom symbols: Add an atom with a specified valence state (e.g.,
[C],[N],[O]) - Bond symbols: Specify the bond order between the most recently added atom and a previous atom (e.g.,
[=C],[#N]) - Branch symbols: Open and close branches for ring closures and side chains (
[Branch1],[Ring1]) - State symbols: Modify atom states like charge or isotope without altering connectivity
SELFIES vs. SMILES Comparison
| Property | SMILES | SELFIES |
|---|---|---|
| Validity guarantee | No | Yes (100%) |
| Human readability | High | Low |
| String length | Shorter | Longer |
| Generative model compatibility | Requires validity filters | Native support |
| Canonicalization | Complex algorithms | Grammar-defined |
SELFIES strings are typically 1.5-2x longer than equivalent SMILES, but the robustness trade-off is essential for variational autoencoders (VAEs), generative adversarial networks (GANs), and reinforcement learning pipelines where invalid outputs waste compute and degrade training.
Encoding and Decoding Pipeline
The SELFIES pipeline operates in three stages:
- Encoding: A SMILES string is parsed into a molecular graph, then converted to a SELFIES string using the derivation grammar
- Manipulation: The SELFIES string is tokenized into a sequence of symbols for use in sequence-based deep learning models (LSTMs, Transformers, VAEs)
- Decoding: The generated SELFIES string is deterministically converted back to a molecular graph, then optionally to SMILES for visualization
This bidirectional mapping ensures lossless conversion between representations while maintaining the robustness guarantee throughout the generative process.
Applications in Generative Chemistry
SELFIES is particularly valuable in de novo drug design pipelines where generative models explore chemical space:
- Variational Autoencoders: The continuous latent space can be freely sampled without producing invalid molecules
- Reinforcement Learning: Reward functions can focus on property optimization rather than validity penalties
- Genetic Algorithms: Crossover and mutation operations always produce valid offspring
- Language Models: Autoregressive generation with SELFIES tokens guarantees valid outputs at every step
Libraries such as selfies (Python) and integrations with RDKit, DeepChem, and GuacaMol support adoption.
SELFIES vs. SMILES: A Technical Comparison
A feature-by-feature comparison of the SELFIES and SMILES molecular string representations, highlighting key differences in validity, generative suitability, and structural expressiveness.
| Feature | SELFIES | SMILES | DeepSMILES |
|---|---|---|---|
100% Syntactic Validity | |||
100% Semantic Validity | |||
Robust to Random Mutation | |||
Direct Generative Model Output | |||
Human Readability | |||
Canonicalization Support | |||
Explicit Hydrogen Encoding | |||
Invalid Output Rate in VAEs | < 0.1% | ~5-15% | ~1-5% |
Frequently Asked Questions
Explore the core mechanics, advantages, and practical applications of the SELFIES molecular representation—a 100% robust string encoding that guarantees every syntactically valid output corresponds to a valid molecular graph.
SELFIES (Self-Referencing Embedded Strings) is a 100% robust molecular string representation where every syntactically valid string corresponds to a valid molecular graph, completely eliminating the syntactic and semantic errors common with SMILES strings. Unlike SMILES, which uses a context-free grammar requiring complex parsing rules for ring closures and branching, SELFIES is derived from a formal grammar that enforces valence constraints directly in its derivation rules. This means a randomly generated or mutated SELFIES string will always decode into a physically valid molecule, making it uniquely suited for generative models and evolutionary algorithms in de novo drug design. The representation stores atoms and bonds as tokens in a sequence, with a self-referencing mechanism that tracks the current state of the molecular graph during construction, preventing invalid valence states or dangling bonds.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Explore the foundational concepts, alternative representations, and validation frameworks that surround the SELFIES molecular string representation.
Molecular Graph
The formal mathematical structure underlying all molecular representations, where atoms are nodes and bonds are edges. SELFIES guarantees a bijective mapping to valid molecular graphs.
- Node features: Atom type, formal charge, hybridization state, chirality
- Edge features: Bond order (single, double, triple, aromatic), stereochemistry
- Graph constraints: Valence rules, octet rule compliance, kekulé structures for aromatic systems
- Representation: Adjacency matrices, edge lists, or feature-augmented graph objects used directly by Graph Neural Networks
DeepSMILES
An intermediate representation that modifies SMILES syntax to improve generative model validity by addressing ring closure and branching ambiguities. A stepping stone toward SELFIES-level robustness.
- Ring syntax: Uses explicit ring-opening and ring-closing tokens with paired indices
- Branching: Replaces parentheses with explicit branch-start and branch-end tokens
- Validity improvement: Reduces invalid outputs compared to standard SMILES but does not achieve 100% robustness
- Historical context: Demonstrated that syntax redesign could improve generation validity, paving the way for SELFIES
Grammar-Based Generation
A class of generative methods that constrain outputs to a formal grammar, ensuring syntactic validity. SELFIES is a prime example where the grammar is designed to be semantically closed—every syntactically valid string maps to a valid molecule.
- Context-free grammars (CFG): Production rules define valid token sequences
- Attribute grammars: Extend CFGs with semantic rules to enforce chemical constraints
- SELFIES grammar: A deterministic finite-state automaton where each derivation step preserves chemical validity
- Alternative approach: Variational autoencoders with grammar-guided decoding for SMILES

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us