
(UFEAT, MFEAT) <- \argmin_{UFEAT, MFEAT} LOSS
LOSS <- \sum_{i,j} (R_{i,j} - RATINGS_{i,j})^2;
R_{i,j} <- UFEAT_{i,-} * MFEAT_{j,-}’;
create tensor MFEAT (movie, fid 1:100) -> feature;
create tensor UFEAT (user, fid 1:100) -> feature;
create tensor RATINGS(user, movie) -> rating;
(1) MLog Program (2) Datalog Program
LOSS(v) :- R(i,j,v1), RATINGS(i,j,v2), v=op(i,j,v1,v2)
R(i,j,v) :- UFEAT(i,j1,v1), MFEAT(j,j2,v2), v=op(j1,v1,j2,v2)
(3.2) Executable Program
“Datalog-ify”
(3.1) Human-readable Math
Static Analysis & Optimiser
Y_{s,t} <- \sigma(Wy*H_{s,t,-});
H_{s,t,-} <- \sigma(Wh*X_{s,t,-} + Uh*H_{s,t-1,-});
create tensor Y(sent, word)-> feat;
create tensor H(sent, word, fid 1:100)-> feat;
create tensor X(sent, word, fid 1:100)-> feat;
(1) MLog Program (2) Datalog Program
H(s,t,v) :- Wh(w),X(s,t,v1),Uh(u),H(s,t-1,v2), v=op(w,v1,u,v2)
H(s,t,v) :- sent(s), t=0, v=0
(3.2) Executable Program
“Datalog-ify”
(3.1) Human-readable Math
Static Analysis & Optimiser
create tensor ANS(sent, word)-> feat;
LOSS <- \sum_{i,j} (Y_{s,t} - ANS_{s,t})^2;
(Wh, Wy, Uh) <- \argmin_{Wh, Wy, Uh} LOSS
create tensor Uh(fid 1:100, fid 1:100)-> feat;
create tensor Wh(fid 1:100, fid 1:100)-> feat;
create tensor Wy(fid 1:100)-> feat;
LOSS(v) :- Y(s,t,v1), ANS(s,t,v2), v=op(s,t,v1,v2)
Y(s,t,v) :- Wy(w),H(s,t,v1), v=op(w,v1)
Figure 2: MLOG Examples for (a) Matrix Factorization and (b) Recurrent Neural Network. (c) User Interface of MLOG.
greSQL such that it runs on the same data representation and users
can use a mix of MLOG and SQL statements. Although our formal
model provides a principled way for this integration, this function-
ality has not been implemented yet. In this demonstration, we focus
on the machine learning component and leave the full integration
as future work. Second, the current MLOG optimizer does not con-
duct special optimizations for sparse tensors. (In fact, it does not
even know the sparsity of the tensor.) Sparse tensor optimization is
important for a range of machine learning tasks, and we will sup-
port it in the near future. Third, the current performance of MLOG
can still be up to 2× slower than hand-optimized TensorFlow pro-
grams. It is our ongoing work to add more optimization rules into
the optimizer and to build our system on a more flexible backend,
e.g. Angel [6, 5]. Despite these limitations, we believe the current
MLOG prototype can stimulate discussions with the audience about
the ongoing trend of supporting machine learning in data manage-
ment systems.
Reproducibility and Public Release. The online demo will
be up before the conference. For now, all MLOG programs, hand-
crafted TensorFlow programs, and automatically generated Tensor-
Flow programs are available at github.com/DS3Lab/MLog.
2. THE MLOG LANGUAGE
In this section, we present basics for the audience to understand
the syntax and semantics of the MLOG language.
2.1 Data Model
The data model of MLOG is based on tensors–all data in MLOG
are tensors and all operations are a subset of linear algebra over
tensors. In MLOG, the tensors are closely related to the relational
model; in fact, logically, a tensor is defined as a special type of re-
lation. Let T be a tensor of dimension dim(T ) and let the index of
each dimension j range from {1, ..., dom(T, j)}. Logically, each
tensor T corresponds to a relation RJT K with dim(T )+1 attributes
(a
1
, ..., a
dim(T )
, v), where the domain of a
j
is {1, ..., dom(T, j)}
and the domain of v is the real space R. Given a tensor T ,
RJT K = {(a
1
, ..., a
dim(T )
, v)|T [a
1
, ..., a
dim(T )
] = v},
where T [a
1
, ..., a
dim(T )
] is the tensor indexing operation that gets
the value at location (a
1
, ..., a
dim(T )
).
Algebra over Tensors. We define a simple algebra over tensors
and define its semantics with respect to RJ−K, which allows us to
tightly integrate operation over tensors into a relational database
and Spark with unified semantics. This algebra is very similar to
DataCube with extensions that support linear algebra operations.
We illustrate it with two example operators:
1. Slicing σ. The operator σ
¯x
(T ) subselects part of the input
tensor and produces a new “subtensor.” The j-th element
of ¯x, i.e., ¯x
j
∈ 2
{1,...,dom(T,j)}
, defines the subselection
on dimension j. The semantic of this operator is defined as
RJσ
¯x
(T )K =
{(a
1
, ..., a
dim(T )
, v)|a
j
∈ ¯x
j
∧(a
1
, ..., a
dim(T )
, v) ∈ RJT K}.
2. Linear algebra operators op. We support a range of linear
algebra operators, including matrix multiplication and con-
volution. These operators all have the form op(T
1
, T
2
) and
their semantics are defined as RJop(T
1
, T
2
)K =
{(a
1
, ..., a
dim(T )
, v)|op(T
1
, T
2
)[a
1
, ..., a
dim(T )
] = v}.
2.2 MLog Program
An MLOG program Π consists of a set of TRules (tensoral rules).
TRule. Each TRule is of the form
T (¯x) : −op (T
1
(¯x
1
), ..., T
n
(¯x
n
)) ,
where n ≥ 0. Similar to Datalog, we call T (¯x) the head of the
rule, and T
1
(¯x
1
), ..., T
n
(¯x
n
) the body of the rule. We call op the
operator of the rule. Each ¯x
i
and ¯x specifies a subselection that
can be used by the slicing operator σ. To simplify notation, we use
“−” to donate the whole domain of each dimension–for example,
if ¯x = (5, −), σ
¯x
(T ) returns a subtensor that contains the entire
fifth row of T . We define the forward evaluation of a TRule as the
process that takes as input the current instances of the body tensors,
and outputs an assignment for the head tensor by evaluating op.
Semantics. Similar to Datalog programs, we can define fixed-
point semantics for MLOG programs. Let I be a data instance that
contains the current result of each tensor. We define the immediate
consequence of program Π on I as S
Π
(I), which contains I and
all forward evaluation results for each TRule. The semantic of an
MLOG program is the least fixed point of S
Π
(I), i.e., S
∞
Π
(I) = I.
1934
文档被以下合辑收录
评论