具有 unigram 特征的感知器,它是如何学习的,下一步是什么?

Perceptron with unigram features, how does it learn and what are the next steps?

我正在学习基本的 NLP 算法,特别是具有 unigram 特征的简单感知器。

我查看了 this and this 中的感知器基础知识。

这是我的简单 Haskell 感知器,改编自 this 来源:

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

我的问题是:

1) 此代码的哪一部分 'learns'?我知道每个特征都有一个相关的权重(正或负),但是我看不到每次迭代如何从先验结果中学习?

2) NLP算法的'next stage'是什么? IE。我知道单层感知器非常简单,我应该寻找哪些其他神经网络结构 and/or 不同的算法以获得更准确的分类器?

1) What part of this code 'learns'?

学习是通过调整权重使感知器在训练数据上的输出变得更接近期望的输出来实现的。

2) What's the 'next stage' of NLP algorithms?

我对 NLP 算法一无所知,但感知器是神经网络的基石。我想您接下来要看的是 feed-forward 反向传播神经网络。它们由连接的感知器层组成。复习一下线性代数和 multi-variable 微积分,因为调整权重有点复杂!