2017-01-15 8 views
0

私は基本的なNLPアルゴリズム、特にユニグラムの特徴を持つ単純なパーセプトロンについて学んでいます。ユニグラムの機能を備えたパーセプトロンは、どのように学習し、次のステップは何ですか?

私はパーセプトロンの基本をthisthisから探しました。

これはthisソースから適応私の簡単なHaskellのパーセプトロン、次のとおりです。

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) '学習' このコードのどの部分?私は各機能に関連する重み(正または負)があることを理解していますが、各反復がどのようにプリオーサーの結果から学習するのか分かりません。

2)NLPアルゴリズムの次の段階は何ですか?私。私は単層パーセプトロンが非常にシンプルであること、他のニューラルネット構造やアルゴリズムはより正確な分類子を探すべきであると理解していますか?

答えて

3

1)このコードのどの部分が「学習する」?

学習は、トレーニングデータ上のパーセプトロンの出力を所望の出力に近づけるように重みを調整することによって達成される。

2)NLPアルゴリズムの次の段階は何ですか?

NLPアルゴリズムについてはわかりませんが、パーセプトロンはニューラルネットワークのビルディングブロックです。あなたが見たいと思う次のものは、フィードフォワードバックプロパゲーションニューラルネットワークです。それらは、接続されたパーセプトロンの層からなる。あなたの線形代数と多変数微積分については、重みを調整することはもう少し複雑ですので、ブラッシュアップしてください!

関連する問題