mirror of
https://github.com/facebook/duckling.git
synced 2024-11-28 16:54:59 +03:00
3f8e52e70a
fbshipit-source-id: 301a10f448e9623aa1c953544f42de562909e192
59 lines
1.2 KiB
Haskell
59 lines
1.2 KiB
Haskell
-- Copyright (c) 2016-present, Facebook, Inc.
|
|
-- All rights reserved.
|
|
--
|
|
-- This source code is licensed under the BSD-style license found in the
|
|
-- LICENSE file in the root directory of this source tree. An additional grant
|
|
-- of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
|
{-# LANGUAGE NoRebindableSyntax #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Duckling.Ranking.Types
|
|
( Feature
|
|
, BagOfFeatures
|
|
, Class
|
|
, Datum
|
|
, Dataset
|
|
|
|
, Classifier(..)
|
|
, Classifiers
|
|
, ClassData(..)
|
|
|
|
, infinity
|
|
) where
|
|
import Data.HashMap.Strict (HashMap)
|
|
import Data.Text (Text)
|
|
import Prelude
|
|
|
|
-- -----------------------------------------------------------------
|
|
-- Aliases
|
|
|
|
type Feature = Text
|
|
type BagOfFeatures = HashMap Feature Int
|
|
type Class = Bool
|
|
type Datum = (BagOfFeatures, Class)
|
|
type Dataset = HashMap Text [Datum]
|
|
|
|
-- -----------------------------------------------------------------
|
|
-- Classification
|
|
|
|
data Classifier = Classifier
|
|
{ okData :: ClassData
|
|
, koData :: ClassData
|
|
}
|
|
deriving (Eq, Show)
|
|
|
|
type Classifiers = HashMap Text Classifier
|
|
|
|
data ClassData = ClassData
|
|
{ prior :: Double
|
|
, unseen :: Double
|
|
, likelihoods :: HashMap Feature Double
|
|
, n :: Int
|
|
}
|
|
deriving (Eq, Show)
|
|
|
|
infinity :: Double
|
|
infinity = 1 / 0
|