1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016, 2020 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2016, 2017, 2020 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
6 ;;; Copyright © 2018, 2019, 2020 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, 2020 Guillaume Le Vaillant <glv@posteo.net>
15 ;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
16 ;;; Copyright © 2020 Konrad Hinsen <konrad.hinsen@fastmail.net>
17 ;;; Copyright © 2020 Edouard Klein <edk@beaver-labs.com>
19 ;;; This file is part of GNU Guix.
21 ;;; GNU Guix is free software; you can redistribute it and/or modify it
22 ;;; under the terms of the GNU General Public License as published by
23 ;;; the Free Software Foundation; either version 3 of the License, or (at
24 ;;; your option) any later version.
26 ;;; GNU Guix is distributed in the hope that it will be useful, but
27 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
28 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 ;;; GNU General Public License for more details.
31 ;;; You should have received a copy of the GNU General Public License
32 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
34 (define-module (gnu packages machine-learning)
35 #:use-module ((guix licenses) #:prefix license:)
36 #:use-module (guix packages)
37 #:use-module (guix utils)
38 #:use-module (guix download)
39 #:use-module (guix svn-download)
40 #:use-module (guix build-system cmake)
41 #:use-module (guix build-system gnu)
42 #:use-module (guix build-system ocaml)
43 #:use-module (guix build-system python)
44 #:use-module (guix build-system r)
45 #:use-module (guix git-download)
46 #:use-module (gnu packages)
47 #:use-module (gnu packages adns)
48 #:use-module (gnu packages algebra)
49 #:use-module (gnu packages audio)
50 #:use-module (gnu packages autotools)
51 #:use-module (gnu packages base)
52 #:use-module (gnu packages bash)
53 #:use-module (gnu packages boost)
54 #:use-module (gnu packages check)
55 #:use-module (gnu packages compression)
56 #:use-module (gnu packages cran)
57 #:use-module (gnu packages databases)
58 #:use-module (gnu packages dejagnu)
59 #:use-module (gnu packages gcc)
60 #:use-module (gnu packages glib)
61 #:use-module (gnu packages graphviz)
62 #:use-module (gnu packages gstreamer)
63 #:use-module (gnu packages image)
64 #:use-module (gnu packages linux)
65 #:use-module (gnu packages maths)
66 #:use-module (gnu packages mpi)
67 #:use-module (gnu packages ocaml)
68 #:use-module (gnu packages onc-rpc)
69 #:use-module (gnu packages perl)
70 #:use-module (gnu packages pkg-config)
71 #:use-module (gnu packages protobuf)
72 #:use-module (gnu packages python)
73 #:use-module (gnu packages python-science)
74 #:use-module (gnu packages python-web)
75 #:use-module (gnu packages python-xyz)
76 #:use-module (gnu packages rpc)
77 #:use-module (gnu packages serialization)
78 #:use-module (gnu packages sphinx)
79 #:use-module (gnu packages statistics)
80 #:use-module (gnu packages sqlite)
81 #:use-module (gnu packages swig)
82 #:use-module (gnu packages web)
83 #:use-module (gnu packages xml)
84 #:use-module (gnu packages xorg)
85 #:use-module (ice-9 match))
88 ;; The last release is >100 commits behind, so we package from git.
89 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
92 (version (string-append "2.2.0-1." (string-take commit 8)))
96 (url "https://github.com/libfann/fann")
98 (file-name (string-append name "-" version "-checkout"))
101 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
102 (build-system cmake-build-system)
105 (modify-phases %standard-phases
107 (lambda* (#:key outputs #:allow-other-keys)
108 (let* ((out (assoc-ref outputs "out")))
109 (with-directory-excursion (string-append (getcwd) "/tests")
110 (invoke "./fann_tests"))))))))
111 (home-page "http://leenissen.dk/fann/wp/")
112 (synopsis "Fast Artificial Neural Network")
114 "FANN is a neural network library, which implements multilayer
115 artificial neural networks in C with support for both fully connected and
116 sparsely connected networks.")
117 (license license:lgpl2.1))))
119 (define-public libsvm
126 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
127 name "-" version ".tar.gz"))
129 (base32 "0jpaq0rr92x38p4nk3gjan79ip67m6p80anb28z1d8601miysyi5"))))
130 (build-system gnu-build-system)
132 `(#:tests? #f ; no "check" target
133 #:phases (modify-phases %standard-phases
136 'install ; no ‘install’ target
137 (lambda* (#:key outputs #:allow-other-keys)
138 (let* ((out (assoc-ref outputs "out"))
139 (bin (string-append out "/bin/")))
141 (for-each (lambda (file)
142 (copy-file file (string-append bin file)))
147 (home-page "https://www.csie.ntu.edu.tw/~cjlin/libsvm/")
148 (synopsis "Library for Support Vector Machines")
150 "LIBSVM is a machine learning library for support vector
151 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
152 distribution estimation (one-class SVM). It supports multi-class
154 (license license:bsd-3)))
156 (define-public python-libsvm
157 (package (inherit libsvm)
158 (name "python-libsvm")
159 (build-system gnu-build-system)
161 `(#:tests? #f ; no "check" target
162 #:make-flags '("-C" "python")
164 (modify-phases %standard-phases
167 'install ; no ‘install’ target
168 (lambda* (#:key inputs outputs #:allow-other-keys)
169 (let ((site (string-append (assoc-ref outputs "out")
173 (assoc-ref inputs "python") 5) 3)
175 (substitute* "python/svm.py"
176 (("../libsvm.so.2") "libsvm.so.2"))
178 (for-each (lambda (file)
179 (copy-file file (string-append site (basename file))))
180 (find-files "python" "\\.py"))
181 (copy-file "libsvm.so.2"
182 (string-append site "libsvm.so.2")))
185 `(("python" ,python)))
186 (synopsis "Python bindings of libSVM")))
189 ;; The latest release candidate is several years and a couple of fixes have
190 ;; been published since. This is why we download the sources from the SVN
192 (let ((svn-revision 2341))
195 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
199 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
200 (revision svn-revision)))
201 (file-name (string-append name "-" version "-checkout"))
204 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
205 (build-system gnu-build-system)
207 `(#:imported-modules (,@%gnu-build-system-modules
208 (guix build python-build-system))
209 #:modules ((guix build python-build-system)
210 ,@%gnu-build-system-modules)
212 (modify-phases %standard-phases
213 (add-after 'unpack 'enter-dir
214 (lambda _ (chdir "ghmm") #t))
216 (add-after 'install 'check
217 (assoc-ref %standard-phases 'check))
218 (add-before 'check 'fix-PYTHONPATH
219 (lambda* (#:key inputs outputs #:allow-other-keys)
220 (let ((python-version (python-version
221 (assoc-ref inputs "python"))))
223 (string-append (getenv "PYTHONPATH")
224 ":" (assoc-ref outputs "out")
225 "/lib/python" python-version
228 (add-after 'enter-dir 'fix-runpath
229 (lambda* (#:key outputs #:allow-other-keys)
230 (substitute* "ghmmwrapper/setup.py"
231 (("^(.*)extra_compile_args = \\[" line indent)
232 (string-append indent
233 "extra_link_args = [\"-Wl,-rpath="
234 (assoc-ref outputs "out") "/lib\"],\n"
237 (assoc-ref outputs "out")
240 (add-after 'enter-dir 'disable-broken-tests
242 (substitute* "tests/Makefile.am"
243 ;; GHMM_SILENT_TESTS is assumed to be a command.
244 (("TESTS_ENVIRONMENT.*") "")
245 ;; Do not build broken tests.
249 (("label_higher_order_test.*$")
250 "label_higher_order_test\n"))
252 ;; These Python unittests are broken as there is no gato.
253 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
254 (substitute* "ghmmwrapper/ghmmunittests.py"
255 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
257 (string-append indent
258 "@unittest.skip(\"Disabled by Guix\")\n"
262 `(("python" ,python-2) ; only Python 2 is supported
263 ("libxml2" ,libxml2)))
265 `(("pkg-config" ,pkg-config)
268 ("autoconf" ,autoconf)
269 ("automake" ,automake)
270 ("libtool" ,libtool)))
271 (home-page "http://ghmm.org")
272 (synopsis "Hidden Markov Model library")
274 "The General Hidden Markov Model library (GHMM) is a C library with
275 additional Python bindings implementing a wide range of types of @dfn{Hidden
276 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
277 training, HMM clustering, HMM mixtures.")
278 (license license:lgpl2.0+))))
287 "http://micans.org/mcl/src/mcl-"
288 (string-replace-substring version "." "-")
292 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
293 (build-system gnu-build-system)
295 `(#:configure-flags (list "--enable-blast")))
298 (home-page "http://micans.org/mcl/")
299 (synopsis "Clustering algorithm for graphs")
301 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
302 fast and scalable unsupervised cluster algorithm for graphs (also known as
303 networks) based on simulation of (stochastic) flow in graphs.")
304 ;; In the LICENCE file and web page it says "The software is licensed
305 ;; under the GNU General Public License, version 3.", but in several of
306 ;; the source code files it suggests GPL3 or later.
307 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
308 (license license:gpl3)))
310 (define-public ocaml-mcl
313 (version "12-068oasis4")
318 (url "https://github.com/fhcrc/mcl")
320 (file-name (git-file-name name version))
323 "0009dc3h2jp3qg5val452wngpqnbfyhbcxylghq0mrjqxx0jdq5p"))))
324 (build-system ocaml-build-system)
327 (modify-phases %standard-phases
328 (add-before 'configure 'patch-paths
330 (substitute* "configure"
331 (("/bin/sh") (which "sh")))
332 (substitute* "setup.ml"
334 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh")))
335 (("-std=c89") "-std=gnu99")
337 ;; This is a mutable string, which is no longer supported. Use
338 ;; a byte buffer instead.
339 (("String.make \\(String.length s\\)")
340 "Bytes.make (String.length s)")
342 ;; These two belong together.
343 (("OASISString.replace_chars")
344 "Bytes.to_string (OASISString.replace_chars")
347 (substitute* "myocamlbuild.ml"
348 (("std=c89") "std=gnu99"))
349 ;; Since we build with a more recent OCaml, we have to use C99 or
350 ;; later. This causes problems with the old C code.
351 (substitute* "src/impala/matrix.c"
352 (("restrict") "restrict_"))
355 `(("ocamlbuild" ,ocamlbuild)))
356 (home-page "https://github.com/fhcrc/mcl")
357 (synopsis "OCaml wrappers around MCL")
359 "This package provides OCaml bindings for the MCL graph clustering
361 (license license:gpl3)))
363 (define-public randomjungle
365 (name "randomjungle")
371 "https://www.imbs.uni-luebeck.de/fileadmin/files/Software"
372 "/randomjungle/randomjungle-" version ".tar_.gz"))
373 (patches (search-patches "randomjungle-disable-static-build.patch"))
376 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
377 (build-system gnu-build-system)
380 (list "--disable-static"
381 (string-append "--with-boost="
382 (assoc-ref %build-inputs "boost")))
384 (modify-phases %standard-phases
386 'configure 'set-CXXFLAGS
388 (setenv "CXXFLAGS" "-fpermissive ")
396 `(("gfortran" ,gfortran)
397 ("gfortran:lib" ,gfortran "lib")))
398 ;; Non-portable assembly instructions are used so building fails on
399 ;; platforms other than x86_64 or i686.
400 (supported-systems '("x86_64-linux" "i686-linux"))
401 (home-page "https://www.imbs.uni-luebeck.de/forschung/software/details.html#c224")
402 (synopsis "Implementation of the Random Forests machine learning method")
404 "Random Jungle is an implementation of Random Forests. It is supposed to
405 analyse high dimensional data. In genetics, it can be used for analysing big
406 Genome Wide Association (GWA) data. Random Forests is a powerful machine
407 learning method. Most interesting features are variable selection, missing
408 value imputation, classifier creation, generalization error estimation and
409 sample proximities between pairs of cases.")
410 (license license:gpl3+)))
412 (define-public openfst
418 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
419 "FstDownload/openfst-" version ".tar.gz"))
422 "0fqgk8195kz21is09gwzwnrg7fr9526bi9mh4apyskapz27pbhr1"))))
423 (build-system gnu-build-system)
424 (home-page "http://www.openfst.org")
425 (synopsis "Library for weighted finite-state transducers")
426 (description "OpenFst is a library for constructing, combining,
427 optimizing, and searching weighted finite-state transducers (FSTs).")
428 (license license:asl2.0)))
430 (define-public shogun
438 "ftp://shogun-toolbox.org/shogun/releases/"
439 (version-major+minor version)
440 "/sources/shogun-" version ".tar.bz2"))
443 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
444 (modules '((guix build utils)
448 ;; Remove non-free sources and files referencing them
449 (for-each delete-file
450 (find-files "src/shogun/classifier/svm/"
451 "SVMLight\\.(cpp|h)"))
452 (for-each delete-file
453 (find-files "examples/undocumented/libshogun/"
455 "(classifier_.*svmlight.*|"
456 "evaluation_cross_validation_locked_comparison).cpp")))
457 ;; Remove non-free functions.
458 (define (delete-ifdefs file)
459 (with-atomic-file-replacement file
461 (let loop ((line (read-line in 'concat))
463 (if (eof-object? line)
468 "#endif //USE_SVMLIGHT" line)))
470 "#ifdef USE_SVMLIGHT" line))))
471 (when (or (not skipping?)
472 (and skipping? (not skip-next?)))
474 (loop (read-line in 'concat) skip-next?)))))))
475 (for-each delete-ifdefs
477 (find-files "src/shogun/classifier/mkl"
478 "^MKLClassification\\.cpp")
479 (find-files "src/shogun/classifier/svm"
480 "^SVMLightOneClass\\.(cpp|h)")
481 (find-files "src/shogun/multiclass"
482 "^ScatterSVM\\.(cpp|h)")
483 (find-files "src/shogun/kernel/"
484 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
485 (find-files "src/shogun/regression/svr"
486 "^(MKLRegression|SVRLight)\\.(cpp|h)")
487 (find-files "src/shogun/transfer/domain_adaptation"
488 "^DomainAdaptationSVM\\.(cpp|h)")))
490 (build-system cmake-build-system)
492 '(#:tests? #f ;no check target
494 (modify-phases %standard-phases
495 (add-after 'unpack 'delete-broken-symlinks
497 (for-each delete-file '("applications/arts/data"
498 "applications/asp/data"
499 "applications/easysvm/data"
500 "applications/msplicer/data"
501 "applications/ocr/data"
503 "examples/undocumented/data"))
505 (add-after 'unpack 'change-R-target-path
506 (lambda* (#:key outputs #:allow-other-keys)
507 (substitute* '("src/interfaces/r/CMakeLists.txt"
508 "examples/meta/r/CMakeLists.txt")
509 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
510 (string-append (assoc-ref outputs "out")
513 (add-after 'unpack 'fix-octave-modules
514 (lambda* (#:key outputs #:allow-other-keys)
515 (substitute* "src/interfaces/octave/CMakeLists.txt"
516 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
517 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
518 ;; change target directory
519 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
520 (string-append (assoc-ref outputs "out")
521 "/share/octave/packages")))
522 (substitute* '("src/interfaces/octave/swig_typemaps.i"
523 "src/interfaces/octave/sg_print_functions.cpp")
524 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
525 (("octave/config\\.h") "octave/octave-config.h")
526 (("octave/oct-obj.h") "octave/ovl.h"))
528 (add-after 'unpack 'move-rxcpp
529 (lambda* (#:key inputs #:allow-other-keys)
530 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
532 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
534 (add-before 'build 'set-HOME
535 ;; $HOME needs to be set at some point during the build phase
536 (lambda _ (setenv "HOME" "/tmp") #t)))
538 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
539 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
540 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
541 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
542 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
543 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
544 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
545 "-DINTERFACE_OCTAVE=ON"
546 "-DINTERFACE_PYTHON=ON"
547 "-DINTERFACE_R=ON")))
550 ("numpy" ,python-numpy)
551 ("r-minimal" ,r-minimal)
552 ("octave" ,octave-cli)
557 ("arpack" ,arpack-ng)
564 `(("pkg-config" ,pkg-config)
566 ;; Non-portable SSE instructions are used so building fails on platforms
567 ;; other than x86_64.
568 (supported-systems '("x86_64-linux"))
569 (home-page "https://shogun-toolbox.org/")
570 (synopsis "Machine learning toolbox")
572 "The Shogun Machine learning toolbox provides a wide range of unified and
573 efficient Machine Learning (ML) methods. The toolbox seamlessly
574 combines multiple data representations, algorithm classes, and general purpose
575 tools. This enables both rapid prototyping of data pipelines and extensibility
576 in terms of new algorithms.")
577 (license license:gpl3+)))
587 (url "https://github.com/ReactiveX/RxCpp")
588 (commit (string-append "v" version))))
590 (base32 "1rdpa3jlc181jd08nk437aar085h28i45s6nzrv65apb3xyyz0ij"))
591 (file-name (git-file-name name version))))
592 (build-system cmake-build-system)
595 (modify-phases %standard-phases
596 (add-after 'unpack 'remove-werror
598 (substitute* (find-files ".")
603 (invoke "ctest"))))))
605 `(("catch" ,catch-framework)))
606 (home-page "http://reactivex.io/")
607 (synopsis "Reactive Extensions for C++")
609 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
610 values-distributed-in-time. ReactiveX is a library for composing asynchronous
611 and event-based programs by using observable sequences.
613 It extends the observer pattern to support sequences of data and/or events and
614 adds operators that allow you to compose sequences together declaratively while
615 abstracting away concerns about things like low-level threading,
616 synchronization, thread-safety, concurrent data structures, and non-blocking
618 (license license:asl2.0)))
620 (define-public r-adaptivesparsity
622 (name "r-adaptivesparsity")
626 (uri (cran-uri "AdaptiveSparsity" version))
629 "0imr5m8mll9j6n4icsv6z9rl5kbnwsp9wvzrg7n90nnmcxq2cz91"))))
631 `((upstream-name . "AdaptiveSparsity")))
632 (build-system r-build-system)
635 (modify-phases %standard-phases
636 (add-after 'unpack 'link-against-armadillo
638 (substitute* "src/Makevars"
639 (("PKG_LIBS=" prefix)
640 (string-append prefix "-larmadillo"))))))))
643 ("r-matrix" ,r-matrix)
645 ("r-rcpparmadillo" ,r-rcpparmadillo)))
647 `(("armadillo" ,armadillo)))
648 (home-page "https://cran.r-project.org/web/packages/AdaptiveSparsity")
649 (synopsis "Adaptive sparsity models")
651 "This package implements the Figueiredo machine learning algorithm for
652 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
654 (license license:lgpl3+)))
656 (define-public gemmlowp-for-tensorflow
657 ;; The commit hash is taken from "tensorflow/workspace.bzl".
658 (let ((commit "38ebac7b059e84692f53e5938f97a9943c120d98")
662 (version (git-version "0" revision commit))
665 (uri (string-append "https://mirror.bazel.build/"
666 "github.com/google/gemmlowp/archive/"
668 (file-name (string-append "gemmlowp-" version ".zip"))
671 "0n56s2g8hrssm4w8qj1v58gfm56a04n9v992ixkmvk6zjiralzxq"))))
672 (build-system cmake-build-system)
675 (list ,@(match (%current-system)
676 ((or "x86_64-linux" "i686-linux")
677 '("-DCMAKE_CXX_FLAGS=-msse2"))
680 (modify-phases %standard-phases
681 ;; This directory contains the CMakeLists.txt.
682 (add-after 'unpack 'chdir
683 (lambda _ (chdir "contrib") #t))
684 ;; There is no install target
686 (lambda* (#:key outputs #:allow-other-keys)
687 (let* ((out (assoc-ref outputs "out"))
688 (lib (string-append out "/lib/"))
689 (inc (string-append out "/include/")))
690 (install-file "../build/libeight_bit_int_gemm.so" lib)
691 (for-each (lambda (dir)
692 (let ((target (string-append inc "/" dir)))
694 (for-each (lambda (h)
695 (install-file h target))
696 (find-files (string-append "../" dir)
698 '("meta" "profiling" "public" "fixedpoint"
699 "eight_bit_int_gemm" "internal"))
703 (home-page "https://github.com/google/gemmlowp")
704 (synopsis "Small self-contained low-precision GEMM library")
706 "This is a small self-contained low-precision @dfn{general matrix
707 multiplication} (GEMM) library. It is not a full linear algebra library.
708 Low-precision means that the input and output matrix entries are integers on
709 at most 8 bits. To avoid overflow, results are internally accumulated on more
710 than 8 bits, and at the end only some significant 8 bits are kept.")
711 (license license:asl2.0))))
720 "http://dlib.net/files/dlib-" version ".tar.bz2"))
723 "139jyi19qz37wwmmy48gil9d1kkh2r3w3bwdzabha6ayxmba96nz"))
724 (modules '((guix build utils)))
727 ;; Delete ~13MB of bundled dependencies.
728 (delete-file-recursively "dlib/external")
729 (delete-file-recursively "docs/dlib/external")
731 (build-system cmake-build-system)
734 (modify-phases %standard-phases
735 (add-after 'unpack 'disable-asserts
737 ;; config.h recommends explicitly enabling or disabling asserts
738 ;; when building as a shared library. By default neither is set.
739 (substitute* "dlib/config.h"
740 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
742 (add-after 'disable-asserts 'disable-failing-tests
744 ;; One test times out on MIPS, so we need to disable it.
745 ;; Others are flaky on some platforms.
746 (let* ((system ,(or (%current-target-system)
748 (disabled-tests (cond
749 ((string-prefix? "mips64" system)
750 '("object_detector" ; timeout
752 ((string-prefix? "armhf" system)
753 '("learning_to_track"))
754 ((string-prefix? "i686" system)
759 (substitute* "dlib/test/makefile"
760 (((string-append "SRC \\+= " test "\\.cpp")) "")))
765 ;; No test target, so we build and run the unit tests here.
766 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
767 (with-directory-excursion test-dir
768 (invoke "make" "-j" (number->string (parallel-job-count)))
769 (invoke "./dtest" "--runall"))
771 (add-after 'install 'delete-static-library
772 (lambda* (#:key outputs #:allow-other-keys)
773 (delete-file (string-append (assoc-ref outputs "out")
777 `(("pkg-config" ,pkg-config)
783 ("libjpeg" ,libjpeg-turbo)
786 ("openblas" ,openblas)
789 "Toolkit for making machine learning and data analysis applications in C++")
791 "Dlib is a modern C++ toolkit containing machine learning algorithms and
792 tools. It is used in both industry and academia in a wide range of domains
793 including robotics, embedded devices, mobile phones, and large high performance
794 computing environments.")
795 (home-page "http://dlib.net")
796 (license license:boost1.0)))
798 (define-public python-scikit-learn
800 (name "python-scikit-learn")
806 (url "https://github.com/scikit-learn/scikit-learn")
808 (file-name (git-file-name name version))
811 "1xqxv210gsmjw094vc5ghq2y9lmm74qkk22pq6flcjzj51b86jxf"))))
812 (build-system python-build-system)
815 (modify-phases %standard-phases
816 (add-after 'build 'build-ext
817 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace") #t))
820 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
821 (setenv "OPENBLAS_NUM_THREADS" "1")
823 ;; Some tests require write access to $HOME.
824 (setenv "HOME" "/tmp")
826 (invoke "pytest" "sklearn" "-m" "not network")))
827 (add-before 'reset-gzip-timestamps 'make-files-writable
828 (lambda* (#:key outputs #:allow-other-keys)
829 ;; Make sure .gz files are writable so that the
830 ;; 'reset-gzip-timestamps' phase can do its work.
831 (let ((out (assoc-ref outputs "out")))
832 (for-each make-file-writable
833 (find-files out "\\.gz$"))
836 `(("openblas" ,openblas)))
838 `(("python-pytest" ,python-pytest)
839 ("python-pandas" ,python-pandas) ;for tests
840 ("python-cython" ,python-cython)))
842 `(("python-numpy" ,python-numpy)
843 ("python-scipy" ,python-scipy)
844 ("python-joblib" ,python-joblib)))
845 (home-page "https://scikit-learn.org/")
846 (synopsis "Machine Learning in Python")
848 "Scikit-learn provides simple and efficient tools for data mining and
850 (properties `((python2-variant . ,(delay python2-scikit-learn))))
851 (license license:bsd-3)))
853 ;; scikit-learn 0.22 and later only supports Python 3, so we stick with
854 ;; an older version here.
855 (define-public python2-scikit-learn
856 (let ((base (package-with-python2 (strip-python2-variant python-scikit-learn))))
863 (url "https://github.com/scikit-learn/scikit-learn")
865 (file-name (git-file-name "python-scikit-learn" version))
868 "08zbzi8yx5wdlxfx9jap61vg1malc9ajf576w7a0liv6jvvrxlpj")))))))
870 (define-public python-scikit-rebate
872 (name "python-scikit-rebate")
876 (uri (pypi-uri "skrebate" version))
879 "1h7qs9gjxpzqabzhb8rmpv3jpmi5iq41kqdibg48299h94iikiw7"))))
880 (build-system python-build-system)
881 ;; Pandas is only needed to run the tests.
883 `(("python-pandas" ,python-pandas)))
885 `(("python-numpy" ,python-numpy)
886 ("python-scipy" ,python-scipy)
887 ("python-scikit-learn" ,python-scikit-learn)
888 ("python-joblib" ,python-joblib)))
889 (home-page "https://epistasislab.github.io/scikit-rebate/")
890 (synopsis "Relief-based feature selection algorithms for Python")
891 (description "Scikit-rebate is a scikit-learn-compatible Python
892 implementation of ReBATE, a suite of Relief-based feature selection algorithms
893 for Machine Learning. These algorithms excel at identifying features that are
894 predictive of the outcome in supervised learning problems, and are especially
895 good at identifying feature interactions that are normally overlooked by
896 standard feature selection algorithms.")
897 (license license:expat)))
899 (define-public python-autograd
900 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
902 (version (git-version "0.0.0" revision commit)))
904 (name "python-autograd")
905 (home-page "https://github.com/HIPS/autograd")
913 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
914 (file-name (git-file-name name version))))
916 (build-system python-build-system)
918 `(("python-nose" ,python-nose)
919 ("python-pytest" ,python-pytest)))
921 `(("python-future" ,python-future)
922 ("python-numpy" ,python-numpy)))
924 `(#:phases (modify-phases %standard-phases
927 (invoke "py.test" "-v"))))))
928 (synopsis "Efficiently computes derivatives of NumPy code")
929 (description "Autograd can automatically differentiate native Python and
930 NumPy code. It can handle a large subset of Python's features, including loops,
931 ifs, recursion and closures, and it can even take derivatives of derivatives
932 of derivatives. It supports reverse-mode differentiation
933 (a.k.a. backpropagation), which means it can efficiently take gradients of
934 scalar-valued functions with respect to array-valued arguments, as well as
935 forward-mode differentiation, and the two can be composed arbitrarily. The
936 main intended application of Autograd is gradient-based optimization.")
937 (license license:expat))))
939 (define-public python2-autograd
940 (package-with-python2 python-autograd))
942 (define-public lightgbm
949 (url "https://github.com/Microsoft/LightGBM")
950 (commit (string-append "v" version))))
953 "0jlvyn7k81dzrh9ij3zw576wbgiwmmr26rzpdxjn1dbpc3njpvzi"))
954 (file-name (git-file-name name version))))
956 `(("python-pytest" ,python-pytest)
957 ("python-nose" ,python-nose)))
959 `(("openmpi" ,openmpi)))
961 `(("python-numpy" ,python-numpy)
962 ("python-scipy" ,python-scipy)))
967 (modify-phases %standard-phases
970 (with-directory-excursion "../source"
971 (invoke "pytest" "tests/c_api_test/test_.py")))))))
972 (build-system cmake-build-system)
973 (home-page "https://github.com/Microsoft/LightGBM")
974 (synopsis "Gradient boosting framework based on decision tree algorithms")
975 (description "LightGBM is a gradient boosting framework that uses tree
976 based learning algorithms. It is designed to be distributed and efficient with
977 the following advantages:
980 @item Faster training speed and higher efficiency
981 @item Lower memory usage
982 @item Better accuracy
983 @item Parallel and GPU learning supported (not enabled in this package)
984 @item Capable of handling large-scale data
986 (license license:expat)))
988 (define-public vowpal-wabbit
989 ;; Language bindings not included.
991 (name "vowpal-wabbit")
996 (url "https://github.com/JohnLangford/vowpal_wabbit")
1000 "04bwzk6ifgnz3fmzid8b7avxf9n5pnx9xcjm61nkjng1vv0bpj8x"))
1001 (file-name (git-file-name name version))))
1007 (list (string-append "--with-boost="
1008 (assoc-ref %build-inputs "boost")))
1010 (modify-phases %standard-phases
1011 (add-after 'unpack 'make-files-writable
1013 (for-each make-file-writable (find-files "." ".*")) #t)))))
1014 (build-system gnu-build-system)
1015 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
1016 (synopsis "Fast machine learning library for online learning")
1017 (description "Vowpal Wabbit is a machine learning system with techniques
1018 such as online, hashing, allreduce, reductions, learning2search, active, and
1019 interactive learning.")
1020 (license license:bsd-3)))
1022 (define-public python2-fastlmm
1024 (name "python2-fastlmm")
1029 (uri (pypi-uri "fastlmm" version ".zip"))
1032 "1q8c34rpmwkfy3r4d5172pzdkpfryj561897z9r3x22gq7813x1m"))))
1033 (build-system python-build-system)
1035 `(#:tests? #f ; some test files are missing
1036 #:python ,python-2)) ; only Python 2.7 is supported
1038 `(("python2-numpy" ,python2-numpy)
1039 ("python2-scipy" ,python2-scipy)
1040 ("python2-matplotlib" ,python2-matplotlib)
1041 ("python2-pandas" ,python2-pandas)
1042 ("python2-scikit-learn" ,python2-scikit-learn)
1043 ("python2-pysnptools" ,python2-pysnptools)))
1046 ("python2-cython" ,python2-cython)
1047 ("python2-mock" ,python2-mock)
1048 ("python2-nose" ,python2-nose)))
1049 (home-page "http://research.microsoft.com/en-us/um/redmond/projects/mscompbio/fastlmm/")
1050 (synopsis "Perform genome-wide association studies on large data sets")
1052 "FaST-LMM, which stands for Factored Spectrally Transformed Linear Mixed
1053 Models, is a program for performing both single-SNP and SNP-set genome-wide
1054 association studies (GWAS) on extremely large data sets.")
1055 (license license:asl2.0)))
1057 ;; There have been no proper releases yet.
1058 (define-public kaldi
1059 (let ((commit "d4791c0f3fc1a09c042dac365e120899ee2ad21e")
1063 (version (git-version "0" revision commit))
1067 (url "https://github.com/kaldi-asr/kaldi")
1069 (file-name (git-file-name name version))
1072 "07k80my6f19mhrkwbzhjsnpf9871wmrwkl0ym468i830w67qyjrz"))))
1073 (build-system gnu-build-system)
1075 `(#:test-target "test"
1077 (modify-phases %standard-phases
1078 (add-after 'unpack 'chdir
1079 (lambda _ (chdir "src") #t))
1081 (lambda* (#:key build system inputs outputs #:allow-other-keys)
1082 (when (not (or (string-prefix? "x86_64" system)
1083 (string-prefix? "i686" system)))
1084 (substitute* "makefiles/linux_openblas.mk"
1085 (("-msse -msse2") "")))
1086 (substitute* "makefiles/default_rules.mk"
1087 (("/bin/bash") (which "bash")))
1088 (substitute* "Makefile"
1089 (("ext_depend: check_portaudio")
1091 (substitute* '("online/Makefile"
1092 "onlinebin/Makefile"
1093 "gst-plugin/Makefile")
1094 (("../../tools/portaudio/install")
1095 (assoc-ref inputs "portaudio")))
1097 ;; This `configure' script doesn't support variables passed as
1098 ;; arguments, nor does it support "prefix".
1099 (let ((out (assoc-ref outputs "out"))
1100 (openblas (assoc-ref inputs "openblas"))
1101 (openfst (assoc-ref inputs "openfst")))
1102 (substitute* "configure"
1103 (("check_for_slow_expf;") "")
1104 ;; This affects the RPATH and also serves as the installation
1106 (("KALDILIBDIR=`pwd`/lib")
1107 (string-append "KALDILIBDIR=" out "/lib")))
1108 (mkdir-p out) ; must exist
1109 (setenv "CONFIG_SHELL" (which "bash"))
1110 (setenv "OPENFST_VER" ,(package-version openfst))
1111 (invoke "./configure"
1114 (string-append "--openblas-root=" openblas)
1115 (string-append "--fst-root=" openfst)))))
1116 (add-after 'build 'build-ext-and-gstreamer-plugin
1118 (invoke "make" "-C" "online" "depend")
1119 (invoke "make" "-C" "online")
1120 (invoke "make" "-C" "onlinebin" "depend")
1121 (invoke "make" "-C" "onlinebin")
1122 (invoke "make" "-C" "gst-plugin" "depend")
1123 (invoke "make" "-C" "gst-plugin")
1125 ;; TODO: also install the executables.
1127 (lambda* (#:key outputs #:allow-other-keys)
1128 (let* ((out (assoc-ref outputs "out"))
1129 (inc (string-append out "/include"))
1130 (lib (string-append out "/lib")))
1132 ;; The build phase installed symlinks to the actual
1133 ;; libraries. Install the actual targets.
1134 (for-each (lambda (file)
1135 (let ((target (readlink file)))
1137 (install-file target lib)))
1138 (find-files lib "\\.so"))
1140 (for-each (lambda (file)
1141 (let ((target-dir (string-append inc "/" (dirname file))))
1142 (install-file file target-dir)))
1143 (find-files "." "\\.h"))
1144 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so"
1145 (string-append lib "/gstreamer-1.0"))
1148 `(("alsa-lib" ,alsa-lib)
1149 ("gfortran" ,gfortran "lib")
1151 ("gstreamer" ,gstreamer)
1153 ("openblas" ,openblas)
1154 ("openfst" ,openfst)
1155 ("portaudio" ,portaudio)
1156 ("python" ,python)))
1158 `(("glib" ,glib "bin") ; glib-genmarshal
1161 ("pkg-config" ,pkg-config)
1163 (home-page "https://kaldi-asr.org/")
1164 (synopsis "Speech recognition toolkit")
1165 (description "Kaldi is an extensible toolkit for speech recognition
1167 (license license:asl2.0))))
1169 (define-public gst-kaldi-nnet2-online
1170 (let ((commit "cb227ef43b66a9835c14eb0ad39e08ee03c210ad")
1173 (name "gst-kaldi-nnet2-online")
1174 (version (git-version "0" revision commit))
1178 (url "https://github.com/alumae/gst-kaldi-nnet2-online")
1180 (file-name (git-file-name name version))
1183 "1i6ffwiavxx07ri0lxix6s8q0r31x7i4xxvhys5jxkixf5q34w8g"))))
1184 (build-system gnu-build-system)
1186 `(#:tests? #f ; there are none
1188 (list (string-append "SHELL="
1189 (assoc-ref %build-inputs "bash") "/bin/bash")
1190 (string-append "KALDI_ROOT="
1191 (assoc-ref %build-inputs "kaldi-src"))
1192 (string-append "KALDILIBDIR="
1193 (assoc-ref %build-inputs "kaldi") "/lib")
1194 "KALDI_FLAVOR=dynamic")
1196 (modify-phases %standard-phases
1197 (add-after 'unpack 'chdir
1198 (lambda _ (chdir "src") #t))
1200 (lambda* (#:key inputs #:allow-other-keys)
1201 (let ((glib (assoc-ref inputs "glib")))
1202 (setenv "CXXFLAGS" "-fPIC")
1203 (setenv "CPLUS_INCLUDE_PATH"
1204 (string-append glib "/include/glib-2.0:"
1205 glib "/lib/glib-2.0/include:"
1206 (assoc-ref inputs "gstreamer")
1207 "/include/gstreamer-1.0")))
1208 (substitute* "Makefile"
1209 (("include \\$\\(KALDI_ROOT\\)/src/kaldi.mk") "")
1210 (("\\$\\(error Cannot find") "#"))
1212 (add-before 'build 'build-depend
1213 (lambda* (#:key make-flags #:allow-other-keys)
1214 (apply invoke "make" "depend" make-flags)))
1216 (lambda* (#:key outputs #:allow-other-keys)
1217 (let* ((out (assoc-ref outputs "out"))
1218 (lib (string-append out "/lib/gstreamer-1.0")))
1219 (install-file "libgstkaldinnet2onlinedecoder.so" lib)
1223 ("gstreamer" ,gstreamer)
1224 ("jansson" ,jansson)
1225 ("openfst" ,openfst)
1229 ("glib:bin" ,glib "bin") ; glib-genmarshal
1230 ("kaldi-src" ,(package-source kaldi))
1231 ("pkg-config" ,pkg-config)))
1232 (home-page "https://kaldi-asr.org/")
1233 (synopsis "Gstreamer plugin for decoding speech")
1234 (description "This package provides a GStreamer plugin that wraps
1235 Kaldi's @code{SingleUtteranceNnet2Decoder}. It requires iVector-adapted DNN
1236 acoustic models. The iVectors are adapted to the current audio stream
1238 (license license:asl2.0))))
1240 (define-public kaldi-gstreamer-server
1241 ;; This is the tip of the py3 branch
1242 (let ((commit "f68cab490be7eb0da2af1475fbc16655f50a60cb")
1245 (name "kaldi-gstreamer-server")
1246 (version (git-version "0" revision commit))
1250 (url "https://github.com/alumae/kaldi-gstreamer-server")
1252 (file-name (git-file-name name version))
1255 "17lh1368vkg8ngrcbn2phvigzlmalrqg6djx2gg61qq1a0nj87dm"))))
1256 (build-system gnu-build-system)
1258 `(#:tests? #f ; there are no tests that can be run automatically
1259 #:modules ((guix build utils)
1260 (guix build gnu-build-system)
1263 (modify-phases %standard-phases
1266 (lambda* (#:key outputs #:allow-other-keys)
1267 ;; Disable hash randomization to ensure the generated .pycs
1268 ;; are reproducible.
1269 (setenv "PYTHONHASHSEED" "0")
1270 (with-directory-excursion "kaldigstserver"
1271 ;; See https://github.com/alumae/kaldi-gstreamer-server/issues/232
1272 (substitute* "master_server.py"
1273 (("\\.replace\\('\\\\.*") ")"))
1275 ;; This is a Python 2 file
1276 (delete-file "decoder_test.py")
1277 (delete-file "test-buffer.py")
1279 (for-each (lambda (file)
1283 "-f" ; force rebuild
1285 (find-files "." "\\.py$")))
1288 (lambda* (#:key inputs outputs #:allow-other-keys)
1289 (let* ((out (assoc-ref outputs "out"))
1290 (bin (string-append out "/bin"))
1291 (share (string-append out "/share/kaldi-gstreamer-server/")))
1292 ;; Install Python files
1293 (with-directory-excursion "kaldigstserver"
1294 (for-each (cut install-file <> share)
1295 (find-files "." ".*")))
1297 ;; Install sample configuration files
1298 (for-each (cut install-file <> share)
1299 (find-files "." "\\.yaml"))
1301 ;; Install executables
1303 (let* ((server (string-append bin "/kaldi-gst-server"))
1304 (client (string-append bin "/kaldi-gst-client"))
1305 (worker (string-append bin "/kaldi-gst-worker"))
1306 (PYTHONPATH (getenv "PYTHONPATH"))
1307 (GST_PLUGIN_PATH (string-append
1308 (assoc-ref inputs "gst-kaldi-nnet2-online")
1309 "/lib/gstreamer-1.0:${GST_PLUGIN_PATH}"))
1310 (wrap (lambda (wrapper what)
1311 (with-output-to-file wrapper
1315 export PYTHONPATH=~a
1316 export GST_PLUGIN_PATH=~a
1317 exec ~a ~a/~a \"$@\"~%"
1318 (which "bash") PYTHONPATH GST_PLUGIN_PATH
1319 (which "python") share what)))
1320 (chmod wrapper #o555))))
1322 (list server client worker)
1323 (list "master_server.py"
1328 `(("gst-kaldi-nnet2-online" ,gst-kaldi-nnet2-online)
1329 ("python" ,python-wrapper)
1330 ("python-pygobject" ,python-pygobject)
1331 ("python-pyyaml" ,python-pyyaml)
1332 ("python-tornado" ,python-tornado-6)))
1333 (home-page "https://github.com/alumae/kaldi-gstreamer-server")
1334 (synopsis "Real-time full-duplex speech recognition server")
1335 (description "This is a real-time full-duplex speech recognition server,
1336 based on the Kaldi toolkit and the GStreamer framework and implemented in
1338 (license license:bsd-2))))
1340 ;; Note that Tensorflow includes a "third_party" directory, which seems to not
1341 ;; only contain modified subsets of upstream library source code, but also
1342 ;; adapter headers provided by Google (such as the fft.h header, which is not
1343 ;; part of the upstream project code). The Tensorflow code includes headers
1344 ;; from the "third_party" directory. It does not look like we can replace
1345 ;; these headers with unmodified upstream files, so we keep them.
1346 (define-public tensorflow
1354 (url "https://github.com/tensorflow/tensorflow")
1355 (commit (string-append "v" version))))
1356 (file-name (string-append "tensorflow-" version "-checkout"))
1359 "0a9kwha395g3wgxfwln5j8vn9nkspmd75xldrlqdq540w996g8xa"))))
1360 (build-system cmake-build-system)
1362 `(#:tests? #f ; no "check" target
1363 #:build-type "Release"
1365 (let ((protobuf (assoc-ref %build-inputs "protobuf"))
1366 (protobuf:native (assoc-ref %build-inputs "protobuf:native"))
1367 (jsoncpp (assoc-ref %build-inputs "jsoncpp"))
1368 (snappy (assoc-ref %build-inputs "snappy"))
1369 (sqlite (assoc-ref %build-inputs "sqlite")))
1371 ;; Use protobuf from Guix
1372 (string-append "-Dprotobuf_STATIC_LIBRARIES="
1373 protobuf "/lib/libprotobuf.so")
1374 (string-append "-DPROTOBUF_PROTOC_EXECUTABLE="
1375 protobuf:native "/bin/protoc")
1377 ;; Use snappy from Guix
1378 (string-append "-Dsnappy_STATIC_LIBRARIES="
1379 snappy "/lib/libsnappy.so")
1380 ;; Yes, this is not actually the include directory but a prefix...
1381 (string-append "-Dsnappy_INCLUDE_DIR=" snappy)
1383 ;; Use jsoncpp from Guix
1384 (string-append "-Djsoncpp_STATIC_LIBRARIES="
1385 jsoncpp "/lib/libjsoncpp.so")
1386 ;; Yes, this is not actually the include directory but a prefix...
1387 (string-append "-Djsoncpp_INCLUDE_DIR=" jsoncpp)
1389 ;; Use sqlite from Guix
1390 (string-append "-Dsqlite_STATIC_LIBRARIES="
1391 sqlite "/lib/libsqlite.a")
1393 ;; Use system libraries wherever possible. Currently, this
1394 ;; only affects zlib.
1395 "-Dsystemlib_ALL=ON"
1396 "-Dtensorflow_ENABLE_POSITION_INDEPENDENT_CODE=ON"
1397 "-Dtensorflow_BUILD_SHARED_LIB=ON"
1398 "-Dtensorflow_OPTIMIZE_FOR_NATIVE_ARCH=OFF"
1399 "-Dtensorflow_ENABLE_SSL_SUPPORT=OFF"
1400 "-Dtensorflow_BUILD_CONTRIB_KERNELS=OFF"))
1403 #:modules ((ice-9 ftw)
1405 (guix build cmake-build-system)
1406 ((guix build python-build-system)
1407 #:select (python-version)))
1408 #:imported-modules (,@%cmake-build-system-modules
1409 (guix build python-build-system))
1411 (modify-phases %standard-phases
1412 (add-after 'unpack 'set-source-file-times-to-1980
1413 ;; At the end of the tf_python_build_pip_package target, a ZIP
1414 ;; archive should be generated via bdist_wheel, but it fails with
1415 ;; "ZIP does not support timestamps before 1980". Luckily,
1416 ;; SOURCE_DATE_EPOCH is respected, which we set to some time in
1418 (lambda _ (setenv "SOURCE_DATE_EPOCH" "315532800") #t))
1419 ;; See https://github.com/tensorflow/tensorflow/issues/20517#issuecomment-406373913
1420 (add-after 'unpack 'python3.7-compatibility
1422 (substitute* '("tensorflow/python/eager/pywrap_tfe_src.cc"
1423 "tensorflow/python/lib/core/ndarray_tensor.cc"
1424 "tensorflow/python/lib/core/py_func.cc")
1425 (("PyUnicode_AsUTF8") "(char *)PyUnicode_AsUTF8"))
1426 (substitute* "tensorflow/c/eager/c_api.h"
1427 (("unsigned char async")
1428 "unsigned char is_async"))
1430 ;; Remove dependency on tensorboard, a complicated but probably
1431 ;; optional package.
1432 (substitute* "tensorflow/tools/pip_package/setup.py"
1433 ((".*'tensorboard >.*") ""))
1435 ;; Fix the build with python-3.8, taken from rejected upstream patch:
1436 ;; https://github.com/tensorflow/tensorflow/issues/34197
1437 (substitute* (find-files "tensorflow/python" ".*\\.cc$")
1438 (("(nullptr,)(\\ +/. tp_print)" _ _ tp_print)
1439 (string-append "NULL, " tp_print)))
1441 (add-after 'python3.7-compatibility 'chdir
1442 (lambda _ (chdir "tensorflow/contrib/cmake") #t))
1443 (add-after 'chdir 'disable-downloads
1444 (lambda* (#:key inputs #:allow-other-keys)
1445 (substitute* (find-files "external" "\\.cmake$")
1446 (("GIT_REPOSITORY.*") "")
1449 "DOWNLOAD_COMMAND \"\"\nPREFIX "))
1451 ;; Use packages from Guix
1452 (let ((grpc (assoc-ref inputs "grpc")))
1453 (substitute* "CMakeLists.txt"
1455 (("include\\(sqlite\\)") "")
1456 (("\\$\\{sqlite_STATIC_LIBRARIES\\}")
1457 (string-append (assoc-ref inputs "sqlite")
1458 "/lib/libsqlite3.so"))
1459 (("sqlite_copy_headers_to_destination") "")
1462 (("include\\(png\\)") "")
1463 (("\\$\\{png_STATIC_LIBRARIES\\}")
1464 (string-append (assoc-ref inputs "libpng")
1465 "/lib/libpng16.so"))
1466 (("png_copy_headers_to_destination") "")
1469 (("include\\(jpeg\\)") "")
1470 (("\\$\\{jpeg_STATIC_LIBRARIES\\}")
1471 (string-append (assoc-ref inputs "libjpeg")
1473 (("jpeg_copy_headers_to_destination") "")
1476 (("include\\(gif\\)") "")
1477 (("\\$\\{gif_STATIC_LIBRARIES\\}")
1478 (string-append (assoc-ref inputs "giflib")
1480 (("gif_copy_headers_to_destination") "")
1483 (("include\\(lmdb\\)") "")
1484 (("\\$\\{lmdb_STATIC_LIBRARIES\\}")
1485 (string-append (assoc-ref inputs "lmdb")
1487 (("lmdb_copy_headers_to_destination") "")
1490 (("include\\(protobuf\\)") "")
1491 (("protobuf_copy_headers_to_destination") "")
1492 (("^ +protobuf") "")
1495 (("include\\(grpc\\)")
1496 "find_package(grpc REQUIRED NAMES gRPC)")
1497 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES grpc\\)") "")
1500 (("include\\(eigen\\)")
1501 (string-append "find_package(eigen REQUIRED NAMES Eigen3)
1502 set(eigen_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/external/eigen_archive "
1503 (assoc-ref inputs "eigen") "/include/eigen3)"))
1507 (("include\\(snappy\\)")
1508 "add_definitions(-DTF_USE_SNAPPY)")
1509 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES snappy\\)") "")
1512 (("include\\(jsoncpp\\)") "")
1513 (("^ +jsoncpp") ""))
1515 (substitute* "tf_core_framework.cmake"
1517 (("\\$\\{GRPC_BUILD\\}/grpc_cpp_plugin")
1518 (which "grpc_cpp_plugin"))
1519 ;; Link with gRPC libraries
1520 (("add_library\\(tf_protos_cc.*" m)
1522 (format #f "\ntarget_link_libraries(tf_protos_cc PRIVATE \
1523 ~a/lib/libgrpc++_unsecure.a \
1524 ~a/lib/libgrpc_unsecure.a \
1525 ~a/lib/libaddress_sorting.a \
1530 (assoc-ref inputs "c-ares"))))))
1531 (substitute* "tf_tools.cmake"
1532 (("add_dependencies\\(\\$\\{proto_text.*") ""))
1533 ;; Remove dependency on bundled grpc
1534 (substitute* "tf_core_distributed_runtime.cmake"
1535 (("tf_core_cpu grpc") "tf_core_cpu"))
1537 ;; This directory is a dependency of many targets.
1538 (mkdir-p "protobuf")
1540 (add-after 'configure 'unpack-third-party-sources
1541 (lambda* (#:key inputs #:allow-other-keys)
1542 ;; This is needed to configure bundled packages properly.
1543 (setenv "CONFIG_SHELL" (which "bash"))
1546 (let* ((what (assoc-ref inputs (string-append name "-src")))
1547 (name* (string-map (lambda (c)
1550 (where (string-append "../build/" name* "/src/" name*)))
1552 ((string-suffix? ".zip" what)
1554 (with-directory-excursion where
1555 (invoke "unzip" what)))
1556 ((string-suffix? ".tar.gz" what)
1558 (invoke "tar" "xf" what
1559 "-C" where "--strip-components=1"))
1561 (let ((parent (dirname where)))
1563 (with-directory-excursion parent
1564 (when (file-exists? name*)
1565 (delete-file-recursively name*))
1566 (copy-recursively what name*)
1567 (map make-file-writable
1568 (find-files name* ".*"))))))))
1578 (rename-file "../build/cub/src/cub/cub-1.8.0/"
1579 "../build/cub/src/cub/cub/")
1581 (add-after 'unpack 'fix-python-build
1582 (lambda* (#:key inputs outputs #:allow-other-keys)
1583 (mkdir-p "protobuf-src")
1584 (invoke "tar" "xf" (assoc-ref inputs "protobuf:src")
1585 "-C" "protobuf-src" "--strip-components=1")
1586 (mkdir-p "eigen-src")
1587 (invoke "tar" "xf" (assoc-ref inputs "eigen:src")
1588 "-C" "eigen-src" "--strip-components=1")
1590 (substitute* "tensorflow/contrib/cmake/tf_python.cmake"
1591 ;; Ensure that all Python dependencies can be found at build time.
1592 (("PYTHONPATH=\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/tf_python" m)
1593 (string-append m ":" (getenv "PYTHONPATH")))
1594 ;; Take protobuf source files from our source package.
1595 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/protobuf/src/protobuf/src/google")
1596 (string-append (getcwd) "/protobuf-src/src/google")))
1598 (substitute* '("tensorflow/contrib/cmake/tf_shared_lib.cmake"
1599 "tensorflow/contrib/cmake/tf_python.cmake")
1600 ;; Take Eigen source files from our source package.
1601 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/eigen/src/eigen/")
1602 (string-append (getcwd) "/eigen-src/"))
1603 ;; Take Eigen headers from our own package.
1604 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/external/eigen_archive")
1605 (string-append (assoc-ref inputs "eigen") "/include/eigen3")))
1607 ;; Correct the RUNPATH of ops libraries generated for Python.
1608 ;; TODO: this doesn't work :(
1609 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1610 ;; warning: RUNPATH contains bogus entries: ("/tmp/guix-build-tensorflow-1.9.0.drv-0/source/tensorflow/contrib/build")
1611 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1612 ;; error: depends on 'libpywrap_tensorflow_internal.so', which
1613 ;; cannot be found in RUNPATH ...
1614 (substitute* "tensorflow/contrib/cmake/tf_cc_ops.cmake"
1615 (("set_target_properties.*")
1616 (string-append "set_target_properties(${_AT_TARGET} PROPERTIES \
1617 COMPILE_FLAGS ${target_compile_flags} \
1618 INSTALL_RPATH_USE_LINK_PATH TRUE \
1619 INSTALL_RPATH " (assoc-ref outputs "out") "/lib)\n")))
1621 (add-after 'build 'build-pip-package
1622 (lambda* (#:key outputs #:allow-other-keys)
1624 (string-append "-Wl,-rpath="
1625 (assoc-ref outputs "out") "/lib"))
1626 (invoke "make" "tf_python_build_pip_package")
1628 (add-after 'build-pip-package 'install-python
1629 (lambda* (#:key inputs outputs #:allow-other-keys)
1630 (let ((out (assoc-ref outputs "out"))
1631 (wheel (car (find-files "../build/tf_python/dist/" "\\.whl$")))
1632 (python-version (python-version
1633 (assoc-ref inputs "python"))))
1634 (invoke "python" "-m" "pip" "install" wheel
1635 (string-append "--prefix=" out))
1637 ;; XXX: broken RUNPATH, see fix-python-build phase.
1640 out "/lib/python" python-version
1641 "/site-packages/tensorflow/contrib/"
1642 "seq2seq/python/ops/lib_beam_search_ops.so"))
1645 `(("pkg-config" ,pkg-config)
1646 ("protobuf:native" ,protobuf-3.6) ; protoc
1647 ("protobuf:src" ,(package-source protobuf-3.6))
1648 ("eigen:src" ,(package-source eigen-for-tensorflow))
1649 ;; install_pip_packages.sh wants setuptools 39.1.0 specifically.
1650 ("python-setuptools" ,python-setuptools-for-tensorflow)
1652 ;; The commit hashes and URLs for third-party source code are taken
1653 ;; from "tensorflow/workspace.bzl".
1655 ,(let ((commit "ee7aa02")
1660 (url "https://boringssl.googlesource.com/boringssl")
1662 (file-name (string-append "boringssl-0-" revision
1663 (string-take commit 7)
1667 "1jf693q0nw0adsic6cgmbdx6g7wr4rj4vxa8j1hpn792fqhd8wgw")))))
1669 ,(let ((version "1.8.0"))
1672 (uri (string-append "https://mirror.bazel.build/github.com/NVlabs/"
1673 "cub/archive/" version ".zip"))
1674 (file-name (string-append "cub-" version ".zip"))
1677 "1hsqikqridb90dkxkjr2918dcry6pfh46ccnwrzawl56aamhdykb")))))
1678 ("double-conversion-src"
1679 ,(let ((commit "5664746")
1684 (url "https://github.com/google/double-conversion")
1687 (git-file-name "double-conversion"
1688 (string-append "0-" revision "."
1689 (string-take commit 7))))
1692 "1h5lppqqxcvdg5jq42i5msgwx20ryij3apvmndflngrgdpc04gn1")))))
1694 ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45"))
1698 "https://mirror.bazel.build/github.com/google/farmhash/archive/"
1700 (file-name (string-append "farmhash-0-" (string-take commit 7)
1704 "185b2xdxl4d4cnsnv6abg8s22gxvx8673jq2yaq85bz4cdy58q35")))))
1705 ;; The license notice on the home page at
1706 ;; http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html says:
1707 ;; Copyright Takuya OOURA, 1996-2001
1709 ;; You may use, copy, modify and distribute this code for any purpose
1710 ;; (include commercial use) and without fee. Please refer to this
1711 ;; package when you modify this code.
1713 ;; We take the identical tarball from the Bazel mirror, because the URL
1714 ;; at the home page is not versioned and might change.
1718 (uri "https://mirror.bazel.build/www.kurims.kyoto-u.ac.jp/~ooura/fft.tgz")
1719 (file-name "fft2d.tar.gz")
1722 "15jjkfvhqvl2c0753d2di8hz0pyzn598g74wqy79awdrf1y67fsj"))))
1724 ,(let ((commit "be5edafc2e1a455768e260ccd68ae7317b6690ee")
1729 (url "https://github.com/google/highwayhash")
1731 (file-name (string-append "highwayhash-0-" revision
1732 (string-take commit 7)
1736 "154jwf98cyy54hldr94pgjn85zynly3abpnc1avmb8a18lzwjyb6")))))
1738 ,(let ((version "0559ce013feac8db639ee1bf776aca0325d28777")
1742 (uri (string-append "https://mirror.bazel.build/"
1743 "github.com/google/nsync/archive/"
1745 (file-name (string-append "nsync-0." revision
1746 "-" (string-take version 7)
1750 "0qdkyqym34x739mmzv97ah5r7ph462v5xkxqxvidmcfqbi64b132")))))
1752 ,(let ((commit "e7efc48")
1757 (url "https://github.com/google/re2")
1759 (file-name (string-append "re2-0-" revision
1760 (string-take commit 7)
1764 "161g9841rjfsy5pn52fcis0s9hdr7rxvb06pad38j5rppfihvign")))))
1765 ("googletest" ,googletest)
1769 `(("python-absl-py" ,python-absl-py)
1770 ("python-astor" ,python-astor)
1771 ("python-gast" ,python-gast)
1772 ("python-grpcio" ,python-grpcio)
1773 ("python-numpy" ,python-numpy)
1774 ("python-protobuf" ,python-protobuf-3.6)
1775 ("python-six" ,python-six)
1776 ("python-termcolo" ,python-termcolor)
1777 ("python-wheel" ,python-wheel)))
1779 `(("c-ares" ,c-ares)
1780 ("eigen" ,eigen-for-tensorflow)
1781 ("gemmlowp" ,gemmlowp-for-tensorflow)
1783 ("libjpeg" ,libjpeg-turbo)
1786 ("grpc" ,grpc-1.16.1 "static")
1787 ("grpc:bin" ,grpc-1.16.1)
1788 ("jsoncpp" ,jsoncpp-for-tensorflow)
1791 ("protobuf" ,protobuf-3.6)
1792 ("python" ,python-wrapper)
1794 (home-page "https://tensorflow.org")
1795 (synopsis "Machine learning framework")
1797 "TensorFlow is a flexible platform for building and training machine
1798 learning models. It provides a library for high performance numerical
1799 computation and includes high level Python APIs, including both a sequential
1800 API for beginners that allows users to build models quickly by plugging
1801 together building blocks and a subclassing API with an imperative style for
1802 advanced research.")
1803 (license license:asl2.0)))
1805 (define-public python-iml
1812 (uri (pypi-uri "iml" version))
1815 "1k8szlpm19rcwcxdny9qdm3gmaqq8akb4xlvrzyz8c2d679aak6l"))))
1816 (build-system python-build-system)
1818 `(("ipython" ,python-ipython)
1819 ("numpy" ,python-numpy)
1820 ("pandas" ,python-pandas)
1821 ("scipy" ,python-scipy)))
1823 `(("nose" ,python-nose)))
1824 (home-page "https://github.com/interpretable-ml/iml")
1825 (synopsis "Interpretable Machine Learning (iML) package")
1826 (description "Interpretable ML (iML) is a set of data type objects,
1827 visualizations, and interfaces that can be used by any method designed to
1828 explain the predictions of machine learning models (or really the output of
1829 any function). It currently contains the interface and IO code from the Shap
1830 project, and it will potentially also do the same for the Lime project.")
1831 (license license:expat)))
1833 (define-public python-keras-applications
1835 (name "python-keras-applications")
1840 (uri (pypi-uri "Keras_Applications" version))
1843 "1rcz31ca4axa6kzhjx4lwqxbg4wvlljkj8qj9a7p9sfd5fhzjyam"))))
1844 (build-system python-build-system)
1845 ;; The tests require Keras, but this package is needed to build Keras.
1846 (arguments '(#:tests? #f))
1848 `(("python-h5py" ,python-h5py)
1849 ("python-numpy" ,python-numpy)))
1851 `(("python-pytest" ,python-pytest)
1852 ("python-pytest-cov" ,python-pytest-cov)
1853 ("python-pytest-pep8" ,python-pytest-pep8)
1854 ("python-pytest-xdist" ,python-pytest-xdist)))
1855 (home-page "https://github.com/keras-team/keras-applications")
1856 (synopsis "Reference implementations of popular deep learning models")
1858 "This package provides reference implementations of popular deep learning
1859 models for use with the Keras deep learning framework.")
1860 (license license:expat)))
1862 (define-public python-keras-preprocessing
1864 (name "python-keras-preprocessing")
1869 (uri (pypi-uri "Keras_Preprocessing" version))
1872 "1r98nm4k1svsqjyaqkfk23i31bl1kcfcyp7094yyj3c43phfp3as"))))
1873 (build-system python-build-system)
1875 `(("python-numpy" ,python-numpy)
1876 ("python-six" ,python-six)))
1878 `(("python-pandas" ,python-pandas)
1879 ("python-pillow" ,python-pillow)
1880 ("python-pytest" ,python-pytest)
1881 ("python-pytest-cov" ,python-pytest-cov)
1882 ("python-pytest-xdist" ,python-pytest-xdist)
1883 ("tensorflow" ,tensorflow)))
1884 (home-page "https://github.com/keras-team/keras-preprocessing/")
1885 (synopsis "Data preprocessing and augmentation for deep learning models")
1887 "Keras Preprocessing is the data preprocessing and data augmentation
1888 module of the Keras deep learning library. It provides utilities for working
1889 with image data, text data, and sequence data.")
1890 (license license:expat)))
1892 (define-public python-keras
1894 (name "python-keras")
1899 (uri (pypi-uri "Keras" version))
1900 (patches (search-patches "python-keras-integration-test.patch"))
1903 "1j8bsqzh49vjdxy6l1k4iwax5vpjzniynyd041xjavdzvfii1dlh"))))
1904 (build-system python-build-system)
1907 (modify-phases %standard-phases
1908 (add-after 'unpack 'remove-tests-for-unavailable-features
1910 (delete-file "keras/backend/theano_backend.py")
1911 (delete-file "keras/backend/cntk_backend.py")
1912 (delete-file "tests/keras/backend/backend_test.py")
1914 ;; FIXME: This doesn't work because Tensorflow is missing the
1915 ;; coder ops library.
1916 (delete-file "tests/keras/test_callbacks.py")
1920 ;; These tests attempt to download data files from the internet.
1921 (delete-file "tests/integration_tests/test_datasets.py")
1922 (delete-file "tests/integration_tests/imagenet_utils_test.py")
1924 (setenv "PYTHONPATH"
1925 (string-append (getcwd) "/build/lib:"
1926 (getenv "PYTHONPATH")))
1927 (invoke "py.test" "-v"
1928 "-p" "no:cacheprovider"
1929 "--ignore" "keras/utils"))))))
1931 `(("python-h5py" ,python-h5py)
1932 ("python-keras-applications" ,python-keras-applications)
1933 ("python-keras-preprocessing" ,python-keras-preprocessing)
1934 ("python-numpy" ,python-numpy)
1935 ("python-pydot" ,python-pydot)
1936 ("python-pyyaml" ,python-pyyaml)
1937 ("python-scipy" ,python-scipy)
1938 ("python-six" ,python-six)
1939 ("tensorflow" ,tensorflow)
1940 ("graphviz" ,graphviz)))
1942 `(("python-pandas" ,python-pandas)
1943 ("python-pytest" ,python-pytest)
1944 ("python-pytest-cov" ,python-pytest-cov)
1945 ("python-pytest-pep8" ,python-pytest-pep8)
1946 ("python-pytest-timeout" ,python-pytest-timeout)
1947 ("python-pytest-xdist" ,python-pytest-xdist)
1948 ("python-sphinx" ,python-sphinx)
1949 ("python-requests" ,python-requests)))
1950 (home-page "https://github.com/keras-team/keras")
1951 (synopsis "High-level deep learning framework")
1952 (description "Keras is a high-level neural networks API, written in Python
1953 and capable of running on top of TensorFlow. It was developed with a focus on
1954 enabling fast experimentation. Use Keras if you need a deep learning library
1958 @item Allows for easy and fast prototyping (through user friendliness,
1959 modularity, and extensibility).
1960 @item Supports both convolutional networks and recurrent networks, as well as
1961 combinations of the two.
1962 @item Runs seamlessly on CPU and GPU.
1964 (license license:expat)))
1967 (let ((version "0.0.0") ; no proper version tag
1968 (commit "ca528e32fea9ca8f2b16053cff17160290fc84ce")
1972 (version (git-version version revision commit))
1977 (url "https://github.com/facebookincubator/gloo")
1979 (file-name (git-file-name name version))
1982 "1q9f80zy75f6njrzrqkmhc0g3qxs4gskr7ns2jdqanxa2ww7a99w"))))
1983 (build-system cmake-build-system)
1985 `(("googletest" ,googletest)))
1987 `(#:configure-flags '("-DBUILD_TEST=1")
1989 (modify-phases %standard-phases
1992 (invoke "make" "gloo_test")
1994 (synopsis "Collective communications library")
1996 "Gloo is a collective communications library. It comes with a
1997 number of collective algorithms useful for machine learning applications.
1998 These include a barrier, broadcast, and allreduce.")
1999 (home-page "https://github.com/facebookincubator/gloo")
2000 (license license:bsd-3))))
2002 (define-public python-umap-learn
2004 (name "python-umap-learn")
2009 (uri (pypi-uri "umap-learn" version))
2012 "02ada2yy6km6zgk2836kg1c97yrcpalvan34p8c57446finnpki1"))))
2013 (build-system python-build-system)
2015 `(("python-joblib" ,python-joblib)
2016 ("python-nose" ,python-nose)))
2018 `(("python-numba" ,python-numba)
2019 ("python-numpy" ,python-numpy)
2020 ("python-scikit-learn" ,python-scikit-learn)
2021 ("python-scipy" ,python-scipy)))
2022 (home-page "https://github.com/lmcinnes/umap")
2024 "Uniform Manifold Approximation and Projection")
2026 "Uniform Manifold Approximation and Projection is a dimension reduction
2027 technique that can be used for visualisation similarly to t-SNE, but also for
2028 general non-linear dimension reduction.")
2029 (license license:bsd-3)))