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