3a40d9c0930c18f4b4a5bb7af3cf5de104c84dd9
[jackhill/guix/guix.git] / gnu / packages / machine-learning.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2017, 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2016, 2017 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
6 ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2018 Kei Kebreau <kkebreau@posteo.net>
8 ;;; Copyright © 2018 Mark Meyer <mark@ofosos.org>
9 ;;; Copyright © 2018 Ben Woodcroft <donttrustben@gmail.com>
10 ;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
11 ;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
12 ;;; Copyright © 2018 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
13 ;;; Copyright © 2019 Nicolas Goaziou <mail@nicolasgoaziou.fr>
14 ;;; Copyright © 2019 Guillaume Le Vaillant <glv@posteo.net>
15 ;;;
16 ;;; This file is part of GNU Guix.
17 ;;;
18 ;;; GNU Guix is free software; you can redistribute it and/or modify it
19 ;;; under the terms of the GNU General Public License as published by
20 ;;; the Free Software Foundation; either version 3 of the License, or (at
21 ;;; your option) any later version.
22 ;;;
23 ;;; GNU Guix is distributed in the hope that it will be useful, but
24 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;;; GNU General Public License for more details.
27 ;;;
28 ;;; You should have received a copy of the GNU General Public License
29 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
30
31 (define-module (gnu packages machine-learning)
32 #:use-module ((guix licenses) #:prefix license:)
33 #:use-module (guix packages)
34 #:use-module (guix utils)
35 #:use-module (guix download)
36 #:use-module (guix svn-download)
37 #:use-module (guix build-system asdf)
38 #:use-module (guix build-system cmake)
39 #:use-module (guix build-system gnu)
40 #:use-module (guix build-system ocaml)
41 #:use-module (guix build-system python)
42 #:use-module (guix build-system r)
43 #:use-module (guix git-download)
44 #:use-module (gnu packages)
45 #:use-module (gnu packages adns)
46 #:use-module (gnu packages algebra)
47 #:use-module (gnu packages audio)
48 #:use-module (gnu packages autotools)
49 #:use-module (gnu packages base)
50 #:use-module (gnu packages bash)
51 #:use-module (gnu packages boost)
52 #:use-module (gnu packages check)
53 #:use-module (gnu packages compression)
54 #:use-module (gnu packages cran)
55 #:use-module (gnu packages databases)
56 #:use-module (gnu packages dejagnu)
57 #:use-module (gnu packages gcc)
58 #:use-module (gnu packages glib)
59 #:use-module (gnu packages graphviz)
60 #:use-module (gnu packages gstreamer)
61 #:use-module (gnu packages image)
62 #:use-module (gnu packages linux)
63 #:use-module (gnu packages lisp)
64 #:use-module (gnu packages maths)
65 #:use-module (gnu packages mpi)
66 #:use-module (gnu packages ocaml)
67 #:use-module (gnu packages onc-rpc)
68 #:use-module (gnu packages perl)
69 #:use-module (gnu packages pkg-config)
70 #:use-module (gnu packages protobuf)
71 #:use-module (gnu packages python)
72 #:use-module (gnu packages python-web)
73 #:use-module (gnu packages python-xyz)
74 #:use-module (gnu packages serialization)
75 #:use-module (gnu packages sphinx)
76 #:use-module (gnu packages statistics)
77 #:use-module (gnu packages sqlite)
78 #:use-module (gnu packages swig)
79 #:use-module (gnu packages tls)
80 #:use-module (gnu packages web)
81 #:use-module (gnu packages xml)
82 #:use-module (gnu packages xorg)
83 #:use-module (ice-9 match))
84
85 (define-public fann
86 ;; The last release is >100 commits behind, so we package from git.
87 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
88 (package
89 (name "fann")
90 (version (string-append "2.2.0-1." (string-take commit 8)))
91 (source (origin
92 (method git-fetch)
93 (uri (git-reference
94 (url "https://github.com/libfann/fann.git")
95 (commit commit)))
96 (file-name (string-append name "-" version "-checkout"))
97 (sha256
98 (base32
99 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
100 (build-system cmake-build-system)
101 (arguments
102 `(#:phases
103 (modify-phases %standard-phases
104 (replace 'check
105 (lambda* (#:key outputs #:allow-other-keys)
106 (let* ((out (assoc-ref outputs "out")))
107 (with-directory-excursion (string-append (getcwd) "/tests")
108 (invoke "./fann_tests"))))))))
109 (home-page "http://leenissen.dk/fann/wp/")
110 (synopsis "Fast Artificial Neural Network")
111 (description
112 "FANN is a free open source neural network library, which implements
113 multilayer artificial neural networks in C with support for both fully
114 connected and sparsely connected networks.")
115 (license license:lgpl2.1))))
116
117 (define-public libsvm
118 (package
119 (name "libsvm")
120 (version "3.23")
121 (source
122 (origin
123 (method url-fetch)
124 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
125 name "-" version ".tar.gz"))
126 (sha256
127 (base32 "0jpaq0rr92x38p4nk3gjan79ip67m6p80anb28z1d8601miysyi5"))))
128 (build-system gnu-build-system)
129 (arguments
130 `(#:tests? #f ; no "check" target
131 #:phases (modify-phases %standard-phases
132 (delete 'configure)
133 (replace
134 'install ; no ‘install’ target
135 (lambda* (#:key outputs #:allow-other-keys)
136 (let* ((out (assoc-ref outputs "out"))
137 (bin (string-append out "/bin/")))
138 (mkdir-p bin)
139 (for-each (lambda (file)
140 (copy-file file (string-append bin file)))
141 '("svm-train"
142 "svm-predict"
143 "svm-scale")))
144 #t)))))
145 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
146 (synopsis "Library for Support Vector Machines")
147 (description
148 "LIBSVM is a machine learning library for support vector
149 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
150 distribution estimation (one-class SVM). It supports multi-class
151 classification.")
152 (license license:bsd-3)))
153
154 (define-public python-libsvm
155 (package (inherit libsvm)
156 (name "python-libsvm")
157 (build-system gnu-build-system)
158 (arguments
159 `(#:tests? #f ; no "check" target
160 #:make-flags '("-C" "python")
161 #:phases
162 (modify-phases %standard-phases
163 (delete 'configure)
164 (replace
165 'install ; no ‘install’ target
166 (lambda* (#:key inputs outputs #:allow-other-keys)
167 (let ((site (string-append (assoc-ref outputs "out")
168 "/lib/python"
169 (string-take
170 (string-take-right
171 (assoc-ref inputs "python") 5) 3)
172 "/site-packages/")))
173 (substitute* "python/svm.py"
174 (("../libsvm.so.2") "libsvm.so.2"))
175 (mkdir-p site)
176 (for-each (lambda (file)
177 (copy-file file (string-append site (basename file))))
178 (find-files "python" "\\.py"))
179 (copy-file "libsvm.so.2"
180 (string-append site "libsvm.so.2")))
181 #t)))))
182 (inputs
183 `(("python" ,python)))
184 (synopsis "Python bindings of libSVM")))
185
186 (define-public ghmm
187 ;; The latest release candidate is several years and a couple of fixes have
188 ;; been published since. This is why we download the sources from the SVN
189 ;; repository.
190 (let ((svn-revision 2341))
191 (package
192 (name "ghmm")
193 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
194 (source (origin
195 (method svn-fetch)
196 (uri (svn-reference
197 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
198 (revision svn-revision)))
199 (file-name (string-append name "-" version "-checkout"))
200 (sha256
201 (base32
202 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
203 (build-system gnu-build-system)
204 (arguments
205 `(#:imported-modules (,@%gnu-build-system-modules
206 (guix build python-build-system))
207 #:phases
208 (modify-phases %standard-phases
209 (add-after 'unpack 'enter-dir
210 (lambda _ (chdir "ghmm") #t))
211 (delete 'check)
212 (add-after 'install 'check
213 (assoc-ref %standard-phases 'check))
214 (add-before 'check 'fix-PYTHONPATH
215 (lambda* (#:key inputs outputs #:allow-other-keys)
216 (let ((python-version (python-version
217 (assoc-ref inputs "python"))))
218 (setenv "PYTHONPATH"
219 (string-append (getenv "PYTHONPATH")
220 ":" (assoc-ref outputs "out")
221 "/lib/python" python-version
222 "/site-packages")))
223 #t))
224 (add-after 'enter-dir 'fix-runpath
225 (lambda* (#:key outputs #:allow-other-keys)
226 (substitute* "ghmmwrapper/setup.py"
227 (("^(.*)extra_compile_args = \\[" line indent)
228 (string-append indent
229 "extra_link_args = [\"-Wl,-rpath="
230 (assoc-ref outputs "out") "/lib\"],\n"
231 line
232 "\"-Wl,-rpath="
233 (assoc-ref outputs "out")
234 "/lib\", ")))
235 #t))
236 (add-after 'enter-dir 'disable-broken-tests
237 (lambda _
238 (substitute* "tests/Makefile.am"
239 ;; GHMM_SILENT_TESTS is assumed to be a command.
240 (("TESTS_ENVIRONMENT.*") "")
241 ;; Do not build broken tests.
242 (("chmm .*") "")
243 (("read_fa .*") "")
244 (("mcmc .*") "")
245 (("label_higher_order_test.*$")
246 "label_higher_order_test\n"))
247
248 ;; These Python unittests are broken as there is no gato.
249 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
250 (substitute* "ghmmwrapper/ghmmunittests.py"
251 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
252 line indent)
253 (string-append indent
254 "@unittest.skip(\"Disabled by Guix\")\n"
255 line)))
256 #t)))))
257 (inputs
258 `(("python" ,python-2) ; only Python 2 is supported
259 ("libxml2" ,libxml2)))
260 (native-inputs
261 `(("pkg-config" ,pkg-config)
262 ("dejagnu" ,dejagnu)
263 ("swig" ,swig)
264 ("autoconf" ,autoconf)
265 ("automake" ,automake)
266 ("libtool" ,libtool)))
267 (home-page "http://ghmm.org")
268 (synopsis "Hidden Markov Model library")
269 (description
270 "The General Hidden Markov Model library (GHMM) is a C library with
271 additional Python bindings implementing a wide range of types of @dfn{Hidden
272 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
273 training, HMM clustering, HMM mixtures.")
274 (license license:lgpl2.0+))))
275
276 (define-public mcl
277 (package
278 (name "mcl")
279 (version "14.137")
280 (source (origin
281 (method url-fetch)
282 (uri (string-append
283 "http://micans.org/mcl/src/mcl-"
284 (string-replace-substring version "." "-")
285 ".tar.gz"))
286 (sha256
287 (base32
288 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
289 (build-system gnu-build-system)
290 (arguments
291 `(#:configure-flags (list "--enable-blast")))
292 (inputs
293 `(("perl" ,perl)))
294 (home-page "http://micans.org/mcl/")
295 (synopsis "Clustering algorithm for graphs")
296 (description
297 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
298 fast and scalable unsupervised cluster algorithm for graphs (also known as
299 networks) based on simulation of (stochastic) flow in graphs.")
300 ;; In the LICENCE file and web page it says "The software is licensed
301 ;; under the GNU General Public License, version 3.", but in several of
302 ;; the source code files it suggests GPL3 or later.
303 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
304 (license license:gpl3)))
305
306 (define-public ocaml-mcl
307 (package
308 (name "ocaml-mcl")
309 (version "12-068oasis4")
310 (source
311 (origin
312 (method git-fetch)
313 (uri (git-reference
314 (url "https://github.com/fhcrc/mcl.git")
315 (commit version)))
316 (file-name (git-file-name name version))
317 (sha256
318 (base32
319 "0009dc3h2jp3qg5val452wngpqnbfyhbcxylghq0mrjqxx0jdq5p"))))
320 (build-system ocaml-build-system)
321 (arguments
322 `(#:phases
323 (modify-phases %standard-phases
324 (add-before 'configure 'patch-paths
325 (lambda _
326 (substitute* "configure"
327 (("/bin/sh") (which "sh")))
328 (substitute* "setup.ml"
329 (("LDFLAGS=-fPIC")
330 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh")))
331 (("-std=c89") "-std=gnu99")
332
333 ;; This is a mutable string, which is no longer supported. Use
334 ;; a byte buffer instead.
335 (("String.make \\(String.length s\\)")
336 "Bytes.make (String.length s)")
337
338 ;; These two belong together.
339 (("OASISString.replace_chars")
340 "Bytes.to_string (OASISString.replace_chars")
341 ((" s;")
342 " s);"))
343 (substitute* "myocamlbuild.ml"
344 (("std=c89") "std=gnu99"))
345 ;; Since we build with a more recent OCaml, we have to use C99 or
346 ;; later. This causes problems with the old C code.
347 (substitute* "src/impala/matrix.c"
348 (("restrict") "restrict_"))
349 #t)))))
350 (native-inputs
351 `(("ocamlbuild" ,ocamlbuild)))
352 (home-page "https://github.com/fhcrc/mcl")
353 (synopsis "OCaml wrappers around MCL")
354 (description
355 "This package provides OCaml bindings for the MCL graph clustering
356 algorithm.")
357 (license license:gpl3)))
358
359 (define-public randomjungle
360 (package
361 (name "randomjungle")
362 (version "2.1.0")
363 (source
364 (origin
365 (method url-fetch)
366 (uri (string-append
367 "https://www.imbs.uni-luebeck.de/fileadmin/files/Software"
368 "/randomjungle/randomjungle-" version ".tar_.gz"))
369 (patches (search-patches "randomjungle-disable-static-build.patch"))
370 (sha256
371 (base32
372 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
373 (build-system gnu-build-system)
374 (arguments
375 `(#:configure-flags
376 (list "--disable-static"
377 (string-append "--with-boost="
378 (assoc-ref %build-inputs "boost")))
379 #:phases
380 (modify-phases %standard-phases
381 (add-before
382 'configure 'set-CXXFLAGS
383 (lambda _
384 (setenv "CXXFLAGS" "-fpermissive ")
385 #t)))))
386 (inputs
387 `(("boost" ,boost)
388 ("gsl" ,gsl)
389 ("libxml2" ,libxml2)
390 ("zlib" ,zlib)))
391 (native-inputs
392 `(("gfortran" ,gfortran)
393 ("gfortran:lib" ,gfortran "lib")))
394 ;; Non-portable assembly instructions are used so building fails on
395 ;; platforms other than x86_64 or i686.
396 (supported-systems '("x86_64-linux" "i686-linux"))
397 (home-page "https://www.imbs.uni-luebeck.de/forschung/software/details.html#c224")
398 (synopsis "Implementation of the Random Forests machine learning method")
399 (description
400 "Random Jungle is an implementation of Random Forests. It is supposed to
401 analyse high dimensional data. In genetics, it can be used for analysing big
402 Genome Wide Association (GWA) data. Random Forests is a powerful machine
403 learning method. Most interesting features are variable selection, missing
404 value imputation, classifier creation, generalization error estimation and
405 sample proximities between pairs of cases.")
406 (license license:gpl3+)))
407
408 (define-public openfst
409 (package
410 (name "openfst")
411 (version "1.7.2")
412 (source (origin
413 (method url-fetch)
414 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
415 "FstDownload/openfst-" version ".tar.gz"))
416 (sha256
417 (base32
418 "0fqgk8195kz21is09gwzwnrg7fr9526bi9mh4apyskapz27pbhr1"))))
419 (build-system gnu-build-system)
420 (home-page "http://www.openfst.org")
421 (synopsis "Library for weighted finite-state transducers")
422 (description "OpenFst is a library for constructing, combining,
423 optimizing, and searching weighted finite-state transducers (FSTs).")
424 (license license:asl2.0)))
425
426 (define-public shogun
427 (package
428 (name "shogun")
429 (version "6.1.3")
430 (source
431 (origin
432 (method url-fetch)
433 (uri (string-append
434 "ftp://shogun-toolbox.org/shogun/releases/"
435 (version-major+minor version)
436 "/sources/shogun-" version ".tar.bz2"))
437 (sha256
438 (base32
439 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
440 (modules '((guix build utils)
441 (ice-9 rdelim)))
442 (snippet
443 '(begin
444 ;; Remove non-free sources and files referencing them
445 (for-each delete-file
446 (find-files "src/shogun/classifier/svm/"
447 "SVMLight\\.(cpp|h)"))
448 (for-each delete-file
449 (find-files "examples/undocumented/libshogun/"
450 (string-append
451 "(classifier_.*svmlight.*|"
452 "evaluation_cross_validation_locked_comparison).cpp")))
453 ;; Remove non-free functions.
454 (define (delete-ifdefs file)
455 (with-atomic-file-replacement file
456 (lambda (in out)
457 (let loop ((line (read-line in 'concat))
458 (skipping? #f))
459 (if (eof-object? line)
460 #t
461 (let ((skip-next?
462 (or (and skipping?
463 (not (string-prefix?
464 "#endif //USE_SVMLIGHT" line)))
465 (string-prefix?
466 "#ifdef USE_SVMLIGHT" line))))
467 (when (or (not skipping?)
468 (and skipping? (not skip-next?)))
469 (display line out))
470 (loop (read-line in 'concat) skip-next?)))))))
471 (for-each delete-ifdefs
472 (append
473 (find-files "src/shogun/classifier/mkl"
474 "^MKLClassification\\.cpp")
475 (find-files "src/shogun/classifier/svm"
476 "^SVMLightOneClass\\.(cpp|h)")
477 (find-files "src/shogun/multiclass"
478 "^ScatterSVM\\.(cpp|h)")
479 (find-files "src/shogun/kernel/"
480 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
481 (find-files "src/shogun/regression/svr"
482 "^(MKLRegression|SVRLight)\\.(cpp|h)")
483 (find-files "src/shogun/transfer/domain_adaptation"
484 "^DomainAdaptationSVM\\.(cpp|h)")))
485 #t))))
486 (build-system cmake-build-system)
487 (arguments
488 '(#:tests? #f ;no check target
489 #:phases
490 (modify-phases %standard-phases
491 (add-after 'unpack 'delete-broken-symlinks
492 (lambda _
493 (for-each delete-file '("applications/arts/data"
494 "applications/asp/data"
495 "applications/easysvm/data"
496 "applications/msplicer/data"
497 "applications/ocr/data"
498 "examples/meta/data"
499 "examples/undocumented/data"))
500 #t))
501 (add-after 'unpack 'change-R-target-path
502 (lambda* (#:key outputs #:allow-other-keys)
503 (substitute* '("src/interfaces/r/CMakeLists.txt"
504 "examples/meta/r/CMakeLists.txt")
505 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
506 (string-append (assoc-ref outputs "out")
507 "/lib/R/library/")))
508 #t))
509 (add-after 'unpack 'fix-octave-modules
510 (lambda* (#:key outputs #:allow-other-keys)
511 (substitute* "src/interfaces/octave/CMakeLists.txt"
512 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
513 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
514 ;; change target directory
515 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
516 (string-append (assoc-ref outputs "out")
517 "/share/octave/packages")))
518 (substitute* '("src/interfaces/octave/swig_typemaps.i"
519 "src/interfaces/octave/sg_print_functions.cpp")
520 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
521 (("octave/config\\.h") "octave/octave-config.h")
522 (("octave/oct-obj.h") "octave/ovl.h"))
523 #t))
524 (add-after 'unpack 'move-rxcpp
525 (lambda* (#:key inputs #:allow-other-keys)
526 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
527 (mkdir-p rxcpp-dir)
528 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
529 #t)))
530 (add-before 'build 'set-HOME
531 ;; $HOME needs to be set at some point during the build phase
532 (lambda _ (setenv "HOME" "/tmp") #t)))
533 #:configure-flags
534 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
535 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
536 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
537 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
538 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
539 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
540 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
541 "-DINTERFACE_OCTAVE=ON"
542 "-DINTERFACE_PYTHON=ON"
543 "-DINTERFACE_R=ON")))
544 (inputs
545 `(("python" ,python)
546 ("numpy" ,python-numpy)
547 ("r-minimal" ,r-minimal)
548 ("octave" ,octave-cli)
549 ("swig" ,swig)
550 ("eigen" ,eigen)
551 ("hdf5" ,hdf5)
552 ("atlas" ,atlas)
553 ("arpack" ,arpack-ng)
554 ("lapack" ,lapack)
555 ("glpk" ,glpk)
556 ("libxml2" ,libxml2)
557 ("lzo" ,lzo)
558 ("zlib" ,zlib)))
559 (native-inputs
560 `(("pkg-config" ,pkg-config)
561 ("rxcpp" ,rxcpp)))
562 ;; Non-portable SSE instructions are used so building fails on platforms
563 ;; other than x86_64.
564 (supported-systems '("x86_64-linux"))
565 (home-page "http://shogun-toolbox.org/")
566 (synopsis "Machine learning toolbox")
567 (description
568 "The Shogun Machine learning toolbox provides a wide range of unified and
569 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
570 combine multiple data representations, algorithm classes, and general purpose
571 tools. This enables both rapid prototyping of data pipelines and extensibility
572 in terms of new algorithms.")
573 (license license:gpl3+)))
574
575 (define-public rxcpp
576 (package
577 (name "rxcpp")
578 (version "4.1.0")
579 (source
580 (origin
581 (method git-fetch)
582 (uri (git-reference
583 (url "https://github.com/ReactiveX/RxCpp.git")
584 (commit (string-append "v" version))))
585 (sha256
586 (base32 "1rdpa3jlc181jd08nk437aar085h28i45s6nzrv65apb3xyyz0ij"))
587 (file-name (git-file-name name version))))
588 (build-system cmake-build-system)
589 (arguments
590 `(#:phases
591 (modify-phases %standard-phases
592 (add-after 'unpack 'remove-werror
593 (lambda _
594 (substitute* (find-files ".")
595 (("-Werror") ""))
596 #t))
597 (replace 'check
598 (lambda _
599 (invoke "ctest"))))))
600 (native-inputs
601 `(("catch" ,catch-framework)))
602 (home-page "http://reactivex.io/")
603 (synopsis "Reactive Extensions for C++")
604 (description
605 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
606 values-distributed-in-time. ReactiveX is a library for composing asynchronous
607 and event-based programs by using observable sequences.
608
609 It extends the observer pattern to support sequences of data and/or events and
610 adds operators that allow you to compose sequences together declaratively while
611 abstracting away concerns about things like low-level threading,
612 synchronization, thread-safety, concurrent data structures, and non-blocking
613 I/O.")
614 (license license:asl2.0)))
615
616 (define-public r-adaptivesparsity
617 (package
618 (name "r-adaptivesparsity")
619 (version "1.6")
620 (source (origin
621 (method url-fetch)
622 (uri (cran-uri "AdaptiveSparsity" version))
623 (sha256
624 (base32
625 "0imr5m8mll9j6n4icsv6z9rl5kbnwsp9wvzrg7n90nnmcxq2cz91"))))
626 (properties
627 `((upstream-name . "AdaptiveSparsity")))
628 (build-system r-build-system)
629 (arguments
630 `(#:phases
631 (modify-phases %standard-phases
632 (add-after 'unpack 'link-against-armadillo
633 (lambda _
634 (substitute* "src/Makevars"
635 (("PKG_LIBS=" prefix)
636 (string-append prefix "-larmadillo"))))))))
637 (propagated-inputs
638 `(("r-mass" ,r-mass)
639 ("r-matrix" ,r-matrix)
640 ("r-rcpp" ,r-rcpp)
641 ("r-rcpparmadillo" ,r-rcpparmadillo)))
642 (inputs
643 `(("armadillo" ,armadillo)))
644 (home-page "https://cran.r-project.org/web/packages/AdaptiveSparsity")
645 (synopsis "Adaptive sparsity models")
646 (description
647 "This package implements the Figueiredo machine learning algorithm for
648 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
649 geometric models.")
650 (license license:lgpl3+)))
651
652 (define-public gemmlowp-for-tensorflow
653 ;; The commit hash is taken from "tensorflow/workspace.bzl".
654 (let ((commit "38ebac7b059e84692f53e5938f97a9943c120d98")
655 (revision "2"))
656 (package
657 (name "gemmlowp")
658 (version (git-version "0" revision commit))
659 (source (origin
660 (method url-fetch)
661 (uri (string-append "https://mirror.bazel.build/"
662 "github.com/google/gemmlowp/archive/"
663 commit ".zip"))
664 (file-name (string-append "gemmlowp-" version ".zip"))
665 (sha256
666 (base32
667 "0n56s2g8hrssm4w8qj1v58gfm56a04n9v992ixkmvk6zjiralzxq"))))
668 (build-system cmake-build-system)
669 (arguments
670 `(#:configure-flags
671 (list ,@(match (%current-system)
672 ((or "x86_64-linux" "i686-linux")
673 '("-DCMAKE_CXX_FLAGS=-msse2"))
674 (_ '())))
675 #:phases
676 (modify-phases %standard-phases
677 ;; This directory contains the CMakeLists.txt.
678 (add-after 'unpack 'chdir
679 (lambda _ (chdir "contrib") #t))
680 ;; There is no install target
681 (replace 'install
682 (lambda* (#:key outputs #:allow-other-keys)
683 (let* ((out (assoc-ref outputs "out"))
684 (lib (string-append out "/lib/"))
685 (inc (string-append out "/include/")))
686 (install-file "../build/libeight_bit_int_gemm.so" lib)
687 (for-each (lambda (dir)
688 (let ((target (string-append inc "/" dir)))
689 (mkdir-p target)
690 (for-each (lambda (h)
691 (install-file h target))
692 (find-files (string-append "../" dir)
693 "\\.h$"))))
694 '("meta" "profiling" "public" "fixedpoint"
695 "eight_bit_int_gemm" "internal"))
696 #t))))))
697 (native-inputs
698 `(("unzip" ,unzip)))
699 (home-page "https://github.com/google/gemmlowp")
700 (synopsis "Small self-contained low-precision GEMM library")
701 (description
702 "This is a small self-contained low-precision @dfn{general matrix
703 multiplication} (GEMM) library. It is not a full linear algebra library.
704 Low-precision means that the input and output matrix entries are integers on
705 at most 8 bits. To avoid overflow, results are internally accumulated on more
706 than 8 bits, and at the end only some significant 8 bits are kept.")
707 (license license:asl2.0))))
708
709 (define-public dlib
710 (package
711 (name "dlib")
712 (version "19.7")
713 (source (origin
714 (method url-fetch)
715 (uri (string-append
716 "http://dlib.net/files/dlib-" version ".tar.bz2"))
717 (sha256
718 (base32
719 "1mljz02kwkrbggyncxv5fpnyjdybw2qihaacb3js8yfkw12vwpc2"))
720 (modules '((guix build utils)))
721 (snippet
722 '(begin
723 ;; Delete ~13MB of bundled dependencies.
724 (delete-file-recursively "dlib/external")
725 (delete-file-recursively "docs/dlib/external")
726 #t))))
727 (build-system cmake-build-system)
728 (arguments
729 `(#:phases
730 (modify-phases %standard-phases
731 (add-after 'unpack 'disable-asserts
732 (lambda _
733 ;; config.h recommends explicitly enabling or disabling asserts
734 ;; when building as a shared library. By default neither is set.
735 (substitute* "dlib/config.h"
736 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
737 #t))
738 (add-after 'disable-asserts 'disable-failing-tests
739 (lambda _
740 ;; One test times out on MIPS, so we need to disable it.
741 ;; Others are flaky on some platforms.
742 (let* ((system ,(or (%current-target-system)
743 (%current-system)))
744 (disabled-tests (cond
745 ((string-prefix? "mips64" system)
746 '("object_detector" ; timeout
747 "data_io"))
748 ((string-prefix? "armhf" system)
749 '("learning_to_track"))
750 ((string-prefix? "i686" system)
751 '("optimization"))
752 (else '()))))
753 (for-each
754 (lambda (test)
755 (substitute* "dlib/test/makefile"
756 (((string-append "SRC \\+= " test "\\.cpp")) "")))
757 disabled-tests)
758 #t)))
759 (replace 'check
760 (lambda _
761 ;; No test target, so we build and run the unit tests here.
762 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
763 (with-directory-excursion test-dir
764 (invoke "make" "-j" (number->string (parallel-job-count)))
765 (invoke "./dtest" "--runall"))
766 #t)))
767 (add-after 'install 'delete-static-library
768 (lambda* (#:key outputs #:allow-other-keys)
769 (delete-file (string-append (assoc-ref outputs "out")
770 "/lib/libdlib.a"))
771 #t)))))
772 (native-inputs
773 `(("pkg-config" ,pkg-config)
774 ;; For tests.
775 ("libnsl" ,libnsl)))
776 (inputs
777 `(("giflib" ,giflib)
778 ("lapack" ,lapack)
779 ("libjpeg" ,libjpeg)
780 ("libpng" ,libpng)
781 ("libx11" ,libx11)
782 ("openblas" ,openblas)
783 ("zlib" ,zlib)))
784 (synopsis
785 "Toolkit for making machine learning and data analysis applications in C++")
786 (description
787 "Dlib is a modern C++ toolkit containing machine learning algorithms and
788 tools. It is used in both industry and academia in a wide range of domains
789 including robotics, embedded devices, mobile phones, and large high performance
790 computing environments.")
791 (home-page "http://dlib.net")
792 (license license:boost1.0)))
793
794 (define-public python-scikit-learn
795 (package
796 (name "python-scikit-learn")
797 (version "0.20.4")
798 (source
799 (origin
800 (method git-fetch)
801 (uri (git-reference
802 (url "https://github.com/scikit-learn/scikit-learn.git")
803 (commit version)))
804 (file-name (git-file-name name version))
805 (sha256
806 (base32
807 "08zbzi8yx5wdlxfx9jap61vg1malc9ajf576w7a0liv6jvvrxlpj"))))
808 (build-system python-build-system)
809 (arguments
810 `(#:phases
811 (modify-phases %standard-phases
812 (add-after 'build 'build-ext
813 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace") #t))
814 (replace 'check
815 (lambda _
816 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
817 (setenv "OPENBLAS_NUM_THREADS" "1")
818
819 ;; Some tests require write access to $HOME.
820 (setenv "HOME" "/tmp")
821
822 (invoke "pytest" "sklearn" "-m" "not network")))
823 (add-before 'reset-gzip-timestamps 'make-files-writable
824 (lambda* (#:key outputs #:allow-other-keys)
825 ;; Make sure .gz files are writable so that the
826 ;; 'reset-gzip-timestamps' phase can do its work.
827 (let ((out (assoc-ref outputs "out")))
828 (for-each make-file-writable
829 (find-files out "\\.gz$"))
830 #t))))))
831 (inputs
832 `(("openblas" ,openblas)))
833 (native-inputs
834 `(("python-pytest" ,python-pytest)
835 ("python-pandas" ,python-pandas) ;for tests
836 ("python-cython" ,python-cython)))
837 (propagated-inputs
838 `(("python-numpy" ,python-numpy)
839 ("python-scipy" ,python-scipy)))
840 (home-page "http://scikit-learn.org/")
841 (synopsis "Machine Learning in Python")
842 (description
843 "Scikit-learn provides simple and efficient tools for data mining and
844 data analysis.")
845 (license license:bsd-3)))
846
847 (define-public python2-scikit-learn
848 (package-with-python2 python-scikit-learn))
849
850 (define-public python-autograd
851 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
852 (revision "0")
853 (version (git-version "0.0.0" revision commit)))
854 (package
855 (name "python-autograd")
856 (home-page "https://github.com/HIPS/autograd")
857 (source (origin
858 (method git-fetch)
859 (uri (git-reference
860 (url home-page)
861 (commit commit)))
862 (sha256
863 (base32
864 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
865 (file-name (git-file-name name version))))
866 (version version)
867 (build-system python-build-system)
868 (native-inputs
869 `(("python-nose" ,python-nose)
870 ("python-pytest" ,python-pytest)))
871 (propagated-inputs
872 `(("python-future" ,python-future)
873 ("python-numpy" ,python-numpy)))
874 (arguments
875 `(#:phases (modify-phases %standard-phases
876 (replace 'check
877 (lambda _
878 (invoke "py.test" "-v"))))))
879 (synopsis "Efficiently computes derivatives of NumPy code")
880 (description "Autograd can automatically differentiate native Python and
881 NumPy code. It can handle a large subset of Python's features, including loops,
882 ifs, recursion and closures, and it can even take derivatives of derivatives
883 of derivatives. It supports reverse-mode differentiation
884 (a.k.a. backpropagation), which means it can efficiently take gradients of
885 scalar-valued functions with respect to array-valued arguments, as well as
886 forward-mode differentiation, and the two can be composed arbitrarily. The
887 main intended application of Autograd is gradient-based optimization.")
888 (license license:expat))))
889
890 (define-public python2-autograd
891 (package-with-python2 python-autograd))
892
893 (define-public lightgbm
894 (package
895 (name "lightgbm")
896 (version "2.0.12")
897 (source (origin
898 (method url-fetch)
899 (uri (string-append
900 "https://github.com/Microsoft/LightGBM/archive/v"
901 version ".tar.gz"))
902 (sha256
903 (base32
904 "132zf0yk0545mg72hyzxm102g3hpb6ixx9hnf8zd2k55gas6cjj1"))
905 (file-name (string-append name "-" version ".tar.gz"))))
906 (native-inputs
907 `(("python-pytest" ,python-pytest)
908 ("python-nose" ,python-nose)))
909 (inputs
910 `(("openmpi" ,openmpi)))
911 (propagated-inputs
912 `(("python-numpy" ,python-numpy)
913 ("python-scipy" ,python-scipy)))
914 (arguments
915 `(#:configure-flags
916 '("-DUSE_MPI=ON")
917 #:phases
918 (modify-phases %standard-phases
919 (replace 'check
920 (lambda* (#:key outputs #:allow-other-keys)
921 (with-directory-excursion ,(string-append "../LightGBM-" version)
922 (invoke "pytest" "tests/c_api_test/test_.py")))))))
923 (build-system cmake-build-system)
924 (home-page "https://github.com/Microsoft/LightGBM")
925 (synopsis "Gradient boosting framework based on decision tree algorithms")
926 (description "LightGBM is a gradient boosting framework that uses tree
927 based learning algorithms. It is designed to be distributed and efficient with
928 the following advantages:
929
930 @itemize
931 @item Faster training speed and higher efficiency
932 @item Lower memory usage
933 @item Better accuracy
934 @item Parallel and GPU learning supported (not enabled in this package)
935 @item Capable of handling large-scale data
936 @end itemize\n")
937 (license license:expat)))
938
939 (define-public vowpal-wabbit
940 ;; Language bindings not included.
941 (package
942 (name "vowpal-wabbit")
943 (version "8.5.0")
944 (source (origin
945 (method url-fetch)
946 (uri (string-append
947 "https://github.com/JohnLangford/vowpal_wabbit/archive/"
948 version ".tar.gz"))
949 (sha256
950 (base32
951 "0clp2kb7rk5sckhllxjr5a651awf4s8dgzg4659yh4hf5cqnf0gr"))
952 (file-name (string-append name "-" version ".tar.gz"))))
953 (inputs
954 `(("boost" ,boost)
955 ("zlib" ,zlib)))
956 (arguments
957 `(#:configure-flags
958 (list (string-append "--with-boost="
959 (assoc-ref %build-inputs "boost")))))
960 (build-system gnu-build-system)
961 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
962 (synopsis "Fast machine learning library for online learning")
963 (description "Vowpal Wabbit is a machine learning system with techniques
964 such as online, hashing, allreduce, reductions, learning2search, active, and
965 interactive learning.")
966 (license license:bsd-3)))
967
968 (define-public python2-fastlmm
969 (package
970 (name "python2-fastlmm")
971 (version "0.2.21")
972 (source
973 (origin
974 (method url-fetch)
975 (uri (pypi-uri "fastlmm" version ".zip"))
976 (sha256
977 (base32
978 "1q8c34rpmwkfy3r4d5172pzdkpfryj561897z9r3x22gq7813x1m"))))
979 (build-system python-build-system)
980 (arguments
981 `(#:tests? #f ; some test files are missing
982 #:python ,python-2)) ; only Python 2.7 is supported
983 (propagated-inputs
984 `(("python2-numpy" ,python2-numpy)
985 ("python2-scipy" ,python2-scipy)
986 ("python2-matplotlib" ,python2-matplotlib)
987 ("python2-pandas" ,python2-pandas)
988 ("python2-scikit-learn" ,python2-scikit-learn)
989 ("python2-pysnptools" ,python2-pysnptools)))
990 (native-inputs
991 `(("unzip" ,unzip)
992 ("python2-cython" ,python2-cython)
993 ("python2-mock" ,python2-mock)
994 ("python2-nose" ,python2-nose)))
995 (home-page "http://research.microsoft.com/en-us/um/redmond/projects/mscompbio/fastlmm/")
996 (synopsis "Perform genome-wide association studies on large data sets")
997 (description
998 "FaST-LMM, which stands for Factored Spectrally Transformed Linear Mixed
999 Models, is a program for performing both single-SNP and SNP-set genome-wide
1000 association studies (GWAS) on extremely large data sets.")
1001 (license license:asl2.0)))
1002
1003 ;; There have been no proper releases yet.
1004 (define-public kaldi
1005 (let ((commit "2f95609f0bb085bd3a1dc5eb0a39f3edea59e606")
1006 (revision "1"))
1007 (package
1008 (name "kaldi")
1009 (version (git-version "0" revision commit))
1010 (source (origin
1011 (method git-fetch)
1012 (uri (git-reference
1013 (url "https://github.com/kaldi-asr/kaldi.git")
1014 (commit commit)))
1015 (file-name (git-file-name name version))
1016 (sha256
1017 (base32
1018 "082qh3pfi7hvncylp4xsmkfahbd7gb0whdfa4rwrx7fxk9rdh3kz"))))
1019 (build-system gnu-build-system)
1020 (arguments
1021 `(#:test-target "test"
1022 #:phases
1023 (modify-phases %standard-phases
1024 (add-after 'unpack 'chdir
1025 (lambda _ (chdir "src") #t))
1026 (replace 'configure
1027 (lambda* (#:key build system inputs outputs #:allow-other-keys)
1028 (when (not (or (string-prefix? "x86_64" system)
1029 (string-prefix? "i686" system)))
1030 (substitute* "makefiles/linux_openblas.mk"
1031 (("-msse -msse2") "")))
1032 (substitute* "makefiles/default_rules.mk"
1033 (("/bin/bash") (which "bash")))
1034 (substitute* "Makefile"
1035 (("ext_depend: check_portaudio")
1036 "ext_depend:"))
1037 (substitute* '("online/Makefile"
1038 "onlinebin/Makefile"
1039 "gst-plugin/Makefile")
1040 (("../../tools/portaudio/install")
1041 (assoc-ref inputs "portaudio")))
1042
1043 ;; This `configure' script doesn't support variables passed as
1044 ;; arguments, nor does it support "prefix".
1045 (let ((out (assoc-ref outputs "out"))
1046 (openblas (assoc-ref inputs "openblas"))
1047 (openfst (assoc-ref inputs "openfst")))
1048 (substitute* "configure"
1049 (("check_for_slow_expf;") "")
1050 ;; This affects the RPATH and also serves as the installation
1051 ;; directory.
1052 (("KALDILIBDIR=`pwd`/lib")
1053 (string-append "KALDILIBDIR=" out "/lib")))
1054 (mkdir-p out) ; must exist
1055 (setenv "CONFIG_SHELL" (which "bash"))
1056 (setenv "OPENFST_VER" ,(package-version openfst))
1057 (invoke "./configure"
1058 "--use-cuda=no"
1059 "--shared"
1060 (string-append "--openblas-root=" openblas)
1061 (string-append "--fst-root=" openfst)))))
1062 (add-after 'build 'build-ext-and-gstreamer-plugin
1063 (lambda _
1064 (invoke "make" "-C" "online" "depend")
1065 (invoke "make" "-C" "online")
1066 (invoke "make" "-C" "onlinebin" "depend")
1067 (invoke "make" "-C" "onlinebin")
1068 (invoke "make" "-C" "gst-plugin" "depend")
1069 (invoke "make" "-C" "gst-plugin")
1070 #t))
1071 ;; TODO: also install the executables.
1072 (replace 'install
1073 (lambda* (#:key outputs #:allow-other-keys)
1074 (let* ((out (assoc-ref outputs "out"))
1075 (inc (string-append out "/include"))
1076 (lib (string-append out "/lib")))
1077 (mkdir-p lib)
1078 ;; The build phase installed symlinks to the actual
1079 ;; libraries. Install the actual targets.
1080 (for-each (lambda (file)
1081 (let ((target (readlink file)))
1082 (delete-file file)
1083 (install-file target lib)))
1084 (find-files lib "\\.so"))
1085 ;; Install headers
1086 (for-each (lambda (file)
1087 (let ((target-dir (string-append inc "/" (dirname file))))
1088 (install-file file target-dir)))
1089 (find-files "." "\\.h"))
1090 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so"
1091 (string-append lib "/gstreamer-1.0"))
1092 #t))))))
1093 (inputs
1094 `(("alsa-lib" ,alsa-lib)
1095 ("gfortran" ,gfortran "lib")
1096 ("glib" ,glib)
1097 ("gstreamer" ,gstreamer)
1098 ("jack" ,jack-1)
1099 ("openblas" ,openblas)
1100 ("openfst" ,openfst)
1101 ("portaudio" ,portaudio)
1102 ("python" ,python)))
1103 (native-inputs
1104 `(("glib" ,glib "bin") ; glib-genmarshal
1105 ("grep" ,grep)
1106 ("sed" ,sed)
1107 ("pkg-config" ,pkg-config)
1108 ("which" ,which)))
1109 (home-page "https://kaldi-asr.org/")
1110 (synopsis "Speech recognition toolkit")
1111 (description "Kaldi is an extensible toolkit for speech recognition
1112 written in C++.")
1113 (license license:asl2.0))))
1114
1115 (define-public gst-kaldi-nnet2-online
1116 (let ((commit "617e43e73c7cc45eb9119028c02bd4178f738c4a")
1117 (revision "1"))
1118 (package
1119 (name "gst-kaldi-nnet2-online")
1120 (version (git-version "0" revision commit))
1121 (source (origin
1122 (method git-fetch)
1123 (uri (git-reference
1124 (url "https://github.com/alumae/gst-kaldi-nnet2-online.git")
1125 (commit commit)))
1126 (file-name (git-file-name name version))
1127 (sha256
1128 (base32
1129 "0xh3w67b69818s6ib02ara4lw7wamjdmh4jznvkpzrs4skbs9jx9"))))
1130 (build-system gnu-build-system)
1131 (arguments
1132 `(#:tests? #f ; there are none
1133 #:make-flags
1134 (list (string-append "SHELL="
1135 (assoc-ref %build-inputs "bash") "/bin/bash")
1136 (string-append "KALDI_ROOT="
1137 (assoc-ref %build-inputs "kaldi-src"))
1138 (string-append "KALDILIBDIR="
1139 (assoc-ref %build-inputs "kaldi") "/lib")
1140 "KALDI_FLAVOR=dynamic")
1141 #:phases
1142 (modify-phases %standard-phases
1143 (add-after 'unpack 'chdir
1144 (lambda _ (chdir "src") #t))
1145 (replace 'configure
1146 (lambda* (#:key inputs #:allow-other-keys)
1147 (let ((glib (assoc-ref inputs "glib")))
1148 (setenv "CXXFLAGS" "-fPIC")
1149 (setenv "CPLUS_INCLUDE_PATH"
1150 (string-append glib "/include/glib-2.0:"
1151 glib "/lib/glib-2.0/include:"
1152 (assoc-ref inputs "gstreamer")
1153 "/include/gstreamer-1.0")))
1154 (substitute* "Makefile"
1155 (("include \\$\\(KALDI_ROOT\\)/src/kaldi.mk") "")
1156 (("\\$\\(error Cannot find") "#"))
1157 #t))
1158 (add-before 'build 'build-depend
1159 (lambda* (#:key make-flags #:allow-other-keys)
1160 (apply invoke "make" "depend" make-flags)))
1161 (replace 'install
1162 (lambda* (#:key outputs #:allow-other-keys)
1163 (let* ((out (assoc-ref outputs "out"))
1164 (lib (string-append out "/lib/gstreamer-1.0")))
1165 (install-file "libgstkaldinnet2onlinedecoder.so" lib)
1166 #t))))))
1167 (inputs
1168 `(("glib" ,glib)
1169 ("gstreamer" ,gstreamer)
1170 ("jansson" ,jansson)
1171 ("openfst" ,openfst)
1172 ("kaldi" ,kaldi)))
1173 (native-inputs
1174 `(("bash" ,bash)
1175 ("glib:bin" ,glib "bin") ; glib-genmarshal
1176 ("kaldi-src" ,(package-source kaldi))
1177 ("pkg-config" ,pkg-config)))
1178 (home-page "https://kaldi-asr.org/")
1179 (synopsis "Gstreamer plugin for decoding speech")
1180 (description "This package provides a GStreamer plugin that wraps
1181 Kaldi's @code{SingleUtteranceNnet2Decoder}. It requires iVector-adapted DNN
1182 acoustic models. The iVectors are adapted to the current audio stream
1183 automatically.")
1184 (license license:asl2.0))))
1185
1186 (define-public kaldi-gstreamer-server
1187 (let ((commit "1735ba49c5dc0ebfc184e45105fc600cd9f1f508")
1188 (revision "1"))
1189 (package
1190 (name "kaldi-gstreamer-server")
1191 (version (git-version "0" revision commit))
1192 (source (origin
1193 (method git-fetch)
1194 (uri (git-reference
1195 (url "https://github.com/alumae/kaldi-gstreamer-server.git")
1196 (commit commit)))
1197 (file-name (git-file-name name version))
1198 (sha256
1199 (base32
1200 "0j701m7lbwmzqxsfanj882v7881hrbmpqybbczbxqpcbg8q34w0k"))))
1201 (build-system gnu-build-system)
1202 (arguments
1203 `(#:tests? #f ; there are no tests that can be run automatically
1204 #:modules ((guix build utils)
1205 (guix build gnu-build-system)
1206 (srfi srfi-26))
1207 #:phases
1208 (modify-phases %standard-phases
1209 (delete 'configure)
1210 (replace 'build
1211 (lambda* (#:key outputs #:allow-other-keys)
1212 ;; Disable hash randomization to ensure the generated .pycs
1213 ;; are reproducible.
1214 (setenv "PYTHONHASHSEED" "0")
1215 (with-directory-excursion "kaldigstserver"
1216 (for-each (lambda (file)
1217 (apply invoke
1218 `("python"
1219 "-m" "compileall"
1220 "-f" ; force rebuild
1221 ,file)))
1222 (find-files "." "\\.py$")))
1223 #t))
1224 (replace 'install
1225 (lambda* (#:key inputs outputs #:allow-other-keys)
1226 (let* ((out (assoc-ref outputs "out"))
1227 (bin (string-append out "/bin"))
1228 (share (string-append out "/share/kaldi-gstreamer-server/")))
1229 ;; Install Python files
1230 (with-directory-excursion "kaldigstserver"
1231 (for-each (cut install-file <> share)
1232 (find-files "." ".*")))
1233
1234 ;; Install sample configuration files
1235 (for-each (cut install-file <> share)
1236 (find-files "." "\\.yaml"))
1237
1238 ;; Install executables
1239 (mkdir-p bin)
1240 (let* ((server (string-append bin "/kaldi-gst-server"))
1241 (client (string-append bin "/kaldi-gst-client"))
1242 (worker (string-append bin "/kaldi-gst-worker"))
1243 (PYTHONPATH (getenv "PYTHONPATH"))
1244 (GST_PLUGIN_PATH (string-append
1245 (assoc-ref inputs "gst-kaldi-nnet2-online")
1246 "/lib/gstreamer-1.0:${GST_PLUGIN_PATH}"))
1247 (wrap (lambda (wrapper what)
1248 (with-output-to-file wrapper
1249 (lambda _
1250 (format #t
1251 "#!~a
1252 export PYTHONPATH=~a
1253 export GST_PLUGIN_PATH=~a
1254 exec ~a ~a/~a \"$@\"~%"
1255 (which "bash") PYTHONPATH GST_PLUGIN_PATH
1256 (which "python") share what)))
1257 (chmod wrapper #o555))))
1258 (for-each wrap
1259 (list server client worker)
1260 (list "master_server.py"
1261 "client.py"
1262 "worker.py")))
1263 #t))))))
1264 (inputs
1265 `(("gst-kaldi-nnet2-online" ,gst-kaldi-nnet2-online)
1266 ("python2" ,python-2)
1267 ("python2-futures" ,python2-futures)
1268 ("python2-pygobject" ,python2-pygobject)
1269 ("python2-pyyaml" ,python2-pyyaml)
1270 ("python2-tornado" ,python2-tornado)
1271 ("python2-ws4py" ,python2-ws4py-for-kaldi-gstreamer-server)))
1272 (home-page "https://github.com/alumae/kaldi-gstreamer-server")
1273 (synopsis "Real-time full-duplex speech recognition server")
1274 (description "This is a real-time full-duplex speech recognition server,
1275 based on the Kaldi toolkit and the GStreamer framework and implemented in
1276 Python.")
1277 (license license:bsd-2))))
1278
1279 (define-public grpc
1280 (package
1281 (name "grpc")
1282 (version "1.16.1")
1283 (source (origin
1284 (method git-fetch)
1285 (uri (git-reference
1286 (url "https://github.com/grpc/grpc.git")
1287 (commit (string-append "v" version))))
1288 (file-name (git-file-name name version))
1289 (sha256
1290 (base32
1291 "1jimqz3115f9pli5w6ik9wi7mjc7ix6y7yrq4a1ab9fc3dalj7p2"))))
1292 (build-system cmake-build-system)
1293 (arguments
1294 `(#:tests? #f ; no test target
1295 #:configure-flags
1296 (list "-DgRPC_ZLIB_PROVIDER=package"
1297 "-DgRPC_CARES_PROVIDER=package"
1298 "-DgRPC_SSL_PROVIDER=package"
1299 "-DgRPC_PROTOBUF_PROVIDER=package")))
1300 (inputs
1301 `(("c-ares" ,c-ares/cmake)
1302 ("openssl" ,openssl)
1303 ("zlib" ,zlib)))
1304 (native-inputs
1305 `(("protobuf" ,protobuf-next)
1306 ("python" ,python-wrapper)))
1307 (home-page "https://grpc.io")
1308 (synopsis "High performance universal RPC framework")
1309 (description "gRPC is a modern open source high performance @dfn{Remote
1310 Procedure Call} (RPC) framework that can run in any environment. It can
1311 efficiently connect services in and across data centers with pluggable support
1312 for load balancing, tracing, health checking and authentication. It is also
1313 applicable in last mile of distributed computing to connect devices, mobile
1314 applications and browsers to backend services.")
1315 (license license:asl2.0)))
1316
1317 ;; Note that Tensorflow includes a "third_party" directory, which seems to not
1318 ;; only contain modified subsets of upstream library source code, but also
1319 ;; adapter headers provided by Google (such as the fft.h header, which is not
1320 ;; part of the upstream project code). The Tensorflow code includes headers
1321 ;; from the "third_party" directory. It does not look like we can replace
1322 ;; these headers with unmodified upstream files, so we keep them.
1323 (define-public tensorflow
1324 (package
1325 (name "tensorflow")
1326 (version "1.9.0")
1327 (source
1328 (origin
1329 (method git-fetch)
1330 (uri (git-reference
1331 (url "https://github.com/tensorflow/tensorflow.git")
1332 (commit (string-append "v" version))))
1333 (file-name (string-append "tensorflow-" version "-checkout"))
1334 (sha256
1335 (base32
1336 "0a9kwha395g3wgxfwln5j8vn9nkspmd75xldrlqdq540w996g8xa"))))
1337 (build-system cmake-build-system)
1338 (arguments
1339 `(#:tests? #f ; no "check" target
1340 #:build-type "Release"
1341 #:configure-flags
1342 (let ((protobuf (assoc-ref %build-inputs "protobuf"))
1343 (protobuf:native (assoc-ref %build-inputs "protobuf:native"))
1344 (jsoncpp (assoc-ref %build-inputs "jsoncpp"))
1345 (snappy (assoc-ref %build-inputs "snappy"))
1346 (sqlite (assoc-ref %build-inputs "sqlite")))
1347 (list
1348 ;; Use protobuf from Guix
1349 (string-append "-Dprotobuf_STATIC_LIBRARIES="
1350 protobuf "/lib/libprotobuf.so")
1351 (string-append "-DPROTOBUF_PROTOC_EXECUTABLE="
1352 protobuf:native "/bin/protoc")
1353
1354 ;; Use snappy from Guix
1355 (string-append "-Dsnappy_STATIC_LIBRARIES="
1356 snappy "/lib/libsnappy.so")
1357 ;; Yes, this is not actually the include directory but a prefix...
1358 (string-append "-Dsnappy_INCLUDE_DIR=" snappy)
1359
1360 ;; Use jsoncpp from Guix
1361 (string-append "-Djsoncpp_STATIC_LIBRARIES="
1362 jsoncpp "/lib/libjsoncpp.so")
1363 ;; Yes, this is not actually the include directory but a prefix...
1364 (string-append "-Djsoncpp_INCLUDE_DIR=" jsoncpp)
1365
1366 ;; Use sqlite from Guix
1367 (string-append "-Dsqlite_STATIC_LIBRARIES="
1368 sqlite "/lib/libsqlite.a")
1369
1370 ;; Use system libraries wherever possible. Currently, this
1371 ;; only affects zlib.
1372 "-Dsystemlib_ALL=ON"
1373 "-Dtensorflow_ENABLE_POSITION_INDEPENDENT_CODE=ON"
1374 "-Dtensorflow_BUILD_SHARED_LIB=ON"
1375 "-Dtensorflow_OPTIMIZE_FOR_NATIVE_ARCH=OFF"
1376 "-Dtensorflow_ENABLE_SSL_SUPPORT=OFF"
1377 "-Dtensorflow_BUILD_CONTRIB_KERNELS=OFF"))
1378 #:make-flags
1379 (list "CC=gcc")
1380 #:modules ((ice-9 ftw)
1381 (guix build utils)
1382 (guix build cmake-build-system))
1383 #:phases
1384 (modify-phases %standard-phases
1385 (add-after 'unpack 'set-source-file-times-to-1980
1386 ;; At the end of the tf_python_build_pip_package target, a ZIP
1387 ;; archive should be generated via bdist_wheel, but it fails with
1388 ;; "ZIP does not support timestamps before 1980". Luckily,
1389 ;; SOURCE_DATE_EPOCH is respected, which we set to some time in
1390 ;; 1980.
1391 (lambda _ (setenv "SOURCE_DATE_EPOCH" "315532800") #t))
1392 ;; See https://github.com/tensorflow/tensorflow/issues/20517#issuecomment-406373913
1393 (add-after 'unpack 'python3.7-compatibility
1394 (lambda _
1395 (substitute* '("tensorflow/python/eager/pywrap_tfe_src.cc"
1396 "tensorflow/python/lib/core/ndarray_tensor.cc"
1397 "tensorflow/python/lib/core/py_func.cc")
1398 (("PyUnicode_AsUTF8") "(char *)PyUnicode_AsUTF8"))
1399 (substitute* "tensorflow/c/eager/c_api.h"
1400 (("unsigned char async")
1401 "unsigned char is_async"))
1402
1403 ;; Remove dependency on tensorboard, a complicated but probably
1404 ;; optional package.
1405 (substitute* "tensorflow/tools/pip_package/setup.py"
1406 ((".*'tensorboard >.*") ""))
1407 #t))
1408 (add-after 'python3.7-compatibility 'chdir
1409 (lambda _ (chdir "tensorflow/contrib/cmake") #t))
1410 (add-after 'chdir 'disable-downloads
1411 (lambda* (#:key inputs #:allow-other-keys)
1412 (substitute* (find-files "external" "\\.cmake$")
1413 (("GIT_REPOSITORY.*") "")
1414 (("GIT_TAG.*") "")
1415 (("PREFIX ")
1416 "DOWNLOAD_COMMAND \"\"\nPREFIX "))
1417
1418 ;; Use packages from Guix
1419 (let ((grpc (assoc-ref inputs "grpc")))
1420 (substitute* "CMakeLists.txt"
1421 ;; Sqlite
1422 (("include\\(sqlite\\)") "")
1423 (("\\$\\{sqlite_STATIC_LIBRARIES\\}")
1424 (string-append (assoc-ref inputs "sqlite")
1425 "/lib/libsqlite3.so"))
1426 (("sqlite_copy_headers_to_destination") "")
1427
1428 ;; PNG
1429 (("include\\(png\\)") "")
1430 (("\\$\\{png_STATIC_LIBRARIES\\}")
1431 (string-append (assoc-ref inputs "libpng")
1432 "/lib/libpng16.so"))
1433 (("png_copy_headers_to_destination") "")
1434
1435 ;; JPEG
1436 (("include\\(jpeg\\)") "")
1437 (("\\$\\{jpeg_STATIC_LIBRARIES\\}")
1438 (string-append (assoc-ref inputs "libjpeg")
1439 "/lib/libjpeg.so"))
1440 (("jpeg_copy_headers_to_destination") "")
1441
1442 ;; GIF
1443 (("include\\(gif\\)") "")
1444 (("\\$\\{gif_STATIC_LIBRARIES\\}")
1445 (string-append (assoc-ref inputs "giflib")
1446 "/lib/libgif.so"))
1447 (("gif_copy_headers_to_destination") "")
1448
1449 ;; lmdb
1450 (("include\\(lmdb\\)") "")
1451 (("\\$\\{lmdb_STATIC_LIBRARIES\\}")
1452 (string-append (assoc-ref inputs "lmdb")
1453 "/lib/liblmdb.so"))
1454 (("lmdb_copy_headers_to_destination") "")
1455
1456 ;; Protobuf
1457 (("include\\(protobuf\\)") "")
1458 (("protobuf_copy_headers_to_destination") "")
1459 (("^ +protobuf") "")
1460
1461 ;; gRPC
1462 (("include\\(grpc\\)")
1463 "find_package(grpc REQUIRED NAMES gRPC)")
1464 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES grpc\\)") "")
1465
1466 ;; Eigen
1467 (("include\\(eigen\\)")
1468 (string-append "find_package(eigen REQUIRED NAMES Eigen3)
1469 set(eigen_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/external/eigen_archive "
1470 (assoc-ref inputs "eigen") "/include/eigen3)"))
1471 (("^ +eigen") "")
1472
1473 ;; snappy
1474 (("include\\(snappy\\)")
1475 "add_definitions(-DTF_USE_SNAPPY)")
1476 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES snappy\\)") "")
1477
1478 ;; jsoncpp
1479 (("include\\(jsoncpp\\)") "")
1480 (("^ +jsoncpp") ""))
1481
1482 (substitute* "tf_core_framework.cmake"
1483 ((" grpc") "")
1484 (("\\$\\{GRPC_BUILD\\}/grpc_cpp_plugin")
1485 (which "grpc_cpp_plugin"))
1486 ;; Link with gRPC libraries
1487 (("add_library\\(tf_protos_cc.*" m)
1488 (string-append m
1489 (format #f "\ntarget_link_libraries(tf_protos_cc PRIVATE \
1490 ~a/lib/libgrpc++_unsecure.a \
1491 ~a/lib/libgrpc_unsecure.a \
1492 ~a/lib/libaddress_sorting.a \
1493 ~a/lib/libgpr.a \
1494 ~a//lib/libcares.so
1495 )\n"
1496 grpc grpc grpc grpc
1497 (assoc-ref inputs "c-ares"))))))
1498 (substitute* "tf_tools.cmake"
1499 (("add_dependencies\\(\\$\\{proto_text.*") ""))
1500 ;; Remove dependency on bundled grpc
1501 (substitute* "tf_core_distributed_runtime.cmake"
1502 (("tf_core_cpu grpc") "tf_core_cpu"))
1503
1504 ;; This directory is a dependency of many targets.
1505 (mkdir-p "protobuf")
1506 #t))
1507 (add-after 'configure 'unpack-third-party-sources
1508 (lambda* (#:key inputs #:allow-other-keys)
1509 ;; This is needed to configure bundled packages properly.
1510 (setenv "CONFIG_SHELL" (which "bash"))
1511 (for-each
1512 (lambda (name)
1513 (let* ((what (assoc-ref inputs (string-append name "-src")))
1514 (name* (string-map (lambda (c)
1515 (if (char=? c #\-)
1516 #\_ c)) name))
1517 (where (string-append "../build/" name* "/src/" name*)))
1518 (cond
1519 ((string-suffix? ".zip" what)
1520 (mkdir-p where)
1521 (with-directory-excursion where
1522 (invoke "unzip" what)))
1523 ((string-suffix? ".tar.gz" what)
1524 (mkdir-p where)
1525 (invoke "tar" "xf" what
1526 "-C" where "--strip-components=1"))
1527 (else
1528 (let ((parent (dirname where)))
1529 (mkdir-p parent)
1530 (with-directory-excursion parent
1531 (when (file-exists? name*)
1532 (delete-file-recursively name*))
1533 (copy-recursively what name*)
1534 (map make-file-writable
1535 (find-files name* ".*"))))))))
1536 (list "boringssl"
1537 "cub"
1538 "double-conversion"
1539 "farmhash"
1540 "fft2d"
1541 "highwayhash"
1542 "nsync"
1543 "re2"))
1544
1545 (rename-file "../build/cub/src/cub/cub-1.8.0/"
1546 "../build/cub/src/cub/cub/")
1547 #t))
1548 (add-after 'unpack 'fix-python-build
1549 (lambda* (#:key inputs outputs #:allow-other-keys)
1550 (mkdir-p "protobuf-src")
1551 (invoke "tar" "xf" (assoc-ref inputs "protobuf:src")
1552 "-C" "protobuf-src" "--strip-components=1")
1553 (mkdir-p "eigen-src")
1554 (invoke "tar" "xf" (assoc-ref inputs "eigen:src")
1555 "-C" "eigen-src" "--strip-components=1")
1556
1557 (substitute* "tensorflow/contrib/cmake/tf_python.cmake"
1558 ;; Ensure that all Python dependencies can be found at build time.
1559 (("PYTHONPATH=\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/tf_python" m)
1560 (string-append m ":" (getenv "PYTHONPATH")))
1561 ;; Take protobuf source files from our source package.
1562 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/protobuf/src/protobuf/src/google")
1563 (string-append (getcwd) "/protobuf-src/src/google")))
1564
1565 (substitute* '("tensorflow/contrib/cmake/tf_shared_lib.cmake"
1566 "tensorflow/contrib/cmake/tf_python.cmake")
1567 ;; Take Eigen source files from our source package.
1568 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/eigen/src/eigen/")
1569 (string-append (getcwd) "/eigen-src/"))
1570 ;; Take Eigen headers from our own package.
1571 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/external/eigen_archive")
1572 (string-append (assoc-ref inputs "eigen") "/include/eigen3")))
1573
1574 ;; Correct the RUNPATH of ops libraries generated for Python.
1575 ;; TODO: this doesn't work :(
1576 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1577 ;; warning: RUNPATH contains bogus entries: ("/tmp/guix-build-tensorflow-1.9.0.drv-0/source/tensorflow/contrib/build")
1578 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1579 ;; error: depends on 'libpywrap_tensorflow_internal.so', which
1580 ;; cannot be found in RUNPATH ...
1581 (substitute* "tensorflow/contrib/cmake/tf_cc_ops.cmake"
1582 (("set_target_properties.*")
1583 (string-append "set_target_properties(${_AT_TARGET} PROPERTIES \
1584 COMPILE_FLAGS ${target_compile_flags} \
1585 INSTALL_RPATH_USE_LINK_PATH TRUE \
1586 INSTALL_RPATH " (assoc-ref outputs "out") "/lib)\n")))
1587 #t))
1588 (add-after 'build 'build-pip-package
1589 (lambda* (#:key outputs #:allow-other-keys)
1590 (setenv "LDFLAGS"
1591 (string-append "-Wl,-rpath="
1592 (assoc-ref outputs "out") "/lib"))
1593 (invoke "make" "tf_python_build_pip_package")
1594 #t))
1595 (add-after 'build-pip-package 'install-python
1596 (lambda* (#:key outputs #:allow-other-keys)
1597 (let ((out (assoc-ref outputs "out"))
1598 (wheel (car (find-files "../build/tf_python/dist/" "\\.whl$"))))
1599 (invoke "python" "-m" "pip" "install" wheel
1600 (string-append "--prefix=" out))
1601
1602 ;; XXX: broken RUNPATH, see fix-python-build phase.
1603 (delete-file
1604 (string-append
1605 out "/lib/python3.7/site-packages/tensorflow/contrib/"
1606 "seq2seq/python/ops/lib_beam_search_ops.so"))
1607 #t))))))
1608 (native-inputs
1609 `(("pkg-config" ,pkg-config)
1610 ("protobuf:native" ,protobuf-next) ; protoc
1611 ("protobuf:src" ,(package-source protobuf-next))
1612 ("eigen:src" ,(package-source eigen-for-tensorflow))
1613 ;; install_pip_packages.sh wants setuptools 39.1.0 specifically.
1614 ("python-setuptools" ,python-setuptools-for-tensorflow)
1615
1616 ;; The commit hashes and URLs for third-party source code are taken
1617 ;; from "tensorflow/workspace.bzl".
1618 ("boringssl-src"
1619 ,(let ((commit "ee7aa02")
1620 (revision "1"))
1621 (origin
1622 (method git-fetch)
1623 (uri (git-reference
1624 (url "https://boringssl.googlesource.com/boringssl")
1625 (commit commit)))
1626 (file-name (string-append "boringssl-0-" revision
1627 (string-take commit 7)
1628 "-checkout"))
1629 (sha256
1630 (base32
1631 "1jf693q0nw0adsic6cgmbdx6g7wr4rj4vxa8j1hpn792fqhd8wgw")))))
1632 ("cub-src"
1633 ,(let ((version "1.8.0"))
1634 (origin
1635 (method url-fetch)
1636 (uri (string-append "https://mirror.bazel.build/github.com/NVlabs/"
1637 "cub/archive/" version ".zip"))
1638 (file-name (string-append "cub-" version ".zip"))
1639 (sha256
1640 (base32
1641 "1hsqikqridb90dkxkjr2918dcry6pfh46ccnwrzawl56aamhdykb")))))
1642 ("double-conversion-src"
1643 ,(let ((commit "5664746")
1644 (revision "1"))
1645 (origin
1646 (method git-fetch)
1647 (uri (git-reference
1648 (url "https://github.com/google/double-conversion.git")
1649 (commit commit)))
1650 (file-name
1651 (git-file-name "double-conversion"
1652 (string-append "0-" revision "."
1653 (string-take commit 7))))
1654 (sha256
1655 (base32
1656 "1h5lppqqxcvdg5jq42i5msgwx20ryij3apvmndflngrgdpc04gn1")))))
1657 ("farmhash-src"
1658 ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45"))
1659 (origin
1660 (method url-fetch)
1661 (uri (string-append
1662 "https://mirror.bazel.build/github.com/google/farmhash/archive/"
1663 commit ".tar.gz"))
1664 (file-name (string-append "farmhash-0-" (string-take commit 7)
1665 ".tar.gz"))
1666 (sha256
1667 (base32
1668 "185b2xdxl4d4cnsnv6abg8s22gxvx8673jq2yaq85bz4cdy58q35")))))
1669 ;; The license notice on the home page at
1670 ;; http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html says:
1671 ;; Copyright Takuya OOURA, 1996-2001
1672 ;;
1673 ;; You may use, copy, modify and distribute this code for any purpose
1674 ;; (include commercial use) and without fee. Please refer to this
1675 ;; package when you modify this code.
1676 ;;
1677 ;; We take the identical tarball from the Bazel mirror, because the URL
1678 ;; at the home page is not versioned and might change.
1679 ("fft2d-src"
1680 ,(origin
1681 (method url-fetch)
1682 (uri "https://mirror.bazel.build/www.kurims.kyoto-u.ac.jp/~ooura/fft.tgz")
1683 (file-name "fft2d.tar.gz")
1684 (sha256
1685 (base32
1686 "15jjkfvhqvl2c0753d2di8hz0pyzn598g74wqy79awdrf1y67fsj"))))
1687 ("highwayhash-src"
1688 ,(let ((commit "be5edafc2e1a455768e260ccd68ae7317b6690ee")
1689 (revision "1"))
1690 (origin
1691 (method git-fetch)
1692 (uri (git-reference
1693 (url "https://github.com/google/highwayhash.git")
1694 (commit commit)))
1695 (file-name (string-append "highwayhash-0-" revision
1696 (string-take commit 7)
1697 "-checkout"))
1698 (sha256
1699 (base32
1700 "154jwf98cyy54hldr94pgjn85zynly3abpnc1avmb8a18lzwjyb6")))))
1701 ("nsync-src"
1702 ,(let ((version "0559ce013feac8db639ee1bf776aca0325d28777")
1703 (revision "1"))
1704 (origin
1705 (method url-fetch)
1706 (uri (string-append "https://mirror.bazel.build/"
1707 "github.com/google/nsync/archive/"
1708 version ".tar.gz"))
1709 (file-name (string-append "nsync-0." revision
1710 "-" (string-take version 7)
1711 ".tar.gz"))
1712 (sha256
1713 (base32
1714 "0qdkyqym34x739mmzv97ah5r7ph462v5xkxqxvidmcfqbi64b132")))))
1715 ("re2-src"
1716 ,(let ((commit "e7efc48")
1717 (revision "1"))
1718 (origin
1719 (method git-fetch)
1720 (uri (git-reference
1721 (url "https://github.com/google/re2")
1722 (commit commit)))
1723 (file-name (string-append "re2-0-" revision
1724 (string-take commit 7)
1725 "-checkout"))
1726 (sha256
1727 (base32
1728 "161g9841rjfsy5pn52fcis0s9hdr7rxvb06pad38j5rppfihvign")))))
1729 ("googletest" ,googletest)
1730 ("swig" ,swig)
1731 ("unzip" ,unzip)))
1732 (propagated-inputs
1733 `(("python-absl-py" ,python-absl-py)
1734 ("python-astor" ,python-astor)
1735 ("python-gast" ,python-gast)
1736 ("python-grpcio" ,python-grpcio)
1737 ("python-numpy" ,python-numpy)
1738 ("python-protobuf" ,python-protobuf-next)
1739 ("python-six" ,python-six)
1740 ("python-termcolo" ,python-termcolor)
1741 ("python-wheel" ,python-wheel)))
1742 (inputs
1743 `(("c-ares" ,c-ares)
1744 ("eigen" ,eigen-for-tensorflow)
1745 ("gemmlowp" ,gemmlowp-for-tensorflow)
1746 ("lmdb" ,lmdb)
1747 ("libjpeg" ,libjpeg)
1748 ("libpng" ,libpng)
1749 ("giflib" ,giflib)
1750 ("grpc" ,grpc)
1751 ("jsoncpp" ,jsoncpp-for-tensorflow)
1752 ("snappy" ,snappy)
1753 ("sqlite" ,sqlite)
1754 ("protobuf" ,protobuf-next)
1755 ("python" ,python-wrapper)
1756 ("zlib" ,zlib)))
1757 (home-page "https://tensorflow.org")
1758 (synopsis "Machine learning framework")
1759 (description
1760 "TensorFlow is a flexible platform for building and training machine
1761 learning models. It provides a library for high performance numerical
1762 computation and includes high level Python APIs, including both a sequential
1763 API for beginners that allows users to build models quickly by plugging
1764 together building blocks and a subclassing API with an imperative style for
1765 advanced research.")
1766 (license license:asl2.0)))
1767
1768 (define-public python-iml
1769 (package
1770 (name "python-iml")
1771 (version "0.6.2")
1772 (source
1773 (origin
1774 (method url-fetch)
1775 (uri (pypi-uri "iml" version))
1776 (sha256
1777 (base32
1778 "1k8szlpm19rcwcxdny9qdm3gmaqq8akb4xlvrzyz8c2d679aak6l"))))
1779 (build-system python-build-system)
1780 (propagated-inputs
1781 `(("ipython" ,python-ipython)
1782 ("nose" ,python-nose)
1783 ("numpy" ,python-numpy)
1784 ("pandas" ,python-pandas)
1785 ("scipy" ,python-scipy)))
1786 (home-page "http://github.com/interpretable-ml/iml")
1787 (synopsis "Interpretable Machine Learning (iML) package")
1788 (description "Interpretable ML (iML) is a set of data type objects,
1789 visualizations, and interfaces that can be used by any method designed to
1790 explain the predictions of machine learning models (or really the output of
1791 any function). It currently contains the interface and IO code from the Shap
1792 project, and it will potentially also do the same for the Lime project.")
1793 (license license:expat)))
1794
1795 (define-public python-keras-applications
1796 (package
1797 (name "python-keras-applications")
1798 (version "1.0.8")
1799 (source
1800 (origin
1801 (method url-fetch)
1802 (uri (pypi-uri "Keras_Applications" version))
1803 (sha256
1804 (base32
1805 "1rcz31ca4axa6kzhjx4lwqxbg4wvlljkj8qj9a7p9sfd5fhzjyam"))))
1806 (build-system python-build-system)
1807 ;; The tests require Keras, but this package is needed to build Keras.
1808 (arguments '(#:tests? #f))
1809 (propagated-inputs
1810 `(("python-h5py" ,python-h5py)
1811 ("python-numpy" ,python-numpy)))
1812 (native-inputs
1813 `(("python-pytest" ,python-pytest)
1814 ("python-pytest-cov" ,python-pytest-cov)
1815 ("python-pytest-pep8" ,python-pytest-pep8)
1816 ("python-pytest-xdist" ,python-pytest-xdist)))
1817 (home-page "https://github.com/keras-team/keras-applications")
1818 (synopsis "Reference implementations of popular deep learning models")
1819 (description
1820 "This package provides reference implementations of popular deep learning
1821 models for use with the Keras deep learning framework.")
1822 (license license:expat)))
1823
1824 (define-public python-keras-preprocessing
1825 (package
1826 (name "python-keras-preprocessing")
1827 (version "1.1.0")
1828 (source
1829 (origin
1830 (method url-fetch)
1831 (uri (pypi-uri "Keras_Preprocessing" version))
1832 (sha256
1833 (base32
1834 "1r98nm4k1svsqjyaqkfk23i31bl1kcfcyp7094yyj3c43phfp3as"))))
1835 (build-system python-build-system)
1836 (propagated-inputs
1837 `(("python-numpy" ,python-numpy)
1838 ("python-six" ,python-six)))
1839 (native-inputs
1840 `(("python-pandas" ,python-pandas)
1841 ("python-pillow" ,python-pillow)
1842 ("python-pytest" ,python-pytest)
1843 ("python-pytest-cov" ,python-pytest-cov)
1844 ("python-pytest-xdist" ,python-pytest-xdist)
1845 ("tensorflow" ,tensorflow)))
1846 (home-page "https://github.com/keras-team/keras-preprocessing/")
1847 (synopsis "Data preprocessing and augmentation for deep learning models")
1848 (description
1849 "Keras Preprocessing is the data preprocessing and data augmentation
1850 module of the Keras deep learning library. It provides utilities for working
1851 with image data, text data, and sequence data.")
1852 (license license:expat)))
1853
1854 (define-public python-keras
1855 (package
1856 (name "python-keras")
1857 (version "2.2.4")
1858 (source
1859 (origin
1860 (method url-fetch)
1861 (uri (pypi-uri "Keras" version))
1862 (patches (search-patches "python-keras-integration-test.patch"))
1863 (sha256
1864 (base32
1865 "1j8bsqzh49vjdxy6l1k4iwax5vpjzniynyd041xjavdzvfii1dlh"))))
1866 (build-system python-build-system)
1867 (arguments
1868 `(#:phases
1869 (modify-phases %standard-phases
1870 (add-after 'unpack 'remove-tests-for-unavailable-features
1871 (lambda _
1872 (delete-file "keras/backend/theano_backend.py")
1873 (delete-file "keras/backend/cntk_backend.py")
1874 (delete-file "tests/keras/backend/backend_test.py")
1875
1876 ;; FIXME: This doesn't work because Tensorflow is missing the
1877 ;; coder ops library.
1878 (delete-file "tests/keras/test_callbacks.py")
1879 #t))
1880 (replace 'check
1881 (lambda _
1882 ;; These tests attempt to download data files from the internet.
1883 (delete-file "tests/integration_tests/test_datasets.py")
1884 (delete-file "tests/integration_tests/imagenet_utils_test.py")
1885
1886 (setenv "PYTHONPATH"
1887 (string-append (getcwd) "/build/lib:"
1888 (getenv "PYTHONPATH")))
1889 (invoke "py.test" "-v"
1890 "-p" "no:cacheprovider"
1891 "--ignore" "keras/utils"))))))
1892 (propagated-inputs
1893 `(("python-h5py" ,python-h5py)
1894 ("python-keras-applications" ,python-keras-applications)
1895 ("python-keras-preprocessing" ,python-keras-preprocessing)
1896 ("python-numpy" ,python-numpy)
1897 ("python-pydot" ,python-pydot)
1898 ("python-pyyaml" ,python-pyyaml)
1899 ("python-scipy" ,python-scipy)
1900 ("python-six" ,python-six)
1901 ("tensorflow" ,tensorflow)
1902 ("graphviz" ,graphviz)))
1903 (native-inputs
1904 `(("python-pandas" ,python-pandas)
1905 ("python-pytest" ,python-pytest)
1906 ("python-pytest-cov" ,python-pytest-cov)
1907 ("python-pytest-pep8" ,python-pytest-pep8)
1908 ("python-pytest-timeout" ,python-pytest-timeout)
1909 ("python-pytest-xdist" ,python-pytest-xdist)
1910 ("python-sphinx" ,python-sphinx)
1911 ("python-requests" ,python-requests)))
1912 (home-page "https://github.com/keras-team/keras")
1913 (synopsis "High-level deep learning framework")
1914 (description "Keras is a high-level neural networks API, written in Python
1915 and capable of running on top of TensorFlow. It was developed with a focus on
1916 enabling fast experimentation. Use Keras if you need a deep learning library
1917 that:
1918
1919 @itemize
1920 @item Allows for easy and fast prototyping (through user friendliness,
1921 modularity, and extensibility).
1922 @item Supports both convolutional networks and recurrent networks, as well as
1923 combinations of the two.
1924 @item Runs seamlessly on CPU and GPU.
1925 @end itemize\n")
1926 (license license:expat)))
1927
1928 (define-public sbcl-cl-libsvm-format
1929 (let ((commit "3300f84fd8d9f5beafc114f543f9d83417c742fb")
1930 (revision "0"))
1931 (package
1932 (name "sbcl-cl-libsvm-format")
1933 (version (git-version "0.1.0" revision commit))
1934 (source
1935 (origin
1936 (method git-fetch)
1937 (uri (git-reference
1938 (url "https://github.com/masatoi/cl-libsvm-format.git")
1939 (commit commit)))
1940 (file-name (git-file-name name version))
1941 (sha256
1942 (base32
1943 "0284aj84xszhkhlivaigf9qj855fxad3mzmv3zfr0qzb5k0nzwrg"))))
1944 (build-system asdf-build-system/sbcl)
1945 (native-inputs
1946 `(("prove" ,sbcl-prove)
1947 ("prove-asdf" ,sbcl-prove-asdf)))
1948 (inputs
1949 `(("alexandria" ,sbcl-alexandria)))
1950 (synopsis "LibSVM data format reader for Common Lisp")
1951 (description
1952 "This Common Lisp library provides a fast reader for data in LibSVM
1953 format.")
1954 (home-page "https://github.com/masatoi/cl-libsvm-format")
1955 (license license:expat))))
1956
1957 (define-public cl-libsvm-format
1958 (sbcl-package->cl-source-package sbcl-cl-libsvm-format))
1959
1960 (define-public ecl-cl-libsvm-format
1961 (sbcl-package->ecl-package sbcl-cl-libsvm-format))
1962
1963 (define-public sbcl-cl-online-learning
1964 (let ((commit "fc7a34f4f161cd1c7dd747d2ed8f698947781423")
1965 (revision "0"))
1966 (package
1967 (name "sbcl-cl-online-learning")
1968 (version (git-version "0.5" revision commit))
1969 (source
1970 (origin
1971 (method git-fetch)
1972 (uri (git-reference
1973 (url "https://github.com/masatoi/cl-online-learning.git")
1974 (commit commit)))
1975 (file-name (git-file-name name version))
1976 (sha256
1977 (base32
1978 "14x95rlg80ay5hv645ki57pqvy12v28hz4k1w0f6bsfi2rmpxchq"))))
1979 (build-system asdf-build-system/sbcl)
1980 (native-inputs
1981 `(("prove" ,sbcl-prove)
1982 ("prove-asdf" ,sbcl-prove-asdf)))
1983 (inputs
1984 `(("cl-libsvm-format" ,sbcl-cl-libsvm-format)
1985 ("cl-store" ,sbcl-cl-store)))
1986 (arguments
1987 `(;; FIXME: Tests pass but then the check phase crashes
1988 #:tests? #f))
1989 (synopsis "Online Machine Learning for Common Lisp")
1990 (description
1991 "This library contains a collection of machine learning algorithms for
1992 online linear classification written in Common Lisp.")
1993 (home-page "https://github.com/masatoi/cl-online-learning")
1994 (license license:expat))))
1995
1996 (define-public cl-online-learning
1997 (sbcl-package->cl-source-package sbcl-cl-online-learning))
1998
1999 (define-public ecl-cl-online-learning
2000 (sbcl-package->ecl-package sbcl-cl-online-learning))
2001
2002 (define-public sbcl-cl-random-forest
2003 (let ((commit "85fbdd4596d40e824f70f1b7cf239cf544e49d51")
2004 (revision "0"))
2005 (package
2006 (name "sbcl-cl-random-forest")
2007 (version (git-version "0.1" revision commit))
2008 (source
2009 (origin
2010 (method git-fetch)
2011 (uri (git-reference
2012 (url "https://github.com/masatoi/cl-random-forest.git")
2013 (commit commit)))
2014 (file-name (git-file-name name version))
2015 (sha256
2016 (base32
2017 "097xv60i1ndz68sg9p4pc7c5gvyp9i1xgw966b4wwfq3x6hbz421"))))
2018 (build-system asdf-build-system/sbcl)
2019 (native-inputs
2020 `(("prove" ,sbcl-prove)
2021 ("prove-asdf" ,sbcl-prove-asdf)
2022 ("trivial-garbage" ,sbcl-trivial-garbage)))
2023 (inputs
2024 `(("alexandria" ,sbcl-alexandria)
2025 ("cl-libsvm-format" ,sbcl-cl-libsvm-format)
2026 ("cl-online-learning" ,sbcl-cl-online-learning)
2027 ("lparallel" ,sbcl-lparallel)))
2028 (arguments
2029 `(;; The tests download data from the Internet
2030 #:tests? #f
2031 #:phases
2032 (modify-phases %standard-phases
2033 (add-after 'unpack 'add-sb-cltl2-dependency
2034 (lambda _
2035 ;; sb-cltl2 is required by lparallel when using sbcl, but it is
2036 ;; not loaded automatically.
2037 (substitute* "cl-random-forest.asd"
2038 (("\\(in-package :cl-user\\)")
2039 "(in-package :cl-user) #+sbcl (require :sb-cltl2)"))
2040 #t)))))
2041 (synopsis "Random Forest and Global Refinement for Common Lisp")
2042 (description
2043 "CL-random-forest is an implementation of Random Forest for multiclass
2044 classification and univariate regression written in Common Lisp. It also
2045 includes an implementation of Global Refinement of Random Forest.")
2046 (home-page "https://github.com/masatoi/cl-random-forest")
2047 (license license:expat))))
2048
2049 (define-public cl-random-forest
2050 (sbcl-package->cl-source-package sbcl-cl-random-forest))
2051
2052 (define-public ecl-cl-random-forest
2053 (sbcl-package->ecl-package sbcl-cl-random-forest))