Add preview of 1984-2019

The 2020 winners are hinted it, but the source code is not there,
nor are the hints. Someone could look into the HTML and
see what was commented out, but that is not a problem because
WHO won is known and the name of their AWARD is known already.
Moreover a number of the winners have talked about what their
entirs do, so the commented out spoiler text is not a bit problem.

One will find HTML commented out with:

    <!-- XXX remove when 2020 is ready
    2020 links here
    XXX remove when 2020 is ready -->

The "XXX remove when 2020 is ready" string is found at the
start and end comment blocks.  Again, soneone could read
what was commented out, but that is OK since most of that
information is known or can be known.  The following files
have such HTML comment blocks in them.

    ./winners.html
    ./years-spoiler.html
    ./years.html

In addition, ./all/summary.txt was modified to not
include the 2020 entries for the momemt.

The 2020 winner code AND write-ups are NOT part of this set.

p.s. The all/all.tar.bz2 does not contain the 2020 source code (yet?).
This commit is contained in:
Landon Curt Noll committed 2020-12-30 16:57:03 -08:00
1 parent 28efc67f5d
commit c0663537cb
1683 files changed
+220064

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+707
View File
@@ -0,0 +1,707 @@
#!/usr/bin/env make
#
# 2019 makefile
#
# This work by Landon Curt Noll, Simon Cooper, and Leonid A. Broukhis
# is licensed under:
#
# Creative Commons Attribution-ShareAlike 3.0 Unported License.
#
# See: http://creativecommons.org/licenses/by-sa/3.0/
#############################
# shell used by this Makefile
#############################
#
SHELL= /bin/bash
#######################
# common tool locations
#######################
#
A2P= a2p
AR= ar
ASA= asa
AT= at
ATQ= atq
ATRM= atrm
AWK= awk
BANNER= banner
BASE64= base64
BASENAME= basename
BATCH= batch
BC= bc
BINHEX= binhex
BISON= bison
BUNZIP2= bunzip2
BZCAT= bzcat
BZCMP= bzcmp
BZDIFF= bzdiff
BZEGREP= bzegrep
BZFGREP= bzfgrep
BZGREP= bzgrep
BZIP2= bzip2
BZLESS= bzless
BZMORE= bzmore
C2PH= c2ph
C89= c89
C99= c99
CAL= cal
CALC= calc
CAT= cat
CD= cd
CHFLAGS= chflags
CHGRP= chgrp
CHMOD= chmod
CKSUM= cksum
CLANG= clang
CLANG_PLUSPLUS= clang++
CLEAR= clear
CMP= cmp
COL= col
COLLDEF= colldef
COLRM= colrm
COLUMN= column
COMPRESS= compress
CP= cp
CPIO= cpio
CPP= cpp
CRC32= crc32
CSH= csh
CSPLIT= csplit
CURL= curl
CUT= cut
C_PLUSPLUS= c++
C_PLUSPLUS_FILT= c++filt
DATE= date
DC= dc
DD= dd
DF= df
DIFF3= diff3
DIFF= diff
DIG= dig
DIRNAME= dirname
ED= ed
EGREP= egrep
ENV= env
EQN= eqn
ETAGS= etags
EXPECT= expect
EXPR= expr
FALSE= false
FGREP= fgrep
FILE= file
FIND2PERL= find2perl
FIND= find
FLEX= flex
FLEX_PLUSPLUS= flex++
FMT= fmt
FOLD= fold
FS_USAGE= fs_usage
FUNZIP= funzip
FUSER= fuser
GCC= gcc
GDIFFMK= gdiffmk
GENCAT= gencat
GENSTRINGS= genstrings
GETOPT= getopt
GETOPTS= getopts
GNUMAKE= gnumake
GREP= grep
GROFF= groff
GROFFER= groffer
GROG= grog
GROPS= grops
GROTTY= grotty
GUNZIP= gunzip
GVIM= gvim
GZCAT= gzcat
GZEXE= gzexe
GZIP_PROG= gzip
G_PLUSPLUS= g++
H2PH= h2ph
H2XS= h2xs
HASH= hash
HEAD= head
HOSTNAME_PROG= hostname
ICONV= iconv
ID= id
INDENT= indent
INFO= info
JOT= jot
KILL= kill
KSH= ksh
LAST= last
LD= ld
LESSECHO= lessecho
LEX= len
LINK= link
LN= ln
LS= ls
M4= m4
MAKE= make
MAN= man
MKDIR= mkdir
MKFIFo= mkfifo
MKTEMP= mktemp
MV= mv
NANO= nano
NASM= nasm
NEQN= neqn
NICE= nice
NL= nl
NM= nm
NOHUP= nohup
NROFF= nroff
NSLOOKUP= nslookup
OD= od
OPENSSL= openssl
PASTE= paste
PATCH= patch
PATHCHK= pathchk
PAX= pax
PERL= perl
PICO= pico
PR= pr
PRINTENV= printenv
PS= ps
PTAR= ptar
PTARDIFF= ptardiff
PTARGREP= ptargrep
PWD= pwd
PYDOC= pydoc
PYTHON= python
PYTHONW= pythonw
READLINK= readlink
RENICE= renice
RESET= reset
REV= rev
RI= ri
RM= rm
RMDIR= rmdir
RSYNC= rsync
RUBY= ruby
RVIM= rvim
SAY= say
SCP= scp
SCREEN= screen
SCRIPT= script
SDIFF= sdiff
SED= sed
SEQ= seq
SFTP= sftp
SH= sh
SHA1= sha1
SHA= sha
SHAR= shar
SHASUM5_18= shasum5.18
SHASUM= shasum
SIZE= size
SLEEP= sleep
SORT= sort
SSH= ssh
STAT= stat
STRIP= strip
STTY= stty
SUM= sum
SYNC= sync
TABS= tabs
TAIL= tail
TAR= tar
TEE= tee
TEST= test
TFTP= tftp
TIDY= tidy
TIME= time
TOP= top
TOUCH= touch
TPUT= tout
TPUT= tput
TR= tr
TROFF= troff
TRUE= true
TSET= tset
TSORT= tsort
UL= ul
UNAME= uname
UNCOMPRESS= uncompress
UNEXPAND= unexpand
UNIFDEF= unifdef
UNIFDEFALL= unifdefall
UNIQ= uniq
UNITS= units
UNLINK= unlink
UNZIP= unzip
UNZIPSFX= unzipsfx
UPTIME= uptime
UUDECODE= uudecode
UUENCODE= uuencode
UUIDGEN= uuidgen
VI= vi
VIEW= view
VIM= vim
VIMDIFF= vimdiff
W= w
WAIT4PATH= wait4path
WAIT= wait
WC= wc
WHAT= what
WHATIS= whatis
WHICH= which
WHO= who
WHOAMI= whoami
WHOIS= whois
WRTIE= write
XAR= xar
XARGS= xargs
XATTR= xattr
XXD= xxd
YACC= yacc
YES= yes
ZCAT= zcat
ZCMP= zcmp
ZDIFF= zdiff
ZEGREP= zegrep
ZFGREP= zfgrep
ZFORCE= zforce
ZGREP= zgrep
ZIP= zip
ZIPCLOAK= zipcloak
ZIPGREp= zipgrep
ZIPINFo= zipinfo
ZIPNOTE= zipnote
ZIPSPLIT= zipsplit
ZLESS= zless
ZMORE= zmore
ZNEW= znew
ZPRINT= zprint
ZSH= zsh
# Set X11_LIBDIR to the directory where the X11 library resides
#
#X11_LIBDIR= /usr/X11R6/lib
#X11_LIBDIR= /usr/X11/lib
X11_LIBDIR= /opt/X11/lib
# Set X11_INCLUDEDIR to the directory where the X11 include files reside
#
#X11_INCDIR= /usr/X11R6/include
#X11_INCDIR= /usr/X11/include
X11_INCDIR= /opt/X11/include
# Compiler warnings
#
#CWARN=
#CWARN= -Wall
#CWARN= -Wall -Wextra
CWARN= -Wall -Wextra -pedantic ${CSILENCE}
#CWARN= -Wall -Wextra -Weverything
#CWARN= -Wall -Wextra -Weverything -pedantic
#CWARN= -Wall -Wextra -Weverything -pedantic ${CSILENCE}
# Silence warnings that ${CWARN} would normally complain about
#
#CSILENCE=
#CSILENCE= -Wno-implicit-int
CSILENCE= -Wno-missing-field-initializers -Wno-for-loop-analysis
# compiler standard
#
#CSTD=
#CSTD= -ansi
CSTD= -std=c11
# compiler bit architecture
#
# Some entries require 32-bitness:
# ARCH= -m32
#
# Some entries require 64-bitness:
# ARCH= -m64
#
# By default we assume nothing:
#
ARCH=
# defines that are needed to compile
#
#CDEFINE=
#CDEFINE= -DIOCCC=26
CDEFINE= ${param}
# include files that are needed to compile
#
CINCLUDE=
#CINCLUDE= -include stdlib.h
#CINCLUDE= -include stdio.h
#CINCLUDE= -include stdlib.h -include stdio.h
#CINCLUDE= -I ${X11_INCDIR}
# optimization
#
# Most compiles will safely use -O2. Some can use only -O1 or -O.
# A few compilers have broken optimizers or this entry make break
# under those buggy optimizers and thus you may not want anything.
# Reasonable compilers will allow for -O3.
#
#OPT=
#OPT= -O
#OPT= -O1
#OPT= -O2
OPT= -O3
# default flags for ANSI C compilation
#
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
# Libraries needed to build
#
#LIBS=
#LIBS= -L ${X11_LIBDIR}
LIBS= -lm
# ANSI compiler
#
# Set CC to the name of your ANSI compiler.
#
# Some entries seem to need gcc. If you have gcc, set
# both CC and MAY_NEED_GCC to gcc.
#
# If you do not have gcc, set CC to the name of your ANSI compiler, and
# set MAY_NEED_GCC to either ${CC} (and hope for the best) or to just :
# to disable such programs.
#
CC= cc
#CC=clang
MAY_NEED_GCC= gcc
##############################
# Special flags for this entry
##############################
#
OBJ= prog.o
INPUTS_GZ= IOCCC-hints.txt.gz Shakespeare.txt.gz \
IOCCC-Rules-Guidelines.txt.gz Eugene_Onegin.txt.gz
INPUTS= IOCCC-hints.txt Shakespeare.txt \
IOCCC-Rules-Guidelines.txt Eugene_Onegin.txt
CPFILES= IOCCC-hints.cp09_1.809 Shakespeare.cp04_1.633 \
IOCCC-Rules-Guidelines.cp98_0.175 Eugene_Onegin.cp11_1.188
OUTPUTS= IOCCC-hints.output.txt Shakespeare.output.txt \
IOCCC-Rules-Guidelines.output.txt Eugene_Onegin.output.txt
DATA= ${CPFILES} ${INPUTS_GZ} ${CPFILES}
TARGET = lin1 per1 rnn1 rnn2 rnn3 lstm1 lstm2 lstm3 lstmp1 lstmp2 lstmp3 \
rlstm1 rlstm2 rlstm3 gru1 gru2 gru3 prog
#
ALT_OBJ=
ALT_TARGET=
# hyperparameters
param = -DRS=.15 -DTR=.95 -DLR=.002 -DLD=.97 -DLE=10 -DCL=5 -DB1=.9 -DB2=.999 \
-DEP=1e-8 -DWD=8e-5 -DDI=100 -DSL=200 -DN=50 -DTP=1 \
-DPF='"cp%02d_%.3f"'
##############################################################
# Networks
#
# Note that temp variables have been added to force evaluation
# order. This allows checkpoint files to be portable beetween
# different compilers.
##############################################################
# linear
lin = -DBK='y=x'
# perceptron
per = -DBK='y=T(x)'
# recurrent neural network
rnn = -DHS=128 -DBK=' \
hp = I(HS), \
t1 = L(HS, x), \
h = C(hp, T(A(t1, L(HS, hp)))), \
y = h \
'
# long short term memory
lstm = -DHS=128 -DBK=' \
cp = I(HS), \
hp = I(HS), \
t1 = L(HS, x), \
f = S(A(t1, L(HS, hp))), \
t2 = L(HS, x), \
i = S(A(t2, L(HS, hp))), \
t3 = L(HS, x), \
cn = T(A(t3, L(HS, hp))), \
t4 = M(f, cp), \
c = C(cp, A(t4, M(i, cn))), \
t5 = L(HS, x), \
o = S(A(t5, L(HS, hp))), \
h = C(hp, M(o, T(c))), \
y = h \
'
# lstm with passthrough
lstmp = -DHS=128 -DBK=' \
cp = I(HS), \
hp = I(HS), \
t1 = L(HS, x), \
t2 = A(t1, L(HS, hp)), \
f = S(A(CM(cp), t2)), \
t3 = L(HS, x), \
t4 = A(t3, L(HS, hp)), \
i = S(A(CM(cp), t4)), \
t5 = L(HS, x), \
cn = T(A(t5, L(HS, hp))), \
t6 = M(f, cp), \
c = C(cp, A(t6, M(i, cn))), \
t7 = L(HS, x), \
t8 = A(t7, L(HS, hp)), \
o = S(A(CM(c), t8)), \
h = C(hp, M(o, T(c))), \
y = h \
'
# residual lstm
rlstm = -DHS=128 -DBK=' \
cp = I(HS), \
hp = I(HS), \
t1 = L(HS, x), \
t2 = A(t1, L(HS, hp)), \
f = S(A(CM(cp), t2)), \
t3 = L(HS, x), \
t4 = A(t3, L(HS, hp)), \
i = S(A(CM(cp), t4)), \
t5 = L(HS, x), \
cn = T(A(t5, L(HS, hp))), \
t6 = M(f, cp), \
c = C(cp, A(t6, M(i, cn))), \
t7 = L(HS, x), \
t8 = A(t7, L(HS, hp)), \
o = S(A(CM(c), t8)), \
m = L(HS, T(c)), \
h = C(hp, M(o, A(m, L(HS, x)))), \
y = h \
'
# gated recurrent unit
gru = -DHS=128 -DBK=' \
hp = I(HS), \
t1 = L(HS, x), \
z = S(A(t1, L(HS, hp))), \
t2 = L(HS, x), \
r = S(A(t2, L(HS, hp))), \
t3 = L(HS, x), \
c = T(A(t3, L(HS, M(r, hp)))), \
zc = OG(1, -1, z), \
t4 = M(zc, hp), \
h = C(hp, A(t4, M(z, c))), \
y = h \
'
# single-layer network
one_layer = -DNW=' \
x = I(n), \
y = L(n, MD(x)) \
'
# two-layer network
two_layer = -DNW=' \
x = I(n), \
y = L(n, MD(MD(x))) \
'
# three-layer network
three_layer = -DNW=' \
x = I(n), \
y = L(n, MD(MD(MD(x)))) \
'
# Enumerated list of networks
#
lin1 = ${lin} ${one_layer}
per1 = ${per} ${one_layer}
rnn1 = ${rnn} ${one_layer}
rnn2 = ${rnn} ${two_layer}
rnn3 = ${rnn} ${three_layer}
lstm1 = ${lstm} ${one_layer}
lstm2 = ${lstm} ${two_layer}
lstm3 = ${lstm} ${three_layer}
lstmp1 = ${lstmp} ${one_layer}
lstmp2 = ${lstmp} ${two_layer}
lstmp3 = ${lstmp} ${three_layer}
rlstm1 = ${rlstm} ${one_layer}
rlstm2 = ${rlstm} ${two_layer}
rlstm3 = ${rlstm} ${three_layer}
gru1 = ${gru} ${one_layer}
gru2 = ${gru} ${two_layer}
gru3 = ${gru} ${three_layer}
# default network
#
prog = ${rnn1}
#################
# build the entry
#################
#
all: ${TARGET} ${DATA}
@${TRUE}
${TARGET}: prog.c Makefile ${INPUTS}
${CC} ${CFLAGS} -o $@ $< $($@) ${LIBS}
# alternative executable
#
alt: ${ALT_TARGET}
@${TRUE}
# data files
#
data: ${DATA}
@${TRUE}
${INPUTS}: %.txt: %.txt.gz
${ZCAT} < $< > $@
test: ${OUTPUTS}
# First 1000 lines of generated output
#
generator = ./lstm2
test-64bit: IOCCC-hints.output.txt IOCCC-Rules-Guidelines.output.txt Shakespeare.output.txt Eugene_Onegin.output.txt
IOCCC-hints.output.txt: IOCCC-hints.cp09_1.809 ${generator}
${generator} < $< | ${HEAD} -n 1000 > $@
Shakespeare.output.txt: Shakespeare.cp04_1.633 ${generator}
${generator} < $< | ${HEAD} -n 1000 > $@
IOCCC-Rules-Guidelines.output.txt: IOCCC-Rules-Guidelines.cp98_0.175 ${generator}
${generator} < $< | ${HEAD} -n 1000 > $@
Eugene_Onegin.output.txt: Eugene_Onegin.cp11_1.188 ${generator}
${generator} < $< | ${HEAD} -n 1000 > $@
###############
# utility rules
###############
#
everything: all alt
clean:
${RM} -f ${OBJ} ${ALT_OBJ}
cpclean:
${RM} -f cp*_*.*
clobber: clean cpclean
${RM} -f ${TARGET} ${ALT_TARGET}
${RM} -f ${INPUTS}
${RM} -f ${OUTPUTS}
@-if [ -e sandwich ]; then \
${RM} -f sandwich; \
echo 'ate sandwich'; \
fi
nuke: clobber
@${TRUE}
dist_clean: nuke
@${TRUE}
install:
@echo "Surely you are performing, Dr. May!"
@${TRUE}
# backwards compatibility
#
build: all
@${TRUE}
##################
# 133t hacker rulz
##################
#
love:
@echo 'not war?'
@${TRUE}
haste:
$(MAKE) waste
@${TRUE}
waste:
@echo 'haste'
@${TRUE}
make:
@echo 'Attend a maker faire'
@${TRUE}
easter_egg:
@echo you expected to often mis-understand this $${RANDOM} magic
@echo chongo '<was here>' "/\\oo/\\"
@echo Eggy
fabricate fashion form frame manufacture produce: make
@${TRUE}
sandwich:
@if [ `id -u` -eq 0 ]; then \
echo 'Okay.'; \
echo $${RANDOM}`date +%s`$${RANDOM} > $@; \
else \
echo 'What? Make it yourself.'; \
exit 1; \
fi
# Understand the history of the Homebrew Computer Club
# as well as the West Coast Computer Faire and
# you might be confused different. :-)
#
supernova: nuke
@-if [ -r .code_anal ]; then \
${RM} -f .code_anal_v6; \
else \
echo "planet deniers, like some members of the IAU, are so cute when they try to defend their logic"; \
fi
@echo A $@ helps ${MAKE} the elements that help form planets
@${TRUE}
deep_magic:
@-if [ -r .code_anal ]; then \
ccode_analysis --deep_magic fc6b6af226b7cc598de3d48fc20ed0bd54f7b4f7f0f651a32b9cf8345b2a3b3f --FNV1a_hash_512_bit "prog"; \
else \
echo "Wrong! Do it again!"; \
sleep 2; \
echo "Wrong! Do it again!"; \
sleep 2; \
echo "Wrong! Do it again!"; \
fi
@${TRUE}
magic: deep_magic
@-if [ -r .code_anal ]; then \
ccode_analysis --level 391581 --mode 216193 --FNV1a_hash_512_bit "prog"; \
else \
echo "If you don't eat yer meat, you can't have any pudding!"; \
echo "How can you have any pudding if you don't eat yer meat?!"; \
fi
@${TRUE}
# The IOCCC resident astronomer states
#
charon: supernova
@echo $@ is a dwarf planet
@echo dwarf is a type of planet
@echo therefore IAU, $@ is a planet
pluto: supernova
${MAKE} charon
@echo $@ is a dwarf planet
@echo dwarf is a type of planet
@echo therefore, $@ is a planet
@echo get used to having lots of planets because a $< can ${MAKE} a lot of them
Binary file not shown.
Binary file not shown.
+659
View File
@@ -0,0 +1,659 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR" content="mkd2html 2.2.0">
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8"> <link rel="stylesheet"
type="text/css"
href="../hint.css">
<title>Most in need to be tweeted</title>
</head>
<body>
<h1>Most in need to be tweeted</h1>
<p>Christopher Mills<br>
Twitter: @MisterXopher</p>
<h2>Judges' comments:</h2>
<h3>To use:</h3>
<pre><code>make
make cpclean
# Let this run for about about an hour and then kill it
./prog Shakespeare.txt
./prog &lt; $(&lt; ls -1tr cp* | tail -1) | head -100
</code></pre>
<h3>Try:</h3>
<pre><code># If you are on a 64-bit system:
make test-64bit
less IOCCC-Rules-Guidelines.output.txt
less IOCCC-hints.output.txt
less Eugene_Onegin.output.txt
# However, as the binary model files used to produce the output are in an implementation-specific format,
# your mileage may vary.
</code></pre>
<h3>Selected Judges Remarks:</h3>
<p>Can a machine learn?</p>
<p>Some say so.</p>
<p>But can a machine learn to write like Shakespeare,</p>
<p>or tweet like <a href="http://trumptwitterarchive.com">Trump</a>?</p>
<p>Can it write rules and guidelines for the IOCCC?</p>
<p>You decide. :-)</p>
<h2>Author&rsquo;s comments:</h2>
<h1>Welcome to OMLET! &#x1f373;</h1>
<p>OMLET is the <em>Obfuscated Machine Learning Environment Toolkit</em>, a
micro-framework for experimenting with <a href="https://en.wikipedia.org/wiki/Recurrent_neural_network">recurrent neural networks</a>. OMLET
lets you build, train and evaluate <a href="https://en.wikipedia.org/wiki/Deep_learning">deep neural networks</a>. Why invest
hours reading documentation and megabytes of disk space on a full-featured DNN
framework like <a href="https://www.tensorflow.org">TensorFlow</a> or <a href="http://torch.ch">Torch</a> when you can have full RNN
functionality in less than 4 KB!</p>
<p>OMLET has the following features:</p>
<ul>
<li>User-programmable network configurations and hyperparameters</li>
<li>Support for various types of recurrent and feed-forward neural networks
including vanilla RNNs, LSTMs and GRUs of depths of up to 99 layers</li>
<li>No limit on parameter size (except for those imposed by the system)</li>
<li>Training and inference modes, with periodic checkpointing</li>
<li>Advanced <a href="https://arxiv.org/abs/1412.6980">Adam</a> optimizer with <a href="https://www.fast.ai/2018/07/02/adam-weight-decay/">weight decay</a> for simplified
training</li>
<li>Hyperparamer support for batch sizing, learning rate schedule, weight
decay and gradient clipping</li>
<li>Easily extensible (requires some expertise in the C programming language)</li>
<li>Friendly markdown documentation</li>
</ul>
<p>OMLET is based on <a href="https://cs.stanford.edu/people/karpathy/">Andrej Karpathy&rsquo;s</a> <a href="https://github.com/karpathy/char-rnn">character-level language model</a>
as described in his blog post <a href="http://karpathy.github.io/2015/05/21/rnn-effectiveness/"><em>The Unreasonable Effectiveness of Recurrent
Neural Networks</em></a>. I&rsquo;ve included a small sample dataset to use for
training, but you can have even more fun by downloading some larger datasets:</p>
<ul>
<li><a href="https://cs.stanford.edu/people/karpathy/char-rnn/linux_input.txt">Linux kernel source</a></li>
<li><a href="https://cs.stanford.edu/people/karpathy/char-rnn/warpeace_input.txt"><em>War and Peace</em></a></li>
<li><a href="https://github.com/ryanmcdermott/trump-speeches">Donald Trump&rsquo;s 2016 campaign speeches</a></li>
</ul>
<h2>Getting started with OMLET</h2>
<p>OMLET has three operating modes:</p>
<ul>
<li><em>Training</em>, which trains a network from scratch</li>
<li><em>Continuation</em>, which trains starting from an existing checkpoint</li>
<li><em>Inference</em>, which uses an existing trained network to make predictions</li>
</ul>
<p>For your first OMLET experiment, we will try training a simple single-level
RNN to write some <a href="https://en.wikipedia.org/wiki/William_Shakespeare">Shakespere</a> plays. Start by typing</p>
<pre><code>make
</code></pre>
<p>After it builds, train it using</p>
<pre><code>./prog shakespere.txt
</code></pre>
<p>This will immediately start outputting gibberish to the output, e.g.</p>
<pre><code>./prog shakespere.txt
sins ohennAu
T-teooclelp tiThoWy
g
nlakuafy
e
sselW usnsofueB Aoee pasfUsuslhe ooM ot Wou moy
me neltAl -no IoyI mhuyakse inT-l chu ghenn ffo? fnsoe yhyye
ue nnfrlass heUthole saounlcesyee pee
t,
T0:0% 3.210888
o',,vU
An ,hTf lnm Far rur:s moilt WoEgrv wonds mith Aog thernw
Rni So
co Nnd :
For an bImy pgafoun:
Wf'r hom wortiverita
int fod mous Eheledet,
Tho he theket nonS wnu-ang dorlaMSp
nrocWiSe tflg 'o.
T0:0% 2.995950
d whecedhencrysesil yr bn,
we hh y thiwt
hut fithlot,
Fmdy s he alt
Vh th no dh foud bobt werw:s Aotnf Fhwi't whe, eusu
lhh thele wewcond ary soupfy wind tDont couc ths:
er fucwald oncli hen bos, f
T0:1% 2.878945
</code></pre>
<p>The gibberish is the networks attempt to write a play. So far, it&rsquo;s not very
successful! Between the chunks of gibberish are training progress reports
that look like</p>
<pre><code>T0:1% 2.878945
</code></pre>
<p>This tells you that we are 1% through training epoch 0, and that the training
<a href="https://en.wikipedia.org/wiki/Loss_function">loss</a> is about 2.88. As the training continues, the training loss will
reduce and the generated snippets will improve quickly:</p>
<pre><code>ses, kuth
LAs of the wish,
As, I nos you,
Yov not to nalll,
Tr tot wonds.
First Sondy, llt lrte, our, tw.
First.
BRUTUS:
Helsting the kith gops of hoch Whay, fars surd what to,
The cownens golt te.
T0:12% 2.259114
eplerrotrur tandans one wiok thy or thach and cullice ded yourssting
And wours:
Whed ur surt.
SINENIUS:
On we lain bith
rerytund: tich lon hyivetetgor.
VOLUONIA:
He brich nom dove worthan then wise,
T0:13% 2.254926
</code></pre>
<p>It&rsquo;s already started to figure out things about Shakespere plays &ndash; how to
spell short English words, how long lines tend to be, and that characters take
turns speaking with their names capitalized. The training loss has dropped to
2.25 and the improvement is noticeable.</p>
<p>Eventually, we will finish with the training data set and move on to a
validation cycle:</p>
<pre><code>y fath onother,
I sucess,
For I me the west crare.
TRANIO:
Whow and'd have not to had you you one in my lapteny she very ame come me a gut and shourd aghir you as ignested; shend to make I strem
To h
T0:99% 1.924063
notnce gaud and is nicked thou day, ha the dusing you disaid: in thim, you things in ere thee thus erile Iht that tare theme my hast thesp thou shay: thou not eaten-or-ho-bess resing: I the but had d
T0:99% 1.923128
V0:0% 1.678907
V0:9% 1.700527
V0:18% 1.733179
V0:27% 1.714891
V0:36% 1.716672
V0:45% 1.782946
V0:54% 1.835629
V0:63% 1.876108
V0:72% 1.906814
V0:81% 1.924096
V0:90% 1.954492
V0:99% 1.969287
serfs you'll alliencseard:
We
got you? before
I say.
Farstred dentlentecaly, sir, I it one bosticield
All me the backnour mino,
Whith capitaned mid! but stell the ifvemion
Willerity.
First Cumfol of
T1:0% 1.885619
</code></pre>
<p>Validation cycles are used to test the network to see if it has learned to
generalize &ndash; how well performs on data it hasn&rsquo;t seen before (as opposed to
the training data that the network will see many times as it trains). Progress
on the validation set is also displayed with a validation progress report that
looks like</p>
<pre><code>V0:36% 1.716672
</code></pre>
<p>which means we are 36% of the way through the validation for epoch 0, and the
validation loss is about 1.72. Comparing the validation loss and the
training loss will give you an idea of how well the network is learning and
can let you know if the network is <a href="https://en.wikipedia.org/wiki/Overfitting">overfitting or underfitting</a>.</p>
<p>As part of the training process, the data set (which for OMLET is the
<code>shakespere.txt</code> file you gave on the command line) is divided into
<a href="https://en.wikipedia.org/wiki/Training,_validation,_and_test_sets">training and validation sets</a> (by default, 95% of the data is used for
training, but like most OMLET parameters, you can change this at compile-time).</p>
<p>At the end of the validation run, OMLET writes out a checkpoint file with a
name like <code>cp01_1.970</code>. This saves the state of the run at the start of the
epoch 1, after computing a validation loss of 1.970. The checkpoint is
helpful if you need to stop and restart training. You can stop training by
doing <code>Control-C</code>.</p>
<p>You can continue training from a previous checkpoint by providing the
checkpoint file name as the second parameter, for example:</p>
<pre><code>./prog shakespere.txt cp01_1.970
</code></pre>
<p>After the validation cycle finishes, OMLET begins the next epoch by restarting
training at the beginning of the training set. Training continues forever,
until you quit it with <code>Control-C</code>. You should monitor the checkpoints to
see that the validation loss continues to drop. If it rises, the network has
probably started to overfit on the training data.</p>
<p>Once you&rsquo;ve trained the validation loss as low as it will go, you can use
OMLET to run the network in inference mode which uses the frozen checkpoint
parameters to generate data. Inference mode takes the checkpoint file as
<em>standard input</em> (not on the command line) and hence must be run with a
command like</p>
<pre><code>./prog &lt; cp55_1.807
</code></pre>
<p>Running it produces an infinite amount of generated output, until you hit
<code>Control-C</code> to stop it.</p>
<p>Note that if you decide to change networks or use a different input file, you
will want to delete all the checkpoint files because the format depends on
both the network and the input &ndash; using the wrong checkpoint is likely to
cause a crash.</p>
<h2>Experimenting with different networks</h2>
<p>The default network for OMLET (the one you get if you type <code>make</code> with the
executable name <code>prog</code>) is the simplest recurrent neural network. It looks
like</p>
<pre><code>h = tanh(Wxh * x + Whh * h' + Bh)
y = Why * h + By
</code></pre>
<p>where</p>
<ul>
<li><code>x</code> is the <em>input vector</em></li>
<li><code>y</code> is the <em>output vector</em></li>
<li><code>h</code> is the <em>hidden state vector</em></li>
<li><code>h'</code> is the previous value of <code>h</code></li>
<li><code>Wxh</code>, <code>Whh</code>, and <code>Why</code> are <em>weight matrices</em></li>
<li><code>Bh</code> and <code>By</code> are <em>bias vectors</em>.</li>
<li><code>tanh</code> is the <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">hyperbolic tangent function</a></li>
</ul>
<p>The <code>W</code>&rsquo;s and <code>B</code>&rsquo;s are the trainable parameters of the network, and the
process of training is optimizing the values of these parameters to minimize
the loss of the network across the training set.</p>
<p>It is the presence of the hidden state vector that allows the RNN to
&ldquo;remember&rdquo; the past. We can see what would happen if we removed this hidden
state. If you type</p>
<pre><code>make lin1
</code></pre>
<p>OMLET will create an <a href="https://en.wikipedia.org/wiki/ADALINE">ADALINE</a> network that does</p>
<pre><code>y = Wxy * x + By
</code></pre>
<p>This simple <a href="https://en.wikipedia.org/wiki/Linear_map">linear</a> <a href="https://en.wikipedia.org/wiki/Feedforward_neural_network">feed-forward network</a>. You can run it with</p>
<pre><code>./lin1 shakespeare.txt
</code></pre>
<p>The linear network won&rsquo;t be able to get past the gibberish stage, because it
lacks history:</p>
<pre><code>./lin1 shakespeare.txt
UERond w,
Gir:
KINof s, mesther s thouth.
E:
KINTret, at fu,
GOMy t, as sth kesewit sooos atse ang k, ck,
Sotheouserivesthecowhet been's, t he, h nre; t and, har wiread of pincer cedst sur has, ut:
T14:67% 2.465115
UKESpan,
NGaromy soreate e m esewfoure pamitherarjulthengeoly tl.
NG s at e! w.
WAllinoully?
Wamisw ofilem:
I'delandinarrstath har aksubly s cath Whern t Is, weciss:
GLat s; llde.
Y aterit dsthence
T14:67% 2.465404
</code></pre>
<p>It is able to guess at what character is likely to follow the current one
(by doing a <a href="https://en.wikipedia.org/wiki/Linear_regression">linear regression</a>), but it lacks any history beyond that to
guide it.</p>
<p>You might be wondering about the role of the <code>tanh</code> function in the RNN.
<code>tanh</code> acts as an <a href="https://en.wikipedia.org/wiki/Activation_function">activation function</a> which adds <a href="https://en.wikipedia.org/wiki/Nonlinear_system">nonlinearity</a>
to the network and allows it to solve complicated problems. Without
nonlinearity, all of the linear functions would fold together into a single
matrix-vector multiply and you&rsquo;d effectively regress to the linear network
above. Alas, even adding a nonlinearity to the feed-forward network
(creating a <a href="https://en.wikipedia.org/wiki/Perceptron">perceptron</a>) does not improve the performance because we
still lack the history provided by the hidden state vector (although if you
want to try it yourself, you can do so with <code>make per1</code>).</p>
<h2>Going deeper</h2>
<p>We can try to improve the RNN&rsquo;s performance by stacking RNN modules atop each
other:</p>
<pre><code>h1 = RNN(h1', x)
h2 = RNN(h2', h1)
y = Why * h2 + By
</code></pre>
<p>with <code>RNN(h, x)</code> defined as above. Each RNN module has its own set of
parameters and its own hidden state vector. This will improve the network&rsquo;s
performance, at the cost of a much larger parameter space</p>
<blockquote><p><strong>IMPORTANT NOTE</strong>: Since OMLET uses the system stack for network storage,
larger networks may cause OMLET to crash (typically with a message like
<code>Segmentation fault</code>) unless the system stack size is first increased.
The exact command for doing so depends on your shell and your system&rsquo;s
hard limits. On <code>sh</code>/<code>ksh</code>/<code>bash</code> shells, you can view the hard limit
with <code>ulimit -Hs</code> and set it with <code>ulimit -s 65532</code> (replacing <code>65532</code>
with the actual hard limit). On <code>csh</code>/<code>tcsh</code> shells, you can view
the hard limit with <code>limit -h stacksize</code> and set it with
<code>limit stacksize 65532</code> (replacing <code>65532</code> with the actual hard limit).</p></blockquote>
<p>You can try the deeper network by doing</p>
<pre><code>make rnn2
</code></pre>
<p>(or even <code>make rnn3</code> if you want a three-layer RNN) and train it with</p>
<pre><code>./rnn2 shakespeare.txt
</code></pre>
<p>The additional depth should allow the network to make better predictions (it
can represent more complicated history), but it may take a long time to train
&ndash; both because the network (being larger) now requires more time to train and
because of the <a href="https://en.wikipedia.org/wiki/Vanishing_gradient_problem">vanishing and exploding gradient problem</a>, which might
keep it from ever reaching its potential.</p>
<h2>LSTMs and GRUs</h2>
<p>RNNs are particularly hard to train because the they are trained using
<a href="https://en.wikipedia.org/wiki/Backpropagation_through_time">bankpropagation through time</a>. The RNN is trained by effectively
converting it into a non-recurrent network by making many copies of it
and propagating the hidden state through the copies. During training,
the backpropagation through many clones of the network amplifies the
gradient, worsening the exploding and vanishing gradient problem.</p>
<p><a href="https://en.wikipedia.org/wiki/Long_short-term_memory">Long Short Term Memory</a> networks (also called LSTMs) were developed to
solve this problem. Christopher Olah gives a good description of them
at his <a href="http://colah.github.io/posts/2015-08-Understanding-LSTMs/">blog posting</a>. You can build a two-level LSTM by doing</p>
<pre><code>make lstm2
</code></pre>
<p>and train with it with</p>
<pre><code>./lstm2 shakespeare.txt
</code></pre>
<p>The LSTM is much easier to train because it explicitly decides how to update
its hidden state via &ldquo;gates&rdquo;. These gates are called</p>
<ul>
<li><em>input gate</em>, which decides what part of the input to pay attention to</li>
<li><em>forget gate</em>, which decides what part of the hidden state to forget</li>
<li><em>output gate</em>, which decides what part of the hidden state is used to
produce the output</li>
</ul>
<p>The basic LSTM equations are</p>
<pre><code>f = sigmoid(Wxf * x + Whf * h' + Bf)
i = sigmoid(Wxi * x + Whi * h' + Bi)
o = sigmoid(Wxo * x + Who * h' + Bo)
c = f * c' + i * tanh(Wxc * x + Whc * h' + Bc)
h = o * tanh(c)
</code></pre>
<p>Where</p>
<ul>
<li><code>x</code> is the input vector</li>
<li><code>h</code> is the hidden state (and the output to the next layer)</li>
<li><code>c</code> is the <em>cell state</em> which represents the &ldquo;memory&rdquo; of the LSTM</li>
<li><code>h'</code> and <code>c</code>&lsquo; are the previous values of <code>h</code> and <code>c</code> respectively</li>
<li><code>f</code> is the <em>forget gate</em> that tells the LSTM what portion of the hidden
state to forget</li>
<li><code>i</code> is the <em>input gate</em> that tells the LSTM what portion of the input
vector to pay attention to</li>
<li><code>o</code> is the <em>output gate</em> that tells the LSTM what portion of the cell
state to use to generate the hidden state</li>
<li><code>Wxf</code>, <code>Whf</code>, <code>Wxi</code>, <code>Whi</code>, <code>Wxo</code>, <code>Who</code>, <code>Wxc</code>, and <code>Whc</code> are trainable
parameter matrices</li>
<li><code>Bf</code>, <code>Bi</code>, <code>Bo</code>, and <code>Bc</code> are trainable bias vectors</li>
<li><code>tanh</code> is the hyperbolic tangent function</li>
<li><code>sigmoid</code> is the <a href="https://en.wikipedia.org/wiki/Logistic_function">logistic function</a></li>
</ul>
<p>There are several LSTM variants (see <a href="http://colah.github.io/posts/2015-08-Understanding-LSTMs/">C. Olah&rsquo;s blog post</a> for more
examples). One important one is the <a href="https://en.wikipedia.org/wiki/Gated_recurrent_unit">gated recurrent unit</a>. GRUs are
simplified versions of an LSTM which combine the gates together, meaning they
require fewer learned parameters. This allows them to train faster than a
generic LSTM. You can build a two-layer GRU with</p>
<pre><code>make gru2
</code></pre>
<h2>Building your own networks</h2>
<p>The OMLET <code>Makefile</code> comes with one-, two- and three-layer RNNs, LSTMs and
GRUs, along with simpler feed-forward networks like multi-layer perceptrons and
a linear network. This isn&rsquo;t the limit of OMLET&rsquo;s power &ndash; you can create your
own networks by modifying the <code>Makefile</code>. Networks are passed in on the
compiler&rsquo;s command-line by using <code>-D</code> directives. The network is defined by
a <code>-DNW='...'</code> command which consists of a series of comma-separated
assignments. For example, the simple one-layer RNN could be defined like</p>
<pre><code>-DNW=` x = I(n), hp = I(128), \
h = C(hp, T(A(L(128, x), L(128, hp)))), \
y = L(n, h)'
</code></pre>
<p>The network declares <code>x</code> as an input vector (there must be a declaration for
<code>x</code>). It is declared as <code>I(n)</code>, which is an input vector of size <code>n</code>, which
is the number of characters of the input alphabet (OMLET computes this from
the input file at the start of training). OMLET will arrange to present the
input character as a <a href="https://en.wikipedia.org/wiki/One-hot">one-hot</a> vector based on the current input
character.</p>
<p>The second declaration, <code>hp</code>, declares the previous hidden state vector (what
we called <code>h'</code> above). We declare this to be of size 128 &ndash; an arbitrary
choice. A larger state vector can (theoretically) carry more state, but at
a cost of larger parameter matrices and longer training time. You can
experiment with increasing the hidden vector size and see.</p>
<p>The third line is the core of the RNN. It sets <code>h</code>, the hidden vector output
to be the sum of two linear elements specified by <code>L</code>. The <code>L</code> function
takes two parameters &ndash; the output vector size (which must match the size of
<code>h</code>) and the input vector. <code>L</code> will compute <code>y = W * x + B</code> where each <code>L</code>
has its own <code>W</code> (weight) and <code>B</code> (bias) training parameters. Both <code>x</code> and
<code>hp</code> are sent through <code>L</code> and the result passed through the <code>A</code> function,
which does vector addition. That result is passed through <code>T</code> which does
element-wise <code>tanh</code> activation.</p>
<p>Next, we wrap the whole thing with the <code>C</code> function. <code>C</code> connects <code>hp</code>
with <code>h</code>, causing the new value of <code>h</code> to be passed to the <code>hp</code> vector on
the next iteration of the algorithm (allowing the RNN to retain state in <code>h</code>).</p>
<p>Finally, the whole result is passed through another instance of <code>L</code>, this time
producing a vector of size <code>n</code>, which will have the negative log
<a href="https://en.wikipedia.org/wiki/Likelihood_function">likelihood</a> function. This is assigned to <code>y</code>, which is the output of
the network (and hence must also be declared).</p>
<p>OMLET will take the <code>y</code> result and pass it through the <a href="https://en.wikipedia.org/wiki/Softmax_function">softmax</a> function,
which converts the log probabilities into a probability distribution. In
inference mode, this is used to select the next character to emit. In
training mode, this is used to generate the loss which is backpropagated.</p>
<p>As an example of a more complicated network, we can look at a two-layer
GRU network:</p>
<pre><code>-DHS=128, \
-DNW=' x = I(n), \
y = L(n, MD(MD(x)))' \
-DBK=' hp = I(HS), \
z = S(A(L(HS, x), L(HS, hp))), \
r = S(A(L(HS, x), L(HS, hp))), \
c = T(A(L(HS, x), L(HS, hp))), \
zc = OG(1, -1, z), \
h = C(hp, A(M(zc, hp), M(z, c))), \
y = h'
</code></pre>
<p>We are using a few new tricks here &ndash; first, we are defining <code>HS</code> as the size
of the hidden and cell vectors. There&rsquo;s nothing special about this name, its
just convenient to specify it so we don&rsquo;t have a bunch of constants in the
code. Second, the network itself is very simple &ndash; it declares <code>x</code> and has
the matrix that converts the <code>HS</code>-sized hidden vector back to the <code>n</code>-sized
alphabet vector&hellip; but it now calls <code>MD</code>, which is the user-definable
module (here we are using it twice, to have two cascaded GRU blocks). The
<code>MD</code> function performs the sub-network defined by the <code>BK</code> compile-time
parameter (specified in the <code>-DBK='...'</code> setting). This sub-module again
takes an <code>x</code> parameter and produces a <code>y</code> output. Inside it, we declare
<code>hp</code> and <code>h</code>, the previous and current state vector, plus equations for the
various GRU gates (these use <code>S</code> for the sigmoid activation function).
One final new call is <code>OG</code> which does offset and gain, performing
<code>y = offset + gain * x</code> where <code>offset</code> (the first parameter) and <code>gain</code> (the
second) are constants. We are using this here to compute <code>(1 - z)</code> for the
GRU&rsquo;s linear interpolator.</p>
<p>The full set of available function blocks follows:</p>
<ul>
<li><code>I(s)</code>: declares a vector (input or state) of size <code>s</code></li>
<li><code>L(s, x)</code>: learnable linear function <code>y = W * x + B</code> with an output vector
size of <code>s</code></li>
<li><code>CM(x)</code>: learnable element-wise gain function <code>y = W * x</code></li>
<li><code>A(a, b)</code>: element-wise add: <code>y = a + b</code></li>
<li><code>M(a, b)</code>: element-wise multiply: <code>y = a * b</code></li>
<li><code>S(x)</code>: sigmoid activation function <code>y = sigmoid(x)</code></li>
<li><code>T(x)</code>: hyperbolic tangent activation function <code>y = tanh(x)</code></li>
<li> <code>C(xp, x)</code>: copy <code>x</code> to <code>xp</code> in the next time step (propagate through
time)</li>
<li> <code>OG(o, g, x)</code>: apply a constant offset and gain: <code>y = o + g * x</code></li>
<li> <code>MD(x)</code>: apply the sub-network specified by <code>BK</code></li>
</ul>
<p>Note: even if you don&rsquo;t use <code>MD</code> in your network, you should still define
<code>BK</code> by adding <code>-DBK='y=x'</code> to the command line, otherwise you will get a
compile-time error.</p>
<h2>Hyperparameters</h2>
<p>OMLET has a large number of training and inference parameters which can be
changed by the user. All of these are set by <code>-D</code> on the compile command line.
The list of hyperparameters follows:</p>
<ul>
<li><code>TP</code>: Temperature parameter for use in inference mode. This divides the
log probabilities before softmax. A low temperature makes the model choose
safer but more boring choices. A high temperature takes more risks but
makes more mistakes. Default is 1.0, which uses the computed
probabilities.</li>
<li>&lsquo;N&rsquo;: Batch size. This is the number of times the RNN is unrolled, so it
controls how far back in the past the RNN can see. The default is 50.
Larger batch sizes update the weights less frequently and allow the RNN to
see farther back in time, but at a cost of proportionally more memory.</li>
<li><code>TR</code>: The percentage of batches in the input data set that will be used
for training. The default value of 0.95 sets this as 95%.</li>
<li><code>LR</code>: The initial learning rate, The default is 0.002.</li>
<li><code>LE</code>: The epoch where the learning rate will start decaying. Defaults to
epoch 10.</li>
<li><code>LD</code>: Learning rate decay, per epoch (after <code>LE</code> epochs). The learning
rate is scaled by this number. Default is 0.97</li>
<li><code>WD</code>: Weight-decay parameter, to promote <a href="https://en.wikipedia.org/wiki/Regularization_(mathematics)">regularizaiton</a>. The default
is 0.00008.</li>
<li><code>RS</code>: The random scale for weight initialization. Weight parameters will
be initialized to be between <code>-RS</code> to <code>+RS</code>. The default is 0.15.</li>
<li><code>CL</code>: Clamp value for gradients. Gradients will be limited to the range
<code>-CL</code> to <code>+CL</code>. Default is 5.</li>
<li><code>B1</code>: Momentum mean parameter for Adam optimizer. Set to 0.9.</li>
<li><code>B2</code>: Momentum variance parameter for Adam optimizer, Set to 0.999.</li>
<li><code>EP</code>: Epsilon parameter for Adam, to provide numerical stability. Set to
0.00000001.</li>
<li><code>DI</code>: How often to print a training or validation progress message and
inference snippet. The default prints every 100 training batches.</li>
<li><code>SL</code>: The number of characters to print when doing an inference snippet.
Default is 200.</li>
<li><code>PF</code>: Format string for the checkpoint filename. The default is
<code>"cp%02d_%.3f"</code> which includes the epoch and validation loss. You may
wish to add a subdirectory to the name to keep checkpoint files out of
the current directory.</li>
</ul>
<hr />
<!--
(c) Copyright 1984-2019, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
[judges]: http://www.ioccc.org/judges.html
[cc]: http://creativecommons.org/licenses/by-sa/3.0/
-->
<TABLE><TR>
<TD><a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="/png/by-sa-3.0-88x31.png" /></a></TD>
<TD><P>&copy; Copyright 1984-2019,
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
- All rights reserved<BR>
This work is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
<TD>&nbsp;<!--<a href="https://validator.w3.org/check?uri=referer"><img src="https://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
</TR></TABLE>
</body>
</html>
+636
View File
@@ -0,0 +1,636 @@
# Most in need to be tweeted
Christopher Mills
Twitter: @MisterXopher
## Judges' comments:
### To use:
make
make cpclean
# Let this run for about about an hour and then kill it
./prog Shakespeare.txt
./prog < $(< ls -1tr cp* | tail -1) | head -100
### Try:
# If you are on a 64-bit system:
make test-64bit
less IOCCC-Rules-Guidelines.output.txt
less IOCCC-hints.output.txt
less Eugene_Onegin.output.txt
# However, as the binary model files used to produce the output are in an implementation-specific format,
# your mileage may vary.
### Selected Judges Remarks:
Can a machine learn?
Some say so.
But can a machine learn to write like Shakespeare,
or tweet like [Trump](http://trumptwitterarchive.com)?
Can it write rules and guidelines for the IOCCC?
You decide. :-)
## Author's comments:
Welcome to OMLET! &#x1f373;
=================
OMLET is the _Obfuscated Machine Learning Environment Toolkit_, a
micro-framework for experimenting with [recurrent neural networks][1]. OMLET
lets you build, train and evaluate [deep neural networks][2]. Why invest
hours reading documentation and megabytes of disk space on a full-featured DNN
framework like [TensorFlow][3] or [Torch][4] when you can have full RNN
functionality in less than 4 KB!
OMLET has the following features:
+ User-programmable network configurations and hyperparameters
+ Support for various types of recurrent and feed-forward neural networks
including vanilla RNNs, LSTMs and GRUs of depths of up to 99 layers
+ No limit on parameter size (except for those imposed by the system)
+ Training and inference modes, with periodic checkpointing
+ Advanced [Adam][42] optimizer with [weight decay][43] for simplified
training
+ Hyperparamer support for batch sizing, learning rate schedule, weight
decay and gradient clipping
+ Easily extensible (requires some expertise in the C programming language)
+ Friendly markdown documentation
OMLET is based on [Andrej Karpathy's][40] [character-level language model][41]
as described in his blog post [_The Unreasonable Effectiveness of Recurrent
Neural Networks_][44]. I've included a small sample dataset to use for
training, but you can have even more fun by downloading some larger datasets:
+ [Linux kernel source][30]
+ [_War and Peace_][31]
+ [Donald Trump's 2016 campaign speeches][32]
Getting started with OMLET
--------------------------
OMLET has three operating modes:
+ _Training_, which trains a network from scratch
+ _Continuation_, which trains starting from an existing checkpoint
+ _Inference_, which uses an existing trained network to make predictions
For your first OMLET experiment, we will try training a simple single-level
RNN to write some [Shakespere][5] plays. Start by typing
make
After it builds, train it using
./prog shakespere.txt
This will immediately start outputting gibberish to the output, e.g.
./prog shakespere.txt
sins ohennAu
T-teooclelp tiThoWy
g
nlakuafy
e
sselW usnsofueB Aoee pasfUsuslhe ooM ot Wou moy
me neltAl -no IoyI mhuyakse inT-l chu ghenn ffo? fnsoe yhyye
ue nnfrlass heUthole saounlcesyee pee
t,
T0:0% 3.210888
o',,vU
An ,hTf lnm Far rur:s moilt WoEgrv wonds mith Aog thernw
Rni So
co Nnd :
For an bImy pgafoun:
Wf'r hom wortiverita
int fod mous Eheledet,
Tho he theket nonS wnu-ang dorlaMSp
nrocWiSe tflg 'o.
T0:0% 2.995950
d whecedhencrysesil yr bn,
we hh y thiwt
hut fithlot,
Fmdy s he alt
Vh th no dh foud bobt werw:s Aotnf Fhwi't whe, eusu
lhh thele wewcond ary soupfy wind tDont couc ths:
er fucwald oncli hen bos, f
T0:1% 2.878945
The gibberish is the networks attempt to write a play. So far, it's not very
successful! Between the chunks of gibberish are training progress reports
that look like
T0:1% 2.878945
This tells you that we are 1% through training epoch 0, and that the training
[loss][6] is about 2.88. As the training continues, the training loss will
reduce and the generated snippets will improve quickly:
ses, kuth
LAs of the wish,
As, I nos you,
Yov not to nalll,
Tr tot wonds.
First Sondy, llt lrte, our, tw.
First.
BRUTUS:
Helsting the kith gops of hoch Whay, fars surd what to,
The cownens golt te.
T0:12% 2.259114
eplerrotrur tandans one wiok thy or thach and cullice ded yourssting
And wours:
Whed ur surt.
SINENIUS:
On we lain bith
rerytund: tich lon hyivetetgor.
VOLUONIA:
He brich nom dove worthan then wise,
T0:13% 2.254926
It's already started to figure out things about Shakespere plays -- how to
spell short English words, how long lines tend to be, and that characters take
turns speaking with their names capitalized. The training loss has dropped to
2.25 and the improvement is noticeable.
Eventually, we will finish with the training data set and move on to a
validation cycle:
y fath onother,
I sucess,
For I me the west crare.
TRANIO:
Whow and'd have not to had you you one in my lapteny she very ame come me a gut and shourd aghir you as ignested; shend to make I strem
To h
T0:99% 1.924063
notnce gaud and is nicked thou day, ha the dusing you disaid: in thim, you things in ere thee thus erile Iht that tare theme my hast thesp thou shay: thou not eaten-or-ho-bess resing: I the but had d
T0:99% 1.923128
V0:0% 1.678907
V0:9% 1.700527
V0:18% 1.733179
V0:27% 1.714891
V0:36% 1.716672
V0:45% 1.782946
V0:54% 1.835629
V0:63% 1.876108
V0:72% 1.906814
V0:81% 1.924096
V0:90% 1.954492
V0:99% 1.969287
serfs you'll alliencseard:
We
got you? before
I say.
Farstred dentlentecaly, sir, I it one bosticield
All me the backnour mino,
Whith capitaned mid! but stell the ifvemion
Willerity.
First Cumfol of
T1:0% 1.885619
Validation cycles are used to test the network to see if it has learned to
generalize -- how well performs on data it hasn't seen before (as opposed to
the training data that the network will see many times as it trains). Progress
on the validation set is also displayed with a validation progress report that
looks like
V0:36% 1.716672
which means we are 36% of the way through the validation for epoch 0, and the
validation loss is about 1.72. Comparing the validation loss and the
training loss will give you an idea of how well the network is learning and
can let you know if the network is [overfitting or underfitting][7].
As part of the training process, the data set (which for OMLET is the
`shakespere.txt` file you gave on the command line) is divided into
[training and validation sets][8] (by default, 95% of the data is used for
training, but like most OMLET parameters, you can change this at compile-time).
At the end of the validation run, OMLET writes out a checkpoint file with a
name like `cp01_1.970`. This saves the state of the run at the start of the
epoch 1, after computing a validation loss of 1.970. The checkpoint is
helpful if you need to stop and restart training. You can stop training by
doing `Control-C`.
You can continue training from a previous checkpoint by providing the
checkpoint file name as the second parameter, for example:
./prog shakespere.txt cp01_1.970
After the validation cycle finishes, OMLET begins the next epoch by restarting
training at the beginning of the training set. Training continues forever,
until you quit it with `Control-C`. You should monitor the checkpoints to
see that the validation loss continues to drop. If it rises, the network has
probably started to overfit on the training data.
Once you've trained the validation loss as low as it will go, you can use
OMLET to run the network in inference mode which uses the frozen checkpoint
parameters to generate data. Inference mode takes the checkpoint file as
*standard input* (not on the command line) and hence must be run with a
command like
./prog < cp55_1.807
Running it produces an infinite amount of generated output, until you hit
`Control-C` to stop it.
Note that if you decide to change networks or use a different input file, you
will want to delete all the checkpoint files because the format depends on
both the network and the input -- using the wrong checkpoint is likely to
cause a crash.
Experimenting with different networks
-------------------------------------
The default network for OMLET (the one you get if you type `make` with the
executable name `prog`) is the simplest recurrent neural network. It looks
like
h = tanh(Wxh * x + Whh * h' + Bh)
y = Why * h + By
where
* `x` is the *input vector*
* `y` is the *output vector*
* `h` is the *hidden state vector*
* `h'` is the previous value of `h`
* `Wxh`, `Whh`, and `Why` are *weight matrices*
* `Bh` and `By` are *bias vectors*.
* `tanh` is the [hyperbolic tangent function][9]
The `W`'s and `B`'s are the trainable parameters of the network, and the
process of training is optimizing the values of these parameters to minimize
the loss of the network across the training set.
It is the presence of the hidden state vector that allows the RNN to
"remember" the past. We can see what would happen if we removed this hidden
state. If you type
make lin1
OMLET will create an [ADALINE][10] network that does
y = Wxy * x + By
This simple [linear][11] [feed-forward network][12]. You can run it with
./lin1 shakespeare.txt
The linear network won't be able to get past the gibberish stage, because it
lacks history:
./lin1 shakespeare.txt
UERond w,
Gir:
KINof s, mesther s thouth.
E:
KINTret, at fu,
GOMy t, as sth kesewit sooos atse ang k, ck,
Sotheouserivesthecowhet been's, t he, h nre; t and, har wiread of pincer cedst sur has, ut:
T14:67% 2.465115
UKESpan,
NGaromy soreate e m esewfoure pamitherarjulthengeoly tl.
NG s at e! w.
WAllinoully?
Wamisw ofilem:
I'delandinarrstath har aksubly s cath Whern t Is, weciss:
GLat s; llde.
Y aterit dsthence
T14:67% 2.465404
It is able to guess at what character is likely to follow the current one
(by doing a [linear regression][13]), but it lacks any history beyond that to
guide it.
You might be wondering about the role of the `tanh` function in the RNN.
`tanh` acts as an [activation function][14] which adds [nonlinearity][15]
to the network and allows it to solve complicated problems. Without
nonlinearity, all of the linear functions would fold together into a single
matrix-vector multiply and you'd effectively regress to the linear network
above. Alas, even adding a nonlinearity to the feed-forward network
(creating a [perceptron][16]) does not improve the performance because we
still lack the history provided by the hidden state vector (although if you
want to try it yourself, you can do so with `make per1`).
Going deeper
------------
We can try to improve the RNN's performance by stacking RNN modules atop each
other:
h1 = RNN(h1', x)
h2 = RNN(h2', h1)
y = Why * h2 + By
with `RNN(h, x)` defined as above. Each RNN module has its own set of
parameters and its own hidden state vector. This will improve the network's
performance, at the cost of a much larger parameter space
> **IMPORTANT NOTE**: Since OMLET uses the system stack for network storage,
> larger networks may cause OMLET to crash (typically with a message like
> `Segmentation fault`) unless the system stack size is first increased.
> The exact command for doing so depends on your shell and your system's
> hard limits. On `sh`/`ksh`/`bash` shells, you can view the hard limit
> with `ulimit -Hs` and set it with `ulimit -s 65532` (replacing `65532`
> with the actual hard limit). On `csh`/`tcsh` shells, you can view
> the hard limit with `limit -h stacksize` and set it with
> `limit stacksize 65532` (replacing `65532` with the actual hard limit).
You can try the deeper network by doing
make rnn2
(or even `make rnn3` if you want a three-layer RNN) and train it with
./rnn2 shakespeare.txt
The additional depth should allow the network to make better predictions (it
can represent more complicated history), but it may take a long time to train
-- both because the network (being larger) now requires more time to train and
because of the [vanishing and exploding gradient problem][17], which might
keep it from ever reaching its potential.
LSTMs and GRUs
--------------
RNNs are particularly hard to train because the they are trained using
[bankpropagation through time][18]. The RNN is trained by effectively
converting it into a non-recurrent network by making many copies of it
and propagating the hidden state through the copies. During training,
the backpropagation through many clones of the network amplifies the
gradient, worsening the exploding and vanishing gradient problem.
[Long Short Term Memory][19] networks (also called LSTMs) were developed to
solve this problem. Christopher Olah gives a good description of them
at his [blog posting][20]. You can build a two-level LSTM by doing
make lstm2
and train with it with
./lstm2 shakespeare.txt
The LSTM is much easier to train because it explicitly decides how to update
its hidden state via "gates". These gates are called
* _input gate_, which decides what part of the input to pay attention to
* _forget gate_, which decides what part of the hidden state to forget
* _output gate_, which decides what part of the hidden state is used to
produce the output
The basic LSTM equations are
f = sigmoid(Wxf * x + Whf * h' + Bf)
i = sigmoid(Wxi * x + Whi * h' + Bi)
o = sigmoid(Wxo * x + Who * h' + Bo)
c = f * c' + i * tanh(Wxc * x + Whc * h' + Bc)
h = o * tanh(c)
Where
* `x` is the input vector
* `h` is the hidden state (and the output to the next layer)
* `c` is the _cell state_ which represents the "memory" of the LSTM
* `h'` and `c`' are the previous values of `h` and `c` respectively
* `f` is the _forget gate_ that tells the LSTM what portion of the hidden
state to forget
* `i` is the _input gate_ that tells the LSTM what portion of the input
vector to pay attention to
* `o` is the _output gate_ that tells the LSTM what portion of the cell
state to use to generate the hidden state
* `Wxf`, `Whf`, `Wxi`, `Whi`, `Wxo`, `Who`, `Wxc`, and `Whc` are trainable
parameter matrices
* `Bf`, `Bi`, `Bo`, and `Bc` are trainable bias vectors
* `tanh` is the hyperbolic tangent function
* `sigmoid` is the [logistic function][21]
There are several LSTM variants (see [C. Olah's blog post][20] for more
examples). One important one is the [gated recurrent unit][22]. GRUs are
simplified versions of an LSTM which combine the gates together, meaning they
require fewer learned parameters. This allows them to train faster than a
generic LSTM. You can build a two-layer GRU with
make gru2
Building your own networks
--------------------------
The OMLET `Makefile` comes with one-, two- and three-layer RNNs, LSTMs and
GRUs, along with simpler feed-forward networks like multi-layer perceptrons and
a linear network. This isn't the limit of OMLET's power -- you can create your
own networks by modifying the `Makefile`. Networks are passed in on the
compiler's command-line by using `-D` directives. The network is defined by
a `-DNW='...'` command which consists of a series of comma-separated
assignments. For example, the simple one-layer RNN could be defined like
-DNW=` x = I(n), hp = I(128), \
h = C(hp, T(A(L(128, x), L(128, hp)))), \
y = L(n, h)'
The network declares `x` as an input vector (there must be a declaration for
`x`). It is declared as `I(n)`, which is an input vector of size `n`, which
is the number of characters of the input alphabet (OMLET computes this from
the input file at the start of training). OMLET will arrange to present the
input character as a [one-hot][23] vector based on the current input
character.
The second declaration, `hp`, declares the previous hidden state vector (what
we called `h'` above). We declare this to be of size 128 -- an arbitrary
choice. A larger state vector can (theoretically) carry more state, but at
a cost of larger parameter matrices and longer training time. You can
experiment with increasing the hidden vector size and see.
The third line is the core of the RNN. It sets `h`, the hidden vector output
to be the sum of two linear elements specified by `L`. The `L` function
takes two parameters -- the output vector size (which must match the size of
`h`) and the input vector. `L` will compute `y = W * x + B` where each `L`
has its own `W` (weight) and `B` (bias) training parameters. Both `x` and
`hp` are sent through `L` and the result passed through the `A` function,
which does vector addition. That result is passed through `T` which does
element-wise `tanh` activation.
Next, we wrap the whole thing with the `C` function. `C` connects `hp`
with `h`, causing the new value of `h` to be passed to the `hp` vector on
the next iteration of the algorithm (allowing the RNN to retain state in `h`).
Finally, the whole result is passed through another instance of `L`, this time
producing a vector of size `n`, which will have the negative log
[likelihood][24] function. This is assigned to `y`, which is the output of
the network (and hence must also be declared).
OMLET will take the `y` result and pass it through the [softmax][25] function,
which converts the log probabilities into a probability distribution. In
inference mode, this is used to select the next character to emit. In
training mode, this is used to generate the loss which is backpropagated.
As an example of a more complicated network, we can look at a two-layer
GRU network:
-DHS=128, \
-DNW=' x = I(n), \
y = L(n, MD(MD(x)))' \
-DBK=' hp = I(HS), \
z = S(A(L(HS, x), L(HS, hp))), \
r = S(A(L(HS, x), L(HS, hp))), \
c = T(A(L(HS, x), L(HS, hp))), \
zc = OG(1, -1, z), \
h = C(hp, A(M(zc, hp), M(z, c))), \
y = h'
We are using a few new tricks here -- first, we are defining `HS` as the size
of the hidden and cell vectors. There's nothing special about this name, its
just convenient to specify it so we don't have a bunch of constants in the
code. Second, the network itself is very simple -- it declares `x` and has
the matrix that converts the `HS`-sized hidden vector back to the `n`-sized
alphabet vector... but it now calls `MD`, which is the user-definable
module (here we are using it twice, to have two cascaded GRU blocks). The
`MD` function performs the sub-network defined by the `BK` compile-time
parameter (specified in the `-DBK='...'` setting). This sub-module again
takes an `x` parameter and produces a `y` output. Inside it, we declare
`hp` and `h`, the previous and current state vector, plus equations for the
various GRU gates (these use `S` for the sigmoid activation function).
One final new call is `OG` which does offset and gain, performing
`y = offset + gain * x` where `offset` (the first parameter) and `gain` (the
second) are constants. We are using this here to compute `(1 - z)` for the
GRU's linear interpolator.
The full set of available function blocks follows:
* `I(s)`: declares a vector (input or state) of size `s`
* `L(s, x)`: learnable linear function `y = W * x + B` with an output vector
size of `s`
* `CM(x)`: learnable element-wise gain function `y = W * x`
* `A(a, b)`: element-wise add: `y = a + b`
* `M(a, b)`: element-wise multiply: `y = a * b`
* `S(x)`: sigmoid activation function `y = sigmoid(x)`
* `T(x)`: hyperbolic tangent activation function `y = tanh(x)`
* `C(xp, x)`: copy `x` to `xp` in the next time step (propagate through
time)
* `OG(o, g, x)`: apply a constant offset and gain: `y = o + g * x`
* `MD(x)`: apply the sub-network specified by `BK`
Note: even if you don't use `MD` in your network, you should still define
`BK` by adding `-DBK='y=x'` to the command line, otherwise you will get a
compile-time error.
Hyperparameters
---------------
OMLET has a large number of training and inference parameters which can be
changed by the user. All of these are set by `-D` on the compile command line.
The list of hyperparameters follows:
* `TP`: Temperature parameter for use in inference mode. This divides the
log probabilities before softmax. A low temperature makes the model choose
safer but more boring choices. A high temperature takes more risks but
makes more mistakes. Default is 1.0, which uses the computed
probabilities.
* 'N': Batch size. This is the number of times the RNN is unrolled, so it
controls how far back in the past the RNN can see. The default is 50.
Larger batch sizes update the weights less frequently and allow the RNN to
see farther back in time, but at a cost of proportionally more memory.
* `TR`: The percentage of batches in the input data set that will be used
for training. The default value of 0.95 sets this as 95%.
* `LR`: The initial learning rate, The default is 0.002.
* `LE`: The epoch where the learning rate will start decaying. Defaults to
epoch 10.
* `LD`: Learning rate decay, per epoch (after `LE` epochs). The learning
rate is scaled by this number. Default is 0.97
* `WD`: Weight-decay parameter, to promote [regularizaiton][27]. The default
is 0.00008.
* `RS`: The random scale for weight initialization. Weight parameters will
be initialized to be between `-RS` to `+RS`. The default is 0.15.
* `CL`: Clamp value for gradients. Gradients will be limited to the range
`-CL` to `+CL`. Default is 5.
* `B1`: Momentum mean parameter for Adam optimizer. Set to 0.9.
* `B2`: Momentum variance parameter for Adam optimizer, Set to 0.999.
* `EP`: Epsilon parameter for Adam, to provide numerical stability. Set to
0.00000001.
* `DI`: How often to print a training or validation progress message and
inference snippet. The default prints every 100 training batches.
* `SL`: The number of characters to print when doing an inference snippet.
Default is 200.
* `PF`: Format string for the checkpoint filename. The default is
`"cp%02d_%.3f"` which includes the epoch and validation loss. You may
wish to add a subdirectory to the name to keep checkpoint files out of
the current directory.
[1]: https://en.wikipedia.org/wiki/Recurrent_neural_network
[2]: https://en.wikipedia.org/wiki/Deep_learning
[3]: https://www.tensorflow.org
[4]: http://torch.ch
[5]: https://en.wikipedia.org/wiki/William_Shakespeare
[6]: https://en.wikipedia.org/wiki/Loss_function
[7]: https://en.wikipedia.org/wiki/Overfitting
[8]: https://en.wikipedia.org/wiki/Training,_validation,_and_test_sets
[9]: https://en.wikipedia.org/wiki/Hyperbolic_function
[10]: https://en.wikipedia.org/wiki/ADALINE
[11]: https://en.wikipedia.org/wiki/Linear_map
[12]: https://en.wikipedia.org/wiki/Feedforward_neural_network
[13]: https://en.wikipedia.org/wiki/Linear_regression
[14]: https://en.wikipedia.org/wiki/Activation_function
[15]: https://en.wikipedia.org/wiki/Nonlinear_system
[16]: https://en.wikipedia.org/wiki/Perceptron
[17]: https://en.wikipedia.org/wiki/Vanishing_gradient_problem
[18]: https://en.wikipedia.org/wiki/Backpropagation_through_time
[19]: https://en.wikipedia.org/wiki/Long_short-term_memory
[20]: http://colah.github.io/posts/2015-08-Understanding-LSTMs/
[21]: https://en.wikipedia.org/wiki/Logistic_function
[22]: https://en.wikipedia.org/wiki/Gated_recurrent_unit
[23]: https://en.wikipedia.org/wiki/One-hot
[24]: https://en.wikipedia.org/wiki/Likelihood_function
[25]: https://en.wikipedia.org/wiki/Softmax_function
[26]: https://en.wikipedia.org/wiki/Dropout_(neural_networks)
[27]: https://en.wikipedia.org/wiki/Regularization_(mathematics)
[30]: https://cs.stanford.edu/people/karpathy/char-rnn/linux_input.txt
[31]: https://cs.stanford.edu/people/karpathy/char-rnn/warpeace_input.txt
[32]: https://github.com/ryanmcdermott/trump-speeches
[40]: https://cs.stanford.edu/people/karpathy/
[41]: https://github.com/karpathy/char-rnn
[42]: https://arxiv.org/abs/1412.6980
[43]: https://www.fast.ai/2018/07/02/adam-weight-decay/
[44]: http://karpathy.github.io/2015/05/21/rnn-effectiveness/
--------------------------------------------------------------------------------
<!--
(c) Copyright 1984-2019, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
[judges]: http://www.ioccc.org/judges.html
[cc]: http://creativecommons.org/licenses/by-sa/3.0/
-->
+73
View File
@@ -0,0 +1,73 @@
#/*void*/include<math.h>
#include/*#pragma _Atomic int*/<stdio.h>
/* { */struct{ int o,s; } typedef V ;
struct{ int x; V o,i,p; }typedef R; int
d,w,a,i,b, u,g,n,j,F,h; R*Q,B [99],*E=B
; V I(int s ){ V o={ d,s} ; d +=s; return
#define O ; { } } if(! n --) { { { ; } }
o; } float*p,ll=1,* q, *e,s,*r,*G,*W,y=1,
# define _ V i ){ V o= I(i .s); * E++=( R) {
*x,l,*z,m; V A(V p,_ 4,o ,p,i} ; return o; } V
X,Y; double drand48(); V C (V i,V o){ *E++=(R)
#define OO ){ P(Q->o,a=Q->i. o-n; b=Q->p .o-n\
; r=b+W+n){ { n=Q->x O//struct volatile union {
{ 3,o,i} ; return o; } unsigned char c[256],t[
sizeof c+N]; V M(V p,_ 5,o,p,i} ; return o ; }
struct{ float r ; short k ,p; char unsigned d[
sizeof c]; } k={ LR} ; V S(_ 2,o,i} ; return o
; } void Z(float*p,int n){ while(n--) *p++=0; }
V L(int s,V i){ V o=I(s),p={ w,s+i.s*s } ; w+=p
#define P(v,i)n=v.o; e=G+n; p=e+v.s; q= p+d; i\
; while(--q,p-->e)// _Alignas _Imaginary _Bool;
.s; *E++=(R){0,o,i,p}; return o; } V CM(V i){ V
o=I(a=i.s),p={ w,a} ; w+=a; *E++=(R){ 7, o,i,
p} ; return o; } void J(int c){ Z(e=G+X.o, X.s)
; c[e]++ ; for(Q=B; Q<E; ++Q OO*p=*r++; n=Q ->i
.s; while(n--)*p+=*r++*e[a+n]O*p=tanh(a[p]) O*p
=1/(exp(-a[p])+1)O p[a+u]=*p O*p=p[a]+b[p]O* p=
a[p]*p[b]O*p=a[p ]*Q->p.s+Q->p.o O*p=a[p]**r ++
; } } } Z(G+d,d); P(Y,m=*e)m=fmax(m,*p); P(Y, s
=0)s+=*q=exp((*p-m)/TP); P(Y, )*q/=s; } V T(_ 1
,o,i}; return o; } int K(int K ){ J(K); P(Y,s =
drand48( ))if((s-=*q)<0)break; return j=p-e; }
V OG(int a,int b,_ 6,o,(V){ b,a} } ; return o;
} void D(char unsigned*s){ float V[2*d]; int R
=u; u=V-G; J(c[*s++ ]); n=c[*s]; l-=log(n[++q]
--)/N; G+=u; p=d+G; if(1[s])D(s); else while(p
-->G){ p[x-G]=*p; d[p]=0; } G-=u; Q=E; while(F
<i&&Q-->B OO r++[w ]+=*q; n=Q->i .s; z=e+a +n;
while(n--){ w[r ]+=*q**--z; d[z]+=*q**r++; } O
a[q]+=*q*(1-*p**p)O q[a]+=*q*(1-*p)**p O*q+=q [
a+u]O a[q]+=*q; q[b]+=*q O q[a]+=b[p]**q; b[q ]
+=p[a ]**q O a[q ]+=Q->p.s**q O a[q ]+=*q**r; r
++[w]+=*q**p; } } } u=R; } V MD( V x){ V BK; //
return y; } int main(int Q,char**E){ FILE*f, *o
=stdin; if(--Q){ o=fopen(2[E],"r"); f=fopen (1[
E],"r"); while(w>-(n=getc(f))){ ++h; if(!n[ t])
{ n[t]++; k.d[k.k]=n; n[c]=k .k++; } } } o &&f\
read(&k,sizeof k,1,o); n=k.k; { V NW; X=x ; Y=
y; } float R[d+d],B[4*w],q[d*2]; G=x=R; W =B; Z
(W,4*w); p=W+w; while(p-->W)*p=2*drand48 ()*RS-
RS; o&&fread(W,1,sizeof B,o); Z(G,d); h /=N; i=
h*TR; h-=i; for(t[1+N]=m; Q; fclose(o) ){ rewi\
nd(f ); while(fread(t,1 +N,1,f) ){ G= q; p=d+G;
while(p-->G)*p=p[x-G]; D(t); ungetc (j=N[t],f)
; if(F++<i){ a=w*3; b=a- w; p=W+w; while(p-->W
){ m=fmax(-CL,fmin(CL,w[p ])); ll *=B1; p[a]=m+
(a[p]-m)*B1; y*=B2; m*=m; b[p]= m+(p[b]-m)*B2;
*p+=(a[p]/sqrt(p[b]/(1-y)+EP)/ (ll-1)+WD**p)*k.
r; p[w]=0; } if(1>F%DI){ G=R ; z=SL+W; while(z
-->B)putchar(k.d[K(j)]); } } if(1>F%DI ){ b=F;
a=i; j=b>a; if(j){ b-=a; a= h; } printf(&j[//;
"\n%c%d:%d%% %f\n"],j[ "TV"],k.p,100*b/a,l/b
); } l*=F!=i; } /** */ char p[999]; if(LE
<=++k .p)k.r*=LD; /*if*/ sprintf(p,PF,k.p
,l/h); fwrite( &k,sizeof k, 1,o =fopen(p,
"w")); F=l =0; fwrite(B,w,/** */sizeof*
W,o); } while(putchar(k.d[K(j)]) ){ } }
/* typedef volatile long double not ;
register restrict unsigned volatile void
_Complex struct bitand*/