💣 Machine learning which might blow up in your face 💣
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Give a slightly not terrible error message

+5 -4
+1 -1
examples/main/shakespeare.hs
··· 69 69 loadShakespeare path = do 70 70 contents <- lift $ readFile path 71 71 let annotated = annotateCapitals contents 72 - (m,cs) <- ExceptT . return . note "Couldn't fit data in hotMap" $ hotMap (Proxy :: Proxy 40) annotated 72 + (m,cs) <- ExceptT . return $ hotMap (Proxy :: Proxy 40) annotated 73 73 hot <- ExceptT . return . note "Couldn't generate hot values" $ traverse (`M.lookup` m) annotated 74 74 return (V.fromList hot, m, cs) 75 75
+4 -3
src/Grenade/Utils/OneHot.hs
··· 52 52 53 53 -- | Create a one hot map from any enumerable. 54 54 -- Returns a map, and the ordered list for the reverse transformation 55 - hotMap :: (Ord a, KnownNat n) => Proxy n -> [a] -> Maybe (Map a Int, Vector a) 55 + hotMap :: (Ord a, KnownNat n) => Proxy n -> [a] -> Either String (Map a Int, Vector a) 56 56 hotMap n as = 57 57 let len = fromIntegral $ natVal n 58 58 uniq = [ c | (c:_) <- group $ sort as] 59 59 hotl = length uniq 60 60 in if hotl == len 61 61 then 62 - Just (M.fromList $ zip uniq [0..], V.fromList uniq) 63 - else Nothing 62 + Right (M.fromList $ zip uniq [0..], V.fromList uniq) 63 + else 64 + Left ("Couldn't create hotMap of size " ++ show len ++ " from vector with " ++ show hotl ++ " unique characters") 64 65 65 66 -- | From a map and value, create a 1D Shape 66 67 -- with one index hot (1) with the rest 0.