Haskell 具有unigram功能的感知器,它是如何学习的,下一步是什么?
我正在学习基本的NLP算法,特别是具有单图特征的简单感知器 我已经从和浏览了感知机的基本原理 这是我的简单Haskell感知器,改编自: 我的问题是: 1) 此代码的哪一部分“学习”?我知道每个特征都有一个相关的权重(正或负),但是我不知道每个迭代如何从先验结果中学习 2) NLP算法的“下一阶段”是什么?也就是说,我知道单层感知器非常简单,为了获得更精确的分类器,我应该考虑哪些其他神经网络结构和/或不同的算法 1) 此代码的哪一部分“学习” 学习是通过调整权重来实现的,以使感知器在训练数据上的输出更接近期望的输出 2) NLP算法的“下一阶段”是什么 我对NLP算法一无所知,但感知器是神经网络的组成部分。我想接下来你要看的是前馈反向传播神经网络。它们由多层相互连接的感知机组成。复习你的线性代数和多变量微积分,因为调整权重有点复杂 1) 此代码的哪一部分“学习” 学习是通过调整权重来实现的,以使感知器在训练数据上的输出更接近期望的输出 2) NLP算法的“下一阶段”是什么 我对NLP算法一无所知,但感知器是神经网络的组成部分。我想接下来你要看的是前馈反向传播神经网络。它们由多层相互连接的感知机组成。复习你的线性代数和多变量微积分,因为调整权重有点复杂Haskell 具有unigram功能的感知器,它是如何学习的,下一步是什么?,haskell,nlp,neural-network,perceptron,Haskell,Nlp,Neural Network,Perceptron,我正在学习基本的NLP算法,特别是具有单图特征的简单感知器 我已经从和浏览了感知机的基本原理 这是我的简单Haskell感知器,改编自: 我的问题是: 1) 此代码的哪一部分“学习”?我知道每个特征都有一个相关的权重(正或负),但是我不知道每个迭代如何从先验结果中学习 2) NLP算法的“下一阶段”是什么?也就是说,我知道单层感知器非常简单,为了获得更精确的分类器,我应该考虑哪些其他神经网络结构和/或不同的算法 1) 此代码的哪一部分“学习” 学习是通过调整权重来实现的,以使感知器在训练数据上的
type Inputs = [Float]
type Weights = [Float]
type Threshold = Float
type LearnRate = Float
type Expected = Float
type Actual = Float
neuronOutput :: (Num a, Ord a) => Inputs -> Weights -> Threshold -> a
--neuronOutput :: (Num a, Ord a) => [a] -> [a] -> a -> a --Parametic polymorphic
neuronOutput inputs weights thresh
| total - thresh >= 0 = 1
| otherwise = 0
where
total = foldl (+) 0 $ zipWith (*) inputs weights
adjustWeights :: Inputs -> Weights -> Expected -> Actual -> LearnRate -> Weights --Adjust the weights
--adjustWeights :: (Num a) => [a] -> [a] -> a -> a -> a -> [a] --Parametic polymorphic
adjustWeights inputs orgiWeights expected actual learn = map delta $ zip inputs orgiWeights
where
delta (i, w) = w + (learn * i * e)
e = expected - actual
singleIteration :: Inputs -> Weights -> Expected -> LearnRate -> Threshold -> Weights --Return adjusted weights based on neuronOutput
--singleIteration :: (Num a, Ord a) => [a] -> [a] -> a -> a -> a -> [a] --Parametic polymorphic
singleIteration inputs weights expectd learn thresh = adjustWeights inputs weights expectd output learn
where
output = neuronOutput inputs weights thresh
implementIterations :: [(Inputs, Expected)] -> Weights -> LearnRate -> Threshold -> (Inputs, Expected) --Applies singleIteration to each input set
implementIterations allInputs weights learnR thresH = (newWeights, delta)
where
newWeights = foldl iterate weights allInputs
iterate w (i, e) = singleIteration i w e learnR thresH
delta = (foldl (+) 0 $ map abs $ zipWith (-) newWeights weights) / (fromIntegral $ length weights) --Func composition here to make better?
runLearning :: [(Inputs, Expected)] -> LearnRate -> Threshold -> Weights -> Int -> (Inputs, Int)
runLearning allInputs learnR thresH weights epochNb
| delta == 0 = (newWeights, epochNb)
| otherwise = runLearning allInputs learnR thresH newWeights (epochNb + 1) --Recusive changing weights each time
where
(newWeights, delta) = implementIterations allInputs weights learnR thresH
main = do
let inputs = [([1, 1, 1], 1), ([0, 0, 0], -1)]
let weights = [1, 1, 1, 0, 0, -4]
print $ runLearning inputs 0.1 0.2 weights 1