feat(Numeric): move all modules to Numeric
This commit is contained in:
parent
506b180498
commit
ed6d2b3021
@ -1,5 +1,5 @@
|
|||||||
module Main where
|
module Main where
|
||||||
import Sibe
|
import Numeric.Sibe
|
||||||
import Numeric.LinearAlgebra
|
import Numeric.LinearAlgebra
|
||||||
import Data.List
|
import Data.List
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
module Main
|
module Main
|
||||||
where
|
where
|
||||||
-- import Sibe
|
import Numeric.Sibe.NLP
|
||||||
import Sibe.NLP
|
import Numeric.Sibe.NaiveBayes
|
||||||
import Sibe.NaiveBayes
|
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
import Sibe
|
import Numeric.Sibe
|
||||||
import Numeric.LinearAlgebra
|
import Numeric.LinearAlgebra
|
||||||
import Data.List
|
import Data.List
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
import Sibe
|
import Numeric.Sibe
|
||||||
import Sibe.Word2Vec
|
import Numeric.Sibe.Word2Vec
|
||||||
import Sibe.Utils
|
import Numeric.Sibe.Utils
|
||||||
import Data.Default.Class
|
import Data.Default.Class
|
||||||
import qualified Data.Vector.Storable as V
|
import qualified Data.Vector.Storable as V
|
||||||
import Data.List (sortBy)
|
import Data.List (sortBy)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module Main where
|
module Main where
|
||||||
import Sibe
|
import Numeric.Sibe
|
||||||
import Numeric.LinearAlgebra
|
import Numeric.LinearAlgebra
|
||||||
import Data.List
|
import Data.List
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: sibe
|
name: sibe
|
||||||
version: 0.1.0.1
|
version: 0.2.0.0
|
||||||
synopsis: Machine Learning algorithms
|
synopsis: Machine Learning algorithms
|
||||||
description: Haskell Machine Learning
|
description: Haskell Machine Learning
|
||||||
homepage: https://github.com/mdibaiee/sibe
|
homepage: https://github.com/mdibaiee/sibe
|
||||||
@ -15,7 +15,7 @@ cabal-version: >=1.10
|
|||||||
|
|
||||||
library
|
library
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
exposed-modules: Sibe, Sibe.NaiveBayes, Sibe.NLP, Sibe.Word2Vec, Sibe.Utils
|
exposed-modules: Numeric.Sibe, Numeric.Sibe.NaiveBayes, Numeric.Sibe.NLP, Numeric.Sibe.Word2Vec, Numeric.Sibe.Utils
|
||||||
build-depends: base >= 4.7 && < 5
|
build-depends: base >= 4.7 && < 5
|
||||||
, hmatrix
|
, hmatrix
|
||||||
, random
|
, random
|
||||||
|
BIN
src/Lib.hi
BIN
src/Lib.hi
Binary file not shown.
@ -3,7 +3,7 @@
|
|||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
|
|
||||||
module Sibe
|
module Numeric.Sibe
|
||||||
(Network(..),
|
(Network(..),
|
||||||
Layer(..),
|
Layer(..),
|
||||||
Input,
|
Input,
|
@ -1,4 +1,4 @@
|
|||||||
module Sibe.NLP
|
module Numeric.Sibe.NLP
|
||||||
(Class,
|
(Class,
|
||||||
Document(..),
|
Document(..),
|
||||||
accuracy,
|
accuracy,
|
||||||
@ -13,7 +13,7 @@ module Sibe.NLP
|
|||||||
ngramText,
|
ngramText,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Sibe.Utils
|
import Numeric.Sibe.Utils
|
||||||
import Data.List
|
import Data.List
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
import Data.List.Split
|
import Data.List.Split
|
@ -1,4 +1,4 @@
|
|||||||
module Sibe.NaiveBayes
|
module Numeric.Sibe.NaiveBayes
|
||||||
(Document(..),
|
(Document(..),
|
||||||
NB(..),
|
NB(..),
|
||||||
initialize,
|
initialize,
|
||||||
@ -18,8 +18,8 @@ module Sibe.NaiveBayes
|
|||||||
removeStopwords,
|
removeStopwords,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Sibe.Utils
|
import Numeric.Sibe.Utils
|
||||||
import Sibe.NLP
|
import Numeric.Sibe.NLP
|
||||||
import Data.List
|
import Data.List
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
@ -1,4 +1,4 @@
|
|||||||
module Sibe.Utils
|
module Numeric.Sibe.Utils
|
||||||
( similarity
|
( similarity
|
||||||
, ordNub
|
, ordNub
|
||||||
, onehot
|
, onehot
|
@ -1,12 +1,12 @@
|
|||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
|
||||||
module Sibe.Word2Vec
|
module Numeric.Sibe.Word2Vec
|
||||||
( word2vec
|
( word2vec
|
||||||
, Word2Vec (..)
|
, Word2Vec (..)
|
||||||
, W2VMethod (..)
|
, W2VMethod (..)
|
||||||
) where
|
) where
|
||||||
import Sibe
|
import Numeric.Sibe
|
||||||
import Sibe.Utils
|
import Numeric.Sibe.Utils
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
import Data.Char
|
import Data.Char
|
||||||
import Data.Maybe
|
import Data.Maybe
|
@ -1,44 +0,0 @@
|
|||||||
module Sibe.Word2Vec
|
|
||||||
(word2vec,
|
|
||||||
mapTuple
|
|
||||||
) where
|
|
||||||
import Sibe
|
|
||||||
import Sibe.NLP
|
|
||||||
import Debug.Trace
|
|
||||||
import Data.Char
|
|
||||||
import Data.Maybe
|
|
||||||
import Data.List
|
|
||||||
import Numeric.LinearAlgebra hiding (find)
|
|
||||||
import qualified Data.Vector.Storable as V
|
|
||||||
|
|
||||||
word2vec docs session = do
|
|
||||||
let cooccurence = concat $ map co docs
|
|
||||||
a = (sigmoid, sigmoid')
|
|
||||||
o = (softmax, crossEntropy')
|
|
||||||
window = 2
|
|
||||||
s = session { training = cooccurence
|
|
||||||
, test = cooccurence
|
|
||||||
, network = buildNetwork 0 (-1, 1) n [(n, 300, (id, id))] (300, n, (softmax, crossEntropy'))
|
|
||||||
}
|
|
||||||
print $ network s
|
|
||||||
newses <- run gd s
|
|
||||||
return (newses, cooccurence, vocabulary, vocvec)
|
|
||||||
where
|
|
||||||
n = length vocabulary
|
|
||||||
vocabulary = ordNub . words . map toLower . concatMap (++ " ") $ docs
|
|
||||||
vocvec = zip vocabulary $ map tovec [0..n]
|
|
||||||
tovec i = replicate i 0 ++ [1] ++ replicate (n - i - 1) 0
|
|
||||||
co d =
|
|
||||||
let p = pairs d
|
|
||||||
in map (\(a, [b, c]) -> (f a, V.concat [f b, f c])) p
|
|
||||||
where
|
|
||||||
f w = vector . snd . fromJust $ find ((== w) . fst) vocvec
|
|
||||||
pairs d = concatMap iter [0..length ws]
|
|
||||||
where
|
|
||||||
ws = words $ map toLower d
|
|
||||||
iter i
|
|
||||||
| i > 0 && i < length ws - 1 = [(ws !! i, [ws !! (i - 1), ws !! (i + 1)])]
|
|
||||||
| otherwise = []
|
|
||||||
|
|
||||||
mapTuple :: (a -> b) -> (a, a) -> (b, b)
|
|
||||||
mapTuple f (a, b) = (f a, f b)
|
|
Loading…
Reference in New Issue
Block a user