Synalinks is an adaptation of Keras 3 focused on neuro-symbolic systems and in-context reinforcement learning, an ensemble of techniques that enhance the LMs predictions and accuracy without changing the weights of the model. Synalinks is an open-source framework that makes it easy to create, evaluate, train, and deploy industry-standard Language Models (LMs) applications.
The goal of Synalinks is to facilitate the rapid setup of simple applications while providing the flexibility for researchers and advanced users to develop sophisticated systems.
The main concept of Synalinks is that it allows developers to build workflows/agents using the Functional API inherited from Keras. Instead of describing a directed acyclic graph (DAG) of tensor computation, it describes a DAG of JSON computation. In this context, the JSON schema acts as a specification (similar to the tensor shape in deep learning frameworks) of the data. The whole graph is computed only using the specification when the program is built.
- Data Models: Uses Pydantic-based
DataModelclasses with field descriptions for structured JSON processing - Schema Specification: JSON schemas act as specifications for data flow, similar to tensor shapes in traditional deep learning
- Type Safety: Ensures data correctness through constrained structured output
- Symbolic Reasoning: Combines neural network capabilities with symbolic logic and reasoning
- In-Context Learning: Enhances predictions without modifying model weights
- Constrained Generation: Ensures both format and content correctness through structured outputs
Synalinks offers four distinct ways to build applications:
- Functional API: Chain modules using Input → Processing → Output patterns
- Subclassing Program: Define modules in
__init__()and implement structure incall() - Mixed Approach: Combine subclassing with Functional API using
build()method - Sequential API: Stack single-input, single-output modules linearly
- Versioning: Each program is serializable into JSON so you can version it with git
- REST API Deployment: Compatible out-of-the-box with FastAPI
- Async Optimization: Automatically optimizes pipelines by detecting parallel processes
- Multi-Provider Support: Integrates with Ollama, OpenAI, Anthropic, Mistral, and Groq
- Documentation Tools: Built-in plotting and visualization for workflows and training history
class Query(synalinks.DataModel):
query: str = synalinks.Field(
description="The user query",
)language_model = synalinks.LanguageModel(
model="ollama/deepseek-r1",
)embedding_model = synalinks.EmbeddingModel(
model="ollama/deepseek-r1",
)- Input: Defines input data structure. Input Module
- Generator: Processes data using language models
- Program: Orchestrates the entire workflow
- Sequential: Linear processing pipeline
- Branch: Branch over the given modules by selecting only some of them
- In-Context Reinforcement Learning: Optimizes prompts without changing model weights
- Rewards System: Built-in evaluation metrics (e.g., ExactMatch)
- Optimizers: Various optimization strategies (e.g., RandomFewShot)
- Batch Processing: Supports batch training with configurable parameters
import synalinks
import asyncio
class Query(synalinks.DataModel):
query: str = synalinks.Field(description="The user query")
class AnswerWithThinking(synalinks.DataModel):
thinking: str = synalinks.Field(description="Step by step thinking")
answer: float = synalinks.Field(description="Numerical answer")
async def main():
language_model = synalinks.LanguageModel(model="ollama/deepseek-r1")
x0 = synalinks.Input(data_model=Query)
x1 = await synalinks.Generator(
data_model=AnswerWithThinking,
language_model=language_model,
)(x0)
program = synalinks.Program(
inputs=x0,
outputs=x1,
name="chain_of_thought",
description="Step by step reasoning system",
)
(x_train, y_train), (x_test, y_test) = synalinks.datasets.gsm8k.load_data()
program.compile(
reward=synalinks.rewards.ExactMatch(in_mask=["answer"]),
optimizer=synalinks.optimizers.RandomFewShot()
)
history = await program.fit(
x_train,
y_train,
validation_data=(x_test, y_test),
batch_size=32,
epochs=10,
)
synalinks.utils.plot_history(history)Synalinks is designed for a diverse range of users, from professionals and AI researchers to students, independent developers, and hobbyists. It is suitable for anyone who wants to learn about AI by building/composing blocks or build solid foundations for enterprise-grade products.
This work has been done under the supervision of François Chollet, the author of Keras. The framework leverages:
- Keras: For graph-based computation backbone and API design
- DSPy: For modules and optimizers inspiration
- Pydantic: For backend data layer and validation
Synalinks follows the principle of progressive disclosure of complexity: meaning that simple workflows should be quick and easy, while arbitrarily advanced ones should be possible via a clear path that builds upon what you've already learned.
The framework bridges the gap between neural networks and symbolic reasoning, creating more robust, interpretable, and controllable AI systems that maintain the flexibility of deep learning while adding the transparency and reliability of symbolic approaches.
- Documentation: https://synalinks.github.io/synalinks/
- GitHub: https://github.com/SynaLinks/synalinks
- Website: https://www.synalinks.com/
uv pip install synalinks
uv run synalinks init