Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voice recognition (fixes #58) #59

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions horde-ad.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,18 @@ library testLibrary
exposed-modules: TestMnistCNN
TestMnistFCNN
TestMnistRNN
TestSpeechRNN
TestSimpleDescent
TestSingleGradient
}

-- Other library packages from which modules are imported.
build-depends:
base
, bytestring
, cereal
, deepseq
, directory
, HUnit-approx
, hmatrix
, horde-ad
Expand Down
1 change: 1 addition & 0 deletions src/HordeAd/Core/Optimizer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module HordeAd.Core.Optimizer
, sgd
, sgdAdam, sgdAdamArgs
, StateAdam, initialStateAdam
, mapDomains
) where

import Prelude
Expand Down
20 changes: 13 additions & 7 deletions src/HordeAd/Core/OptimizerTools.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE TypeFamilies #-}
-- | Tools for implementing (and debugging the use of) gradient descent schemes.
module HordeAd.Core.OptimizerTools
( updateWithGradient
( mapDomains, updateWithGradient
, gradientIsNil, minimumGradient, maximumGradient
, ArgsAdam(..), defaultArgsAdam
, StateAdam(..), initialStateAdam
Expand All @@ -22,6 +22,7 @@ import Numeric.LinearAlgebra.Devel
(MatrixOrder (..), liftMatrix, liftMatrix2, matrixFromVector, orderOf)

import HordeAd.Internal.Delta (Domains, isTensorDummy)
import HordeAd.Internal.OrthotopeOrphanInstances (liftVT)

{-
60% of heap allocation in matrix- and vector-based MNIST
Expand Down Expand Up @@ -144,18 +145,23 @@ data StateAdam r = StateAdam
, vAdam :: Domains r
}

-- The arguments are just sample params0, for dimensions.
mapDomains :: (Numeric r1, Numeric r2)
=> (Vector r1 -> Vector r2) -> Domains r1 -> Domains r2
mapDomains f (params0, params1, params2, paramsX) =
( f params0
, V.map f params1
, V.map (liftMatrix f) params2
, V.map (liftVT f) paramsX )

-- The arguments are just sample params, for dimensions.
zeroParameters :: Numeric r
=> Domains r -> Domains r
zeroParameters (params0, params1, params2, paramsX) =
zeroParameters domains =
let zeroVector v = runST $ do
vThawed <- V.thaw v
VM.set vThawed 0
V.unsafeFreeze vThawed
in ( zeroVector params0
, V.map zeroVector params1
, V.map (liftMatrix zeroVector) params2
, V.map (\a -> OT.constant (OT.shapeL a) 0) paramsX ) -- fast allright
in mapDomains zeroVector domains

initialStateAdam :: Numeric r
=> Domains r -> StateAdam r
Expand Down
6 changes: 3 additions & 3 deletions src/HordeAd/Internal/OrthotopeOrphanInstances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import Numeric.LinearAlgebra (Matrix, Numeric, Vector)
import qualified Numeric.LinearAlgebra as HM
import qualified Numeric.LinearAlgebra.Devel

liftVT :: Numeric r
=> (Vector r -> Vector r)
-> OT.Array r -> OT.Array r
liftVT :: (Numeric r1, Numeric r2)
=> (Vector r1 -> Vector r2)
-> OT.Array r1 -> OT.Array r2
liftVT op t = OT.fromVector (OT.shapeL t) $ op $ OT.toVector t

liftVT2 :: Numeric r
Expand Down
2 changes: 2 additions & 0 deletions test/ExtremelyLongTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import qualified TestMnistFCNN
import qualified TestMnistRNN
import qualified TestSimpleDescent
import qualified TestSingleGradient
import qualified TestSpeechRNN
#endif

main :: IO ()
Expand All @@ -46,5 +47,6 @@ tests = testGroup "Tests" $
++ TestSimpleDescent.testTrees
++ TestMnistFCNN.testTrees
++ TestMnistRNN.testTrees
++ TestSpeechRNN.testTrees
++ TestMnistCNN.testTrees
#endif
2 changes: 2 additions & 0 deletions test/ShortTestForCI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import qualified TestMnistFCNN
import qualified TestMnistRNN
import qualified TestSimpleDescent
import qualified TestSingleGradient
import qualified TestSpeechRNN
#endif

main :: IO ()
Expand All @@ -41,6 +42,7 @@ tests = testGroup "Short tests for CI" $
++ TestSimpleDescent.testTrees
++ TestMnistFCNN.shortTestForCITrees
++ TestMnistRNN.shortTestForCITrees
++ TestSpeechRNN.shortTestForCITrees
++ TestMnistCNN.shortTestForCITrees
#else
[]
Expand Down
Loading