Dyna – 用于机器学习的逻辑编程
Dyna – Logic Programming for Machine Learning

原始链接: https://dyna.org/

## Dyna:一种用于机器学习的编程语言 Dyna 是一种编程语言,旨在弥合数学符号和机器学习研究人员的可执行代码之间的差距。Dyna 建立在 Datalog 和 Prolog 等逻辑编程范式之上,允许灵活的执行顺序和加权规则,从而简洁地表达复杂的算法。例如矩阵乘法、斐波那契数列、CKY 句法分析,甚至神经网络——所有这些都可以用几行代码实现。 该项目从 Dyna 1.0 发展而来,通过半环扩展 Datalog 用于动态规划,到 Dyna 2.0,它引入了函数、变量处理、惰性求值和基于原型的继承。当前的研究重点是通过关系代数和项重写进行高效实现,并利用强化学习来优化程序执行。 存在几种实现,包括 Dyna3(一个现代 Clojure 版本),以及早期版本,如 Dyna-R 和 Dyna-Pi,每个版本都在探索语言能力的各个方面。Dyna 旨在通过最大限度地减少将数学概念转化为可运行程序的工作量,来简化机器学习研究过程。

## Dyna:用于机器学习的逻辑编程 - 摘要 Dyna 是一种新的逻辑编程语言,专为机器学习设计。它最近在 Hacker News 上受到关注,这归功于其创建者 Matthewfl,该语言是他博士研究的成果。它是 Datalog 的扩展,能够超越简单的真/假陈述进行概率推理。 Dyna3 是最新的实现,使用 Clojure 构建,并具有 JIT 编译器——一些人认为它非常先进。它还支持函数式编程,具有 lambda 闭包和嵌入式 DSL。 评论员指出它与 Scallop 相似,Scallop 是另一个专注于可微性和 PyTorch 集成的 Datalog 扩展。虽然目前仍是一个研究项目,但 Dyna 提供了 Python、Clojure 和 Java API,允许潜在地在生产系统中应用,尽管创建者承认要达到成熟度仍需要大量的进一步开发。原始帖子提供了包括论文、代码仓库和 YouTube 解释等资源。
相关文章

原文

About the Dyna Programming Language

Dyna is a programming language designed by and for machine learning researchers. Dyna builds on the paradigm of logic programming languages such as Datalog and Prolog. However, Dyna goes much further in that it allows for flexible execution orders and for rules in the program to be "weighted". This means that we can efficiently express complicated programs in a few lines of code without having to worry about how the program will execute and only focus on what we want computed. For example, we can write our matrix multiplication in a single line of code, as well as the fibonacci sequence, CKY parsing, and even an "infinite" neural network in a few lines of code as shown below.

% Dyna rule for multiplying the matrix `a` and `b` together
c(I,K) += a(I,J) * b(J,K).

% The fibonacci sequence
fib(N) := fib(N-1) + fib(N-2).                                   % recursive step
fib(0) := 0.                                                     % override recursive step for 0 and 1
fib(1) := 1.

% CKY Parsing
phrase(X,I,K) max= phrase(Y,I,J) * phrase(Z,J,K) * rule(X,Y,Z).  % binary CKY rule
phrase(X,I,K) max= phrase(Y,I,K) * rule(X,Y).                    % uniary CKY rule
phrase(X,I,I+1) max= rule(X, word(I)).                           % terminal rule


% A Neural Network defined in terms of edges
sigma(X) = 1/(1+exp(-X)).                                        % define sigmoid function
out(J) = sigma(in(J)).                                           % apply sigmoid function
in(J) += out(I) * edge(I,J).                                     % vector-matrix product
loss += (out(J) - target(J))**2.                                 % L2 loss
edge(input(X,Y),hidden(X+DX,Y+DY)) = weight(DX,DY).              % define edges in terms of weight matrix
weight(DX,DY) := random(-1,1) for DX:-4..4, DY:-4..4.            % random initialization for matrix

% To see more example Dyna programs, please checkout our research papers.

History of the Dyna Project

The Dyna project was initially started in 2004 as an umbrella project to make a programming language for Machine Learning (ML) researchers. Most algorithms that ML researchers implement are expressible in a few lines of math. In the process of researching new algorithms, researchers often have to iterate many times. This means that they revise the mathematical concept of their algorithm and then recode their program to match. The Dyna project hopes to help this process by reducing the distance between mathematical concepts and executable code.

The discrepancy between non-executable mathematical notation and executable programs was the central motivation for the Dyna project and led to the development of Dyna 1.0 (Paper 1, Paper 2) Dyna 1.0 extended Datalog by replacing the boolean semiring used in logic programming to allow any semiring. In other words, this meant that Dyna 1.0 was a notation for expressing and running dynamic programs. As such, Dyna 1.0 was successfully used in a number of research papers.

On the heels of Dyna 1.0 success, Dyna 2.0 was proposed to rectify many of the limitations of Dyna 1.0 (Paper). Dyna 1.0 requires everything to use the same semiring, Dyna 2.0 removes this restriction, instead, it has functions. Dyna 1.0 is a dialect of Datalog and as such, requires all terms to only contain ground values. This allowed the Dyna 1.0 compiler to generate programs that loop over the entire domain of an expression---much like a scan of a database table. Dyna 2.0 has no such restriction. Instead, Dyna 2.0 allows for variables in the program to remain free. Dyna 2.0 performs unification similar to Prolog, where expressions like a(X)=a(Y) unifies X and Y together without knowing the value of X or Y. Dyna 2.0 also supports both lazy expressions allowing for expressions like X+Y=Z to remain "unevaluated". Dyna 2.0 can also eagerly compute and memoize any expression to avoid recomputing the same expression many times. Dyna 2.0 also introduced a prototype-based inheritance (dynabases) which is useful for building larger programs.

Ongoing Research about Dyna

  • Relational Algebra and Term Rewriting to build a Flexible, Complete Implementation — The execution of a Dyna program is non-trivial and can not be implemented using the same techniques used to implement Datalog and Prolog engines. In this research, we are looking into new ways in which declarative programming languages can be implemented using term-rewriting on top of a relational algebra which can represent a Dyna program.
  • Reinforcement Learning used to find an Optimal Execution Strategy — One of the major differences between Dyna compared to other programming languages is that Dyna does not guarantee the order in which expressions are evaluated. This, in turn, provides us with opportunities to "rearrange" to program to improve the program's runtime. In this work, we are investigating how reinforcement learning and heuristic search strategies can be used to automatically make a program more efficient.

Select Published Research Papers

Additional talks about Dyna can be found here.

Downloads / Different Implementations of Dyna

  • Dyna3 (online demo) — A new implementation of the Dyna programming language written in Clojure. This implementation is a redesign of Dyna-R to be faster and more feature complete.
  • Dyna-R — An implementation of Dyna using Relational Expressions (R-exprs). This implementation was the first implementation to successfully run many of our more complex Dyna 2 programs from the Dyna 2 paper. This implementation is known to run slow (it is an interpreter written in pure python).
  • Dyna-Pi — An implementation of Dyna 1 (semiring programs only) to study reinforcement learning ability to optimize a program's runtime through program transformations. Written in Python.
  • Dyna-Phi — An implementation of Dyna using the Truffle/Graal framework.
  • Dyna2 — An early attempt at implementing Dyna 2 written in Haskell and Python.
  • Dyna1 — The original implementation the Dyna programming language. This implementation only supports single semiring programs, see the section about history of Dyna above. Download not available.
联系我们 contact @ memedata.com