• 検索結果がありません。

補足資料 プログラミングの基礎勉強会:チュートリアル 首都大学東京 自然言語処理研究室(小町研)

N/A
N/A
Protected

Academic year: 2018

シェア "補足資料 プログラミングの基礎勉強会:チュートリアル 首都大学東京 自然言語処理研究室(小町研)"

Copied!
20
0
0

読み込み中.... (全文を見る)

全文

(1)

7. Neural Networks

Supplement

(2)
(3)
(4)

Forward Propagation

・ ・ ・ t a n h t a n h

" Vector (Vocab)

$ Vector (2)

" Matrix (2, Vocab)

" Vector (2)

(5)

Forward Propagation

t a n h

# Vector

(1)

$

Vector (2)

#

= tanh

$

 

$

+

$

$

Matrix (1, 2)

$

(6)

Hyperbolic Tangent

tanh � =

./0.1/

./2.1/

tanh �

3

=

./2.1/ 40 ./0.1/ 4

./2.1/ 4

=

5 ./2.1/ 4

= 1 −

./2.1/ 405

./2.1/ 4

= 1 −

.4/2#2.14/05 ./2.1/ 4

= 1 −

.4/0#2.14/

./2.1/ 4

= 1 −

./0.1/ 4 ./2.1/ 4

= 1 − tanh

#

(7)

Why gradient is used ?

err =

<

4

0=

 

4

#

・Minimizing

err

function

>?@@

>A

= 0

→ w is ideal

>?@@

>A

> 0

→ w is too big (w -=

λ

>?@@

>A

 

→ w will be decreased)

>?@@

>A

< 0

→ w is too small (w -=

λ

>?@@

>A

 

→ w will be increased)

(8)

Back Propagation

t a n h

#

Vector (1)

err =  

#

− �

 

#

2

#

=

derr

d

#

=

#

− �

#

3

=

derr

d

$

 

$

+

$

      =

derr

d

#

d

#

d

$

 

$

+

$

      =

#

1 −

#

#

Vector

3#

(9)

Back Propagation

t a n h

$ Vector (2)

$

=

derr

d

$

        =

derr

d

$

 

$

+

$

d

$

 

$

+

$

d

$

=

#

3

 

$

$ Matrix (1, 2)

$ Vector (1)

3#

(10)

Back Propagation

t a n h

t a n h

$

3

=

derr

d

"

 

"

+

"

      =

derr

d

$

d

$

d

"

 

"

+

"

      =

$

1 −

$

#

3$

Vector (2)

$

(11)

Back Propagation

・ ・ ・ t a n h t a n h

" Matrix (2, Vocab)

" Vector (2)

"

=

derr

d

"

        =

derr

d

"

 

"

+

"

d

"

 

"

+

"

d

"

=

$

3

 

"

3$

Vector (2)

"

(12)

Update Weights

・ ・ ・ t a n h t a n h

" Matrix (2, Vocab)

" Vector (2)

"

−= λ

>?@@

>

A

I

 = λ

 �

$

3

>

A

I

 

<

I

2

J

I

>

A

I

= λ 

$

3

"

"

−= λ 

>?@@

>

J

I

 = λ 

$

3

>

A

I

 

<

I

2

J

I

>

J

I

= λ 

$

3

3$

Vector (2)

"

(13)

Update Weights

t a n h

3#

Vector (1)

$ Vector (2)

$ Matrix (1, 2)

$ Vector (1)

$

−= λ

>?@@

>

A

K

 = λ

 �

#

3

>

A

K

 

<

K

2

J

K

>

A

K

= λ 

#

3

$

$

−= λ 

>?@@

>

J

K

 = λ 

#

3

>

A

K

 

<

K

2

J

K

>

J

K

(14)
(15)

Saving Models

・Saving dict to File

・Saving network to file

network = list [ net[0], net[1], …, net[i] ]

net[i] = tuple ( w, b )

w, b = array ([[…],[…], …, […]])

How to save to file ?

from each key, value in dict

(16)

Serializer

・Serializer converts object hierarchy into a byte stream

・Saving

・Loading

Network can be saved easily !

import pickle

pickle.dump(file_object, network)

(17)
(18)

Create Feature

CREATE_FEATURES(x):

create list phi (len = len(ids))

split x into words for word in words

#Training

phi[ids[ UNI: +word]] += 1 #Testing

if UNI: +word in ids:

phi[ids[ UNI: +word]] += 1

(19)

Training

create defaultdict ids, array feat_lab

get len(ids)

for each labeled pair x, y in the data

add (create_features(x), y ) to feat_lab initialize net randomly

for I iterations

for each labeled pair φ0 , y in the feat_lab

φ= forward_nn(net, φ0 )

δ'= backward_nn(net, φ, y) update_weights(net, φ, δ', λ)

(20)

Testing

read ids from id_file

read net from weights_file

for each x in the data

φ0 = create_features(x)

φ= forward_nn(net, φ0 )

参照

関連したドキュメント

Mochizuki, Topics Surrounding the Combinatorial Anabelian Geometry of Hyperbolic Curves III: Tripods and Tempered Fundamental Groups, RIMS Preprint 1763 (November 2012).

Kambe, Acoustic signals associated with vor- page texline reconnection in oblique collision of two vortex rings.. Matsuno, Interaction of an algebraic soliton with uneven bottom

Pacific Institute for the Mathematical Sciences(PIMS) カナダ 平成21年3月30日 National Institute for Mathematical Sciences(NIMS) 大韓民国 平成22年6月24日

関谷 直也 東京大学大学院情報学環総合防災情報研究センター准教授 小宮山 庄一 危機管理室⻑. 岩田 直子

るものの、およそ 1:1 の関係が得られた。冬季には TEOM の値はやや小さくなる傾 向にあった。これは SHARP

手話言語研究センター講話会.

本研究科は、本学の基本理念のもとに高度な言語コミュニケーション能力を備え、建学

本研究科は、本学の基本理念のもとに高度な言語コミュニケーション能力を備え、建学