packages feed

crf-chain2-tiers 0.2.0 → 0.2.1

raw patch · 3 files changed

+27/−16 lines, 3 filesdep ~logfloat

Dependency ranges changed: logfloat

Files

crf-chain2-tiers.cabal view
@@ -1,5 +1,5 @@ name:               crf-chain2-tiers-version:            0.2.0+version:            0.2.1 synopsis:           Second-order, tiered, constrained, linear conditional random fields description:     The library provides implementation of the second-order, linear@@ -31,7 +31,7 @@       , monad-codec             >= 0.2          && < 0.3       , data-lens               >= 2.10.4       && < 2.11       , comonad                 >= 4.0          && < 4.1-      , logfloat+      , logfloat                >= 0.12.1       && < 0.13       , parallel       , sgd                     >= 0.3.2 && < 0.4 
src/Data/CRF/Chain2/Tiers.hs view
@@ -15,6 +15,7 @@  -- * Tagging , tag+, marginals  -- * Modules , module Data.CRF.Chain2.Tiers.Dataset.External@@ -184,3 +185,11 @@     onWords xs =         [ unJust codec word x         | (word, x) <- zip sent xs ]+++-- | Tag labels with marginal probabilities.+marginals :: (Ord a, Ord b) => CRF a b -> Sent a b -> [[Double]]+marginals CRF{..}+    = map (map LogFloat.fromLogFloat)+    . I.marginals model+    . encodeSent codec
src/Data/CRF/Chain2/Tiers/Inference.hs view
@@ -2,7 +2,7 @@  module Data.CRF.Chain2.Tiers.Inference ( tag-, probs+-- , probs , marginals , expectedFeatures , accuracy@@ -116,19 +116,21 @@     let ixs = tagIxs crf sent     in  [lbAt x i | (x, i) <- zip (V.toList sent) ixs] --- | Tag potential labels with corresponding probabilities.-probs :: Model -> Xs -> [[L.LogFloat]]-probs crf sent =-    let alpha = forward maximum crf sent-        beta = backward maximum crf sent-        normalize xs =-            let d = - sum xs-            in map (*d) xs-        m1 k x = maximum-            [ alpha k x y * beta (k + 1) x y-            | y <- lbIxs sent (k - 1) ]-    in  [ normalize [m1 i k | k <- lbIxs sent i]-        | i <- [0 .. V.length sent - 1] ]+-- -- | Tag labels with corresponding probabilities.+-- TODO: doesn't work, crashes with "Data.Number.LogFloat.negate:+-- argument out of range" for some reason.+-- probs :: Model -> Xs -> [[L.LogFloat]]+-- probs crf sent =+--     let alpha = forward maximum crf sent+--         beta = backward maximum crf sent+--         normalize xs =+--             let d = - sum xs+--             in map (*d) xs+--         m1 k x = maximum+--             [ alpha k x y * beta (k + 1) x y+--             | y <- lbIxs sent (k - 1) ]+--     in  [ normalize [m1 i k | k <- lbIxs sent i]+--         | i <- [0 .. V.length sent - 1] ]  -- | Tag potential labels with marginal probabilities. marginals :: Model -> Xs -> [[L.LogFloat]]