• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

From neural networks to the Category of composable supervised learning algorithms in Scala with compile-time matrix checking based on singleton-types

Neurocat

Neurocat is an experimental toy library studying 2 things:

  • The link between category theory and supervised learning algorithm and neural networks through the concepts described in this amazing paper Backprop as Functor: A compositional perspective on supervised learning which tries to unify (partly at least) category theory & supervised learning concepts & simple neural networks/

  • how to represent matrices (and thus neural networks) which dimensions are checked at compile-time using the new feature singleton-types described in SIP-23 which allows to manipulate the integer 3 as the value 3 but also the type 3. My matrix experimentations use the little & really cool library singleton-ops by Frank S. Thomas the author of the great refined library too. Shapeless Nat is a nice idea but not good for big naturals because this is a recursive structure (down to 0) checked at compile-time so 100000 as

Very superficially, the idea of the paper is quite simple (minus a few details):

  • A supervised learning algorithm can be seen as a structure able to approximate a function A -> B relying on parameters P which are updated through an optimization/training process using a set of training samples.
  • This paper shows that the set of supervised learning algorithms equipped with 3 functions (implement, update-params, request-input) forms a symmetric monoidal category Learn and then demonstrates that supervised learning algorithms can be composed
  • It also shows that there exists a Functor from the category ParaFn of parametrised functions P -> A -> B to Learn category.

ParaFn -> Learn

  • Then it shows that a (trained) neural network can be seen as an approximation of a function InputLayer -> OutputLayer parametrised by the weights W.
  • Thus it demonstrates there is also a Functor from the category of neural network (W, InputLayer, OutputLayer) to the category of parametrised functions (W -> InputLayer -> OutputLayer)

I: NNet -> ParaFn

  • By simple functor composition, you have then a Functor from neural networks to supervised learning algorithms:

NNet -> Learn : (ParaFn -> Learn) ∘ (NNet -> ParaFn)

I'll stop there for now but my work has just started and there are more concepts about the bimonoidal aspects of neural networks under euclidean space constraints and pending studies about recurrent networks and more.

Discovering that formulation, I just said: "Whoaaa that's cool, exactly what I had in mind without being able to put words on it".

Why? Because everything I've seen about neural networks looks like programming from the 70s, not like I program nowadays with Functional Programming, types & categories.

This starts unifying concepts and is exactly the reason of being of category theory in maths. I think programming learning algorithms will change a lot in the future exactly as programming backends changed a lot those last 10 years.

I'm just scratching the surface of all of those concepts. I'm not a NeuralNetwork expert at all neither a good mathematician so I just want to open this field of study in a language which now has singleton-types allowing really cool new ways of manipulating data structures

So first, have a look at this sample:

For info, to manipulate matrices, I used ND4J to have an array abstraction to test both in CPU or GPU mode but any library doing this could be used naturally.

More Repositories

1

play-autosource

Play Autosource : 1mn REST/Crud/Async/Typesafe Datasource for Play Framework
Scala
153
star
2

neural-ode

Neural Ordinary Differential Equation
Jupyter Notebook
97
star
3

siena

Siena is a persitence API for Java inspired on the Google App Engine Python Datastore API
Java
81
star
4

play-json-zipper

play-json-zipper
Scala
70
star
5

play-actor-room

A Room manager for Play Framework 2.2 based on WebSocket & Bots
Scala
50
star
6

play-siena

Siena Module for Play! Framework
Java
42
star
7

play2-json-demo

Play2 Json Demos
JavaScript
42
star
8

scaledn

Scala EDN parser based on Parboiled2
Scala
39
star
9

scala-xmlsoap-ersatz

XML/SOAP Ersatz tools, for Scala (developed & used with Play Framework 2.0 Scala) to read/write XML/SOAP without code generation, annotations or whatever magic
Scala
39
star
10

scalaeff

Scala
35
star
11

injective

Runorama injection with Free / Coproduct / Coyoneda
Scala
28
star
12

zpark-ztream

Driving Spark stream with Scalaz-Stream
Scala
26
star
13

play-capistrano

A module to deploy Play apps with Capistrano
Ruby
24
star
14

play-json-alone

Sample of Play2.2-SNAPSHOT JSON API used stand-alone
Scala
24
star
15

freek

Free wrapper specialized to Coproducts of DSL/Containers
Scala
24
star
16

shapelaysson

Shapelaysson = Shapeless + Play-Json
Scala
23
star
17

freez

Optimizing FreeMonads with other representations of the structure
Scala
21
star
18

scalaio-2014

ScalaIO Talk 2014 code sample
Scala
20
star
19

codenets

My own playground for PLP (Programming Language Processing) using DeepLearning techniques
Python
19
star
20

pytorch_math_dataset

Pytorch Playground for Mathematical Reasoning Dataset
Jupyter Notebook
18
star
21

khats

Khats, cats on Higher-Kinded amphets
Scala
16
star
22

play-crud-siena

A module for the Play! web framework providing a CRUD mechanism when using Siena DB APIs.
Java
16
star
23

daemonad

A categorical programming facility for Scala that offers a direct API for working with monad & a few monad stacks (at least trying).
Scala
11
star
24

pytorch-neural-ode

Experiment with Neural ODE on Pytorch
Jupyter Notebook
9
star
25

maquereau

Come on taste my fresh Scala Macrooooos!!!
Scala
9
star
26

playzstream

Scala
8
star
27

freevan

Van Laarhoven Free Monad implementation
Scala
6
star
28

shapeless-rules

Play 2.3 generic Validation API with Shapeless
Scala
6
star
29

shameless

Shapeless funny extensions
Scala
6
star
30

snapshot_ensembles

Neural Network Snapshot Ensembles
Jupyter Notebook
5
star
31

jszipper

Generic Json Zipper
Scala
4
star
32

where-is-felipe2

where-is-felipe 2
Scala
4
star
33

scalameta-diff

Scala
3
star
34

mandubian-mvn

mandubian maven repo
3
star
35

generic-dao

Generic Dao for Java Generics and Enum + Spring + Hibernate
3
star
36

xwiki-selector

A GWT XWiki space/page selector with hooks on an existing form
Java
2
star
37

play2json

Play20 Json Demo
Scala
2
star
38

play2-mongodb-async

MongoDB Async Support to Play! Framework 2.0 based on Mongo Async Driver
Scala
2
star
39

mutimmutable

mutable in the small, immutable in the large
Scala
2
star
40

activator-play-autosource-reactivemongo

Activator template for ReactiveMongo Play Autosource - Automatic CRUD/REST Datasource.
Shell
2
star
41

shapotomic

Shapeless HList + Datomisca/Datomic Schema
Scala
1
star
42

buyme

Buy Me
JavaScript
1
star
43

play2-scala-richjson

Play2 Scala Rich Json
Scala
1
star
44

monitored

Scala
1
star
45

webgl-stream

JavaScript
1
star
46

mandubian.com

Mandubian Website
CSS
1
star
47

resource-test

Scala
1
star
48

memopedia

memopedia
JavaScript
1
star
49

FreeFood

FreeFood[I[_]] is the simplest recipe that can give food from ingredients I[_]
1
star
50

play2-data-resources

Play2 Scala Data Resources
Scala
1
star
51

rescator

Scala Very Simple Json API
Scala
1
star
52

ad-rust

An experimental study on using (& learning) Rust for Automatic Differentiation with ArrayFire and then applying that to build neural networks
Rust
1
star