<s>
Torch	B-Algorithm
is	O
an	O
open-source	B-Application
machine	O
learning	O
library	O
,	O
</s>
<s>
a	O
scientific	O
computing	O
framework	O
,	O
and	O
a	O
scripting	B-Language
language	I-Language
based	O
on	O
Lua	B-Language
.	O
</s>
<s>
It	O
provides	O
LuaJIT	B-Application
interfaces	O
to	O
deep	B-Algorithm
learning	I-Algorithm
algorithms	O
implemented	O
in	O
C	B-Language
.	O
It	O
was	O
created	O
at	O
IDIAP	O
at	O
EPFL	O
.	O
</s>
<s>
Torch	B-Algorithm
development	O
moved	O
in	O
2017	O
to	O
PyTorch	B-Algorithm
,	O
a	O
port	O
of	O
the	O
library	O
to	O
Python	B-Language
.	O
</s>
<s>
The	O
core	O
package	O
of	O
Torch	B-Algorithm
is	O
torch	B-Algorithm
.	O
</s>
<s>
The	O
Tensor	O
also	O
supports	O
mathematical	O
operations	O
like	O
max	O
,	O
min	O
,	O
sum	O
,	O
statistical	O
distributions	O
like	O
uniform	O
,	O
normal	O
and	O
multinomial	O
,	O
and	O
BLAS	B-Application
operations	O
like	O
dot	O
product	O
,	O
matrix	O
–	O
vector	O
multiplication	O
,	O
matrix	O
–	O
matrix	O
multiplication	O
and	O
matrix	O
product	O
.	O
</s>
<s>
The	O
following	O
exemplifies	O
using	O
torch	B-Algorithm
via	O
its	O
REPL	B-Application
interpreter	O
:	O
</s>
<s>
The	O
torch	B-Algorithm
package	O
also	O
simplifies	O
object-oriented	B-Language
programming	I-Language
and	O
serialization	B-Application
by	O
providing	O
various	O
convenience	O
functions	O
which	O
are	O
used	O
throughout	O
its	O
packages	O
.	O
</s>
<s>
The	O
torch.class(classname, parentclass )	O
function	O
can	O
be	O
used	O
to	O
create	O
object	B-Language
factories	I-Language
(	O
classes	O
)	O
.	O
</s>
<s>
When	O
the	O
constructor	O
is	O
called	O
,	O
torch	B-Algorithm
initializes	O
and	O
sets	O
a	O
Lua	B-Language
table	O
with	O
the	O
user-defined	O
metatable	O
,	O
which	O
makes	O
the	O
table	O
an	O
object	O
.	O
</s>
<s>
Objects	O
created	O
with	O
the	O
torch	B-Algorithm
factory	O
can	O
also	O
be	O
serialized	O
,	O
as	O
long	O
as	O
they	O
do	O
not	O
contain	O
references	O
to	O
objects	O
that	O
cannot	O
be	O
serialized	O
,	O
such	O
as	O
Lua	B-Language
coroutines	B-Architecture
,	O
and	O
Lua	B-Language
userdata	O
.	O
</s>
<s>
The	O
nn	O
package	O
is	O
used	O
for	O
building	O
neural	B-Architecture
networks	I-Architecture
.	O
</s>
<s>
Modules	O
have	O
a	O
forward( )	O
and	O
backward( )	O
method	O
that	O
allow	O
them	O
to	O
feedforward	B-Algorithm
and	O
backpropagate	B-Algorithm
,	O
respectively	O
.	O
</s>
<s>
This	O
modular	O
interface	O
provides	O
first-order	O
automatic	B-Algorithm
gradient	I-Algorithm
differentiation	I-Algorithm
.	O
</s>
<s>
What	O
follows	O
is	O
an	O
example	O
use-case	O
for	O
building	O
a	O
multilayer	B-Algorithm
perceptron	I-Algorithm
using	O
Modules	O
:	O
</s>
<s>
Criteria	O
are	O
helpful	O
to	O
train	O
neural	B-Architecture
network	I-Architecture
on	O
classical	O
tasks	O
.	O
</s>
<s>
Common	O
criteria	O
are	O
the	O
Mean	B-Algorithm
Squared	I-Algorithm
Error	I-Algorithm
criterion	O
implemented	O
in	O
MSECriterion	O
and	O
the	O
cross-entropy	O
criterion	O
implemented	O
in	O
ClassNLLCriterion	O
.	O
</s>
<s>
It	O
also	O
has	O
StochasticGradient	O
class	O
for	O
training	O
a	O
neural	B-Architecture
network	I-Architecture
using	O
Stochastic	B-Algorithm
gradient	I-Algorithm
descent	I-Algorithm
,	O
although	O
the	O
optim	O
package	O
provides	O
much	O
more	O
options	O
in	O
this	O
respect	O
,	O
like	O
momentum	O
and	O
weight	O
decay	O
regularization	O
.	O
</s>
<s>
Many	O
packages	O
other	O
than	O
the	O
above	O
official	O
packages	O
are	O
used	O
with	O
Torch	B-Algorithm
.	O
</s>
<s>
These	O
are	O
listed	O
in	O
the	O
torch	B-Algorithm
cheatsheet	O
.	O
</s>
<s>
They	O
can	O
be	O
installed	O
with	O
LuaRocks	B-Language
,	O
the	O
Lua	B-Language
package	O
manager	O
which	O
is	O
also	O
included	O
with	O
the	O
Torch	B-Algorithm
distribution	O
.	O
</s>
<s>
Torch	B-Algorithm
is	O
used	O
by	O
the	O
Facebook	O
AI	B-Application
Research	I-Application
Group	O
,	O
IBM	O
,	O
Yandex	O
and	O
the	O
Idiap	O
Research	O
Institute	O
.	O
</s>
<s>
Torch	B-Algorithm
has	O
been	O
extended	O
for	O
use	O
on	O
Android	B-Application
and	O
iOS	B-Application
.	O
</s>
<s>
It	O
has	O
been	O
used	O
to	O
build	O
hardware	O
implementations	O
for	O
data	O
flows	O
like	O
those	O
found	O
in	O
neural	B-Architecture
networks	I-Architecture
.	O
</s>
<s>
Facebook	O
has	O
released	O
a	O
set	O
of	O
extension	O
modules	O
as	O
open	B-Application
source	I-Application
software	I-Application
.	O
</s>
