gaia.core.kan_extensions module
Kan Extensions for GAIA Framework - Foundation Model Construction
Implements Section 6.6 from GAIA paper: “Kan Extension” INTEGRATES with existing kan_verification.py for complete Kan extension system
THEORETICAL FOUNDATIONS: - Definition 48: Left Kan extension Lan_K F: D → E with universal property - Right Kan extension Ran_K F: D → E as right adjoint - Migration functors Δ_F, Σ_F, Π_F for generative AI model modifications - Foundation model construction via functor extension - Universal property: “every concept in category theory is a special case of Kan extension”
This enables GAIA to construct foundation models by extending functors over categories, rather than interpolating functions on sets - the core innovation of GAIA.
- class gaia.core.kan_extensions.Category(name)[source]
Bases:
ABC
Abstract base class for categories
A category consists of objects and morphisms with composition and identity
- class gaia.core.kan_extensions.SetCategory[source]
Bases:
Category
Category of sets and functions
Objects are sets, morphisms are functions between sets
- get_morphism(source, target)
Get morphism between objects
- has_morphism(source, target)
Check if morphism exists between objects
- class gaia.core.kan_extensions.GenerativeAICategory(name='GenerativeAI')[source]
Bases:
Category
Category for generative AI models
Objects are model components, morphisms are transformations between them
- get_morphism(source, target)
Get morphism between objects
- has_morphism(source, target)
Check if morphism exists between objects
- class gaia.core.kan_extensions.Functor(source_category, target_category, name)[source]
-
Abstract base class for functors F: C → D
Maps objects and morphisms while preserving categorical structure
- abstractmethod map_morphism(morphism, source_obj, target_obj)[source]
Map morphism from source to target category
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- class gaia.core.kan_extensions.NeuralFunctor(source_category, target_category)[source]
Bases:
Functor
Functor for neural network transformations
Maps between categories of neural network components
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- verify_functoriality()
Verify functor laws: F(id) = id and F(g∘f) = F(g)∘F(f)
- class gaia.core.kan_extensions.NaturalTransformation(source_functor, target_functor, name)[source]
Bases:
object
Natural transformation between functors
Provides component-wise transformation that commutes with functor morphisms
- class gaia.core.kan_extensions.LeftKanExtension(F, K, name='LeftKanExtension')[source]
Bases:
object
Left Kan extension Lan_K F: D → E
From (MAHADEVAN,2024) Definition 48: Universal property for extending functors
- class gaia.core.kan_extensions.RightKanExtension(F, K, name='RightKanExtension')[source]
Bases:
object
Right Kan extension Ran_K F: D → E
Dual to left Kan extension, constructed via limits instead of colimits
- class gaia.core.kan_extensions.MigrationFunctor(F, name='MigrationFunctor')[source]
Bases:
object
Migration functors for generative AI model modifications
From GAIA paper: Δ_F (pullback), Σ_F (left pushforward), Π_F (right pushforward)
- pullback_functor(epsilon_functor)[source]
Δ_F: ε → δ
Pullback functor that maps modified model back to original
- class gaia.core.kan_extensions.FoundationModelBuilder(name='FoundationModelBuilder')[source]
Bases:
object
Foundation model builder using Kan extensions
Core innovation of GAIA: build foundation models by extending functors over categories rather than interpolating functions on sets
- build_foundation_model_via_left_kan(base_functor_name, extension_functor_name, model_name)[source]
Build foundation model via left Kan extension
This extends the base functor along the extension direction
- build_foundation_model_via_right_kan(base_functor_name, extension_functor_name, model_name)[source]
Build foundation model via right Kan extension
- gaia.core.kan_extensions.create_llm_foundation_model(vocab_size, hidden_dim)[source]
Create foundation model for Large Language Models
Uses Kan extensions to build LLM from categorical components