• 검색 결과가 없습니다.

Overview Today:

N/A
N/A
Protected

Academic year: 2021

Share "Overview Today:"

Copied!
69
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

Overview Today:

• From one-layer to multi layer neural networks!

Backprop (last bit of heavy math)

• Different descriptions and viewpoints of backprop

• Project Tips

(2)

Announcement:

• Hint for PSet1: Understand math and dimensionality, then check them with breakpoints or print statements:

(3)

Why go through all of these derivatives?

• Actual understanding of math behind deep learning

• Backprop can be an imperfect abstraction, e.g.

• During optimization issues (e.g. vanishing gradients)

• Enables you to debug models, think of and implement completely new models

(4)

Explanation #1 for backprop

(5)

Remember: Window-based Neural Net

Computing a window’s score with a 3-layer neural net: s = score(museums in Paris are amazing )

Xwindow = [ xmuseums xin xParis xare xamazing]

(6)

Putting all gradients together:

• Remember: Full objective function for each window was:

• For example: (sub)gradient for U:

(7)

Two layer neural nets and full backprop

• Let’s look at a 2 layer neural network

• Same window definition for x

• Same scoring function

• 2 hidden layers (carefully define superscripts now!)

W(1) W(2)

a(2) a(3)

x U

s

(8)

Two layer neural nets and full backprop

• Fully written out as one function:

• Same derivation as before for W(2) (now sitting on a(2))

W(1) W(2)

S

a(2) a(3)

(9)

Two layer neural nets and full backprop

• Same derivation as before for top W(2) :

• In matrix notation:

where and

°

is the element-wise product also called Hadamard product (⊗, ⨀)

• Last missing piece for understanding general backprop:

(10)

Two layer neural nets and full backprop

• Last missing piece:

• What’s the bottom layer’s error message δ(2)?

• Similar derivation to single layer model

• Main difference, we already have and need to apply the chain rule again on

(11)

Two layer neural nets and full backprop

• Chain rule for:

Get intuition by deriving as if it was a scalar

• Intuitively, we have to sum over all the nodes coming into layer

• Putting it all together:

The second derivative in eq. 28 for output units is simply

@a(ni l)

@Wij(nl 1) = @

@Wij(nl 1)zi(nl) = @

@Wij(nl 1)

Wi(n· l 1)a(nl 1)

= a(nj l 1). (46)

We adopt standard notation and introduce the error related to an output unit:

@En

@Wij(nl 1) = (yi ti)a(nj l 1) = i(nl)a(nj l 1). (47) So far, we only computed errors for output units, now we will derive ’s for normal hidden units and show how these errors are backpropagated to compute weight derivatives of lower levels. We will start with second to top layer weights from which a generalization to arbitrarily deep layers will become obvious.

Similar to eq. 28, we start with the error derivative:

@E

@Wij(nl 2) = X

n

@En

@a(nl)

| {z }

(nl)

@a(nl)

@Wij(nl 2) + Wji(nl 2). (48)

Now,

( (nl))T @a(nl)

@Wij(nl 2) = ( (nl))T @z(nl)

@Wij(nl 2) (49)

= ( (nl))T @

@Wij(nl 2)W(nl 1)a(nl 1) (50)

= ( (nl))T @

@Wij(nl 2)W·i(nl 1)a(ni l 1) (51)

= ( (nl))TW·i(nl 1) @

@Wij(nl 2)a(ni l 1) (52)

= ( (nl))TW·i(nl 1) @

@Wij(nl 2)f (zi(nl 1)) (53)

= ( (nl))TW·i(nl 1) @

@Wij(nl 2)f (Wi(n· l 2)a(nl 2)) (54)

= ( (nl))TW·i(nl 1)f0(zi(nl 1))a(nj l 2) (55)

=

( (nl))TW·i(nl 1)

f0(zi(nl 1))a(nj l 2) (56)

= 0

@

sXl+1

j=1

Wji(nl 1) j(nl)) 1

A f0(zi(nl 1))

| {z }

a(nj l 2) (57)

= i(nl 1)a(nj l 2) (58)

where we used in the first line that the top layer is linear. This is a very detailed account of essentially just the chain rule.

So, we can write the errors of all layers l (except the top layer) (in vector format, using the Hadamard product ):

(l) =

(W(l))T (l+1)

f0(z(l)), (59)

7

(12)

Two layer neural nets and full backprop

• Final derivative:

• In general for any matrix W(l) at internal layer l and any error with regularization ER all backprop in standard multilayer

neural networks boils down to 2 equations:

• Top and bottom layers have simpler δ

The second derivative in eq. 28 for output units is simply

@a(ni l)

@Wij(nl 1) = @

@Wij(nl 1) zi(nl) = @

@Wij(nl 1)

Wi(n· l 1)a(nl 1)

= a(nj l 1). (46) We adopt standard notation and introduce the error related to an output unit:

@En

@Wij(nl 1) = (yi ti)a(nj l 1) = i(nl)a(nj l 1). (47) So far, we only computed errors for output units, now we will derive ’s for normal hidden units and show how these errors are backpropagated to compute weight derivatives of lower levels. We will start with second to top layer weights from which a generalization to arbitrarily deep layers will become obvious.

Similar to eq. 28, we start with the error derivative:

@E

@Wij(nl 2) = X

n

@En

@a(nl)

| {z }

(nl)

@a(nl)

@Wij(nl 2) + Wji(nl 2). (48)

Now,

( (nl))T @a(nl)

@Wij(nl 2) = ( (nl))T @z(nl)

@Wij(nl 2) (49)

= ( (nl))T @

@Wij(nl 2)W(nl 1)a(nl 1) (50)

= ( (nl))T @

@Wij(nl 2)W·i(nl 1)a(ni l 1) (51)

= ( (nl))TW·i(nl 1) @

@Wij(nl 2)a(ni l 1) (52)

= ( (nl))TW·i(nl 1) @

@Wij(nl 2)f (zi(nl 1)) (53)

= ( (nl))TW·i(nl 1) @

@Wij(nl 2)f (Wi(n· l 2)a(nl 2)) (54)

= ( (nl))TW·i(nl 1)f0(zi(nl 1))a(nj l 2) (55)

=

( (nl))TW·i(nl 1)

f0(zi(nl 1))a(nj l 2) (56)

=

0

@

sl+1

X

j=1

Wji(nl 1) j(nl)) 1

A f0(zi(nl 1))

| {z }

a(nj l 2) (57)

= i(nl 1)a(nj l 2) (58)

where we used in the first line that the top layer is linear. This is a very detailed account of essentially just the chain rule.

So, we can write the errors of all layers l (except the top layer) (in vector format, using the Hadamard product ):

(l) =

(W(l))T (l+1)

f0(z(l)), (59)

7

where the sigmoid derivative from eq. 14 gives f0(z(l)) = (1 a(l))a(l). Using that definition, we get the hidden layer backprop derivatives:

@

@Wij(l)ER = a(l)j i(l+1) + Wij(l) (60)

(61) Which in one simplified vector notation becomes:

@

@W(l)ER = (l+1)(a(l))T + W(l). (62)

In summary, the backprop procedure consists of four steps:

1. Apply an input xn and forward propagate it through the network to get the hidden and output activations using eq. 18.

2. Evaluate (nl) for output units using eq. 42.

3. Backpropagate the ’s to obtain a (l) for each hidden layer in the network using eq. 59.

4. Evaluate the required derivatives with eq. 62 and update all the weights using an optimization procedure such as conjugate gradient or L-BFGS. CG seems to be faster and work better when using mini-batches of training data to estimate the derivatives.

If you have any further questions or found errors, please send an email to [email protected]

5 Recursive Neural Networks

Same as backprop in previous section but splitting error derivatives and noting that the derivatives of the same W at each node can all be added up. Lastly, the delta’s from the parent node and possible delta’s from a softmax classifier at each node are just added.

References

[Ben07] Yoshua Bengio. Learning deep architectures for ai. Technical report, Dept. IRO, Universite de Montreal, 2007.

8

(13)

Taking a step back

Explanation #2 for backprop:

“Circuits”

These examples are from CS231n:

http://cs231n.github.io/optimization-2/

(14)

Functions as circuits

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 10 13 Jan 2016

e.g. x = -2, y = 5, z = -4

(15)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 11 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

(16)

Recursively walking back through circuit

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 12 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

(17)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 13 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

(18)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 14 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

(19)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 15 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

(20)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 16 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

(21)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 17 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

(22)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 18 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

(23)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 19 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

Chain rule:

(24)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 20 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

(25)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 21 13 Jan 2016

e.g. x = -2, y = 5, z = -4

Want:

Chain rule:

(26)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 22 13 Jan 2016

f

activations

(27)

Recursively apply chain rule through each node

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 26 13 Jan 2016

f

activations

gradients

“local gradient”

(28)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 30 13 Jan 2016

Another example:

(29)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 31 13 Jan 2016

Another example:

(30)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 33 13 Jan 2016

Another example:

(31)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 34 13 Jan 2016

Another example:

(32)

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 35 13 Jan 2016

Another example:

(33)

Jumping to the end…

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 41 13 Jan 2016

Another example:

[local gradient] x [its gradient]

x0: [2] x [0.2] = 0.4 w0: [-1] x [0.2] = -0.2

0.4

(34)

Combine nodes in the circuit when convenient

Lecture 4 - 13 Jan 2016

Fei-Fei Li & Andrej Karpathy & Justin Johnson

Fei-Fei Li & Andrej Karpathy & Justin Johnson Lecture 4 - 43 13 Jan 2016

sigmoid function

sigmoid gate

(0.73) * (1 - 0.73) = 0.2

We’ll combine a lot in #4 : )

(35)

Explanation #3 for backprop

The high-level flowgraph

(36)

Backpropagation (Another explanation)

• Compute gradient of example-wise loss wrt parameters

• Simply applying the derivative chain rule wisely

If computing the loss(example, parameters) is O(n)

computation, then so is computing the gradient

(37)

Simple Chain Rule

(38)

Multiple Paths Chain Rule

(39)

Multiple Paths Chain Rule - General

(40)

Chain Rule in Flow Graph

Flow graph: any directed acyclic graph node = computation result

arc = computation dependency

= successors of

(41)

Back-Prop in Multi-Layer Net

h = sigmoid(Vx)

(42)

Back-Prop in General Flow Graph

= successors of

1. Fprop: visit nodes in topo-sort order

- Compute value of node given predecessors 2. Bprop:

- initialize output gradient = 1 - visit nodes in reverse order:

Compute gradient wrt each node using gradient wrt successors

Single scalar output

(43)

Automatic Differentiation

• The gradient computation can be automatically inferred from the symbolic expression of the fprop.

• Each node type needs to know how to compute its output and how to compute the gradient wrt its inputs given the

gradient wrt its output.

• Easy and fast prototyping

(44)

Explanation #4 for backprop

The delta error signals in real

neural nets

(45)

Actual error signals for 2 layer neural net

W(1) W(2)

a(2) a(3)

(46)

Visualization of intuition

• Let’s say we want with previous layer and f = σ

Our first example:

Backpropagation using error vectors

CS224D: Deep Learning for NLP 31

σ 1

z(1) 1 a(1)

W(1) z(2) a(2) W(2) z(3) s

δ(3) Gradient w.r.t W(2) = δ(3)a(2)T

(47)

Visualization of intuition Our first example:

Backpropagation using error vectors

CS224D: Deep Learning for NLP 32

σ 1

z(1) 1 a(1)

W(1) z(2) a(2) W(2) z(3) s

δ(3) W(2)T δ(3)

--Reusing the δ(3) for downstream updates.

--Moving error vector across affine transformation simply requires multiplication with the transpose of forward matrix

--Notice that the dimensions will line up perfectly too!

(48)

Visualization of intuition Our first example:

Backpropagation using error vectors

CS224D: Deep Learning for NLP 33

σ 1

z(1) 1 a(1)

W(1) z(2) a(2) W(2) z(3) s

W(2)T δ(3) σ’(z(2))!W(2)T δ(3)

= δ(2)

--Moving error vector across point-wise non-linearity requires point-wise multiplication with local gradient of the non-linearity

(49)

Visualization of intuition Our first example:

Backpropagation using error vectors

CS224D: Deep Learning for NLP 34

σ 1

z(1) 1 a(1)

W(1) z(2) a(2) W(2) z(3) s

δ(2)

Gradient w.r.t W(1) = δ(2)a(1)T W(1)T δ(2)

(50)

You survived Backprop!

• Congrats!

• You now understand the inner workings of most deep learning models out there

• This was the hardest part of the class

• Everything else from now on is mostly just more

matrix multiplications and backprop :)

(51)

Bag of Tricks for Efficient Text Classification

Armand Joulin, Edouard Grave, Piotr Bojanowski, Tomas Mikolov Facebook AI Research

(52)

Text classification

(53)

Bag of Words (or n-grams)

Natural language

processing is fun. Natural

language processing

is

fun Average

(54)

Simple linear model

x1 x2 xn-1 xn

hidden

Word vectors Text vector

...

output Softmax

(55)

Learning

# documents

normalized bag of features of n-th doc label of n-

th doc

softmax weight matrices

(56)

Hierarchical softmax

Machine learning

AI

NLP

Computer Science

Javascript GUI

Angular

Probability of a node is always lower than one

of its parent k classes

...

(57)

Hierarchical softmax

Machine learning

AI

NLP

Computer Science

Javascript GUI

Angular

Probability of a node is always lower than one

of its parent k classes

...

O(hlog(k)) vs O(kh) training

time!

(Text representation dimension h)

(58)

Results

Fast!

As good as NN!

(59)

Summary

fastText is often on par with deep learning classifiers fastText takes seconds, instead of days

Can learn vector representations of words in different languages (with performance better than word2vec!)

Thanks!

(60)

Class Project

• Important (30%) and lasting result of the class

• Final Project Poster Presentation: 2%

• Choice of doing Assignment 4 or a Final project

• Mandatory approved mentors à You need to reach out to potential mentors

• Start early and clearly define your task and dataset

• See https://web.stanford.edu/class/cs224n/project.html

(61)

Project types

1. Apply existing neural network model to a new task 2. Implement a complex neural architecture

3. Come up with a new neural network model

4. Theory of deep learning, e.g. optimization

(62)

Class Project: Apply Existing NNets to Tasks

1. Define Task:

Example: Summarization

2. Define Dataset

1. Search for academic datasets

They already have baselines

E.g.: Document Understanding Conference (DUC)

2. Define your own (harder, need more new baselines)

If you’re a graduate student: connect to your research

Summarization, Wikipedia: Intro paragraph and rest of large article

Be creative: Twitter, Blogs, News

(63)

Class Project: Apply Existing NNets to Tasks

3. Define your metric

• Search online for well established metrics on this task

• Summarization: Rouge (Recall-Oriented Understudy for

Gisting Evaluation) which defines n-gram overlap to human summaries

4. Split your dataset!

• Train/Dev/Test

• Academic dataset often come pre-split

• Don’t look at the test split until ~1 week before deadline!

(or at most once a week)

(64)

Class Project: Apply Existing NNets to Tasks

5. Establish a baseline

• Implement the simplest model (often logistic regression on unigrams and bigrams) first

• Compute metrics on train AND dev

• Analyze errors

• If metrics are amazing and no errors:

done, problem was too easy, restart :)

6. Implement existing neural net model

• Compute metric on train and dev

• Analyze output and errors

• Minimum bar for this class

(65)

Class Project: Apply Existing NNets to Tasks

7. Always be close to your data!

• Visualize the dataset

• Collect summary statistics

• Look at errors

• Analyze how different hyperparameters affect performance 8. Try out different model variants

• Soon you will have more options

Word vector averaging model (neural bag of words)

Fixed window neural model

Recurrent neural network

Recursive neural network

Convolutional neural network

(66)

Class Project: A New Model -- Advanced Option

• Do all other steps first (Start early!)

• Gain intuition of why existing models are flawed

• Talk to researcher/mentor, come to project office hours a lot

• Implement new models and iterate quickly over ideas

• Set up efficient experimental framework

• Build simpler new models first

• Example Summarization:

• Average word vectors per paragraph, then greedy search

• Implement language model (introduced later)

• Stretch goal: Generate summary with seq2seq!

(67)

Project Ideas

• Summarization

• NER, like PSet 2 but with larger data

Natural Language Processing (almost) from Scratch, Ronan Collobert, Jason Weston, Leon Bottou, Michael Karlen, Koray Kavukcuoglu, Pavel Kuksa, http://arxiv.org/abs/1103.0398

• Simple question answering, A Neural Network for Factoid Question Answering over Paragraphs, Mohit Iyyer, Jordan Boyd-Graber, Leonardo Claudino, Richard Socher and Hal Daumé III (EMNLP 2014)

• Image to text mapping or generation,

Grounded Compositional Semantics for Finding and Describing Images with Sentences, Richard Socher, Andrej Karpathy, Quoc V. Le, Christopher D. Manning, Andrew Y. Ng. (TACL 2014)

or

Deep Visual-Semantic Alignments for Generating Image Descriptions, Andrej Karpathy, Li Fei-Fei

• Entity level sentiment

• Use DL to solve an NLP challenge on kaggle,

Develop a scoring algorithm for student-written short-answer responses, https://www.kaggle.com/c/asap-sas

(68)

Another example project: Sentiment

Sentiment on movie reviews: http://nlp.stanford.edu/sentiment/

Lots of deep learning baselines and methods have been tried

(69)

Next up

• Some fun and fundamental linguistics with syntactic parsing

• TensorFlow lecture (for Ass.2 ) – also useful for projects and life : )

참조

관련 문서

The blue whale opens its mouth, drinks seawater, and closes

Almost all Indian movies contain five to six different singing and

What is the number of square units in the area of a triangle whose sides measure 5, 5 and

We also define period of a Fibonacci sequence modulo an integer, m and derive certain interesting properties related to them.. Afterwards, we derive some new properties of a

The most common frozen section specimens that we receive include trucut breast biopsies for diagnosis of carcinoma (in the past we received lumpectomies but now these

These flags and control bits are used when Link Units, such as PC Link Units, SYSMAC LINK Units, Remote I/O Units, SYSMAC NET Link Units, or Host Link Units, are mounted to the

As you see in our survey report ⑦ stating ⑧ eight units of computers ⑨ are badly damaged ⑩ on account of the inferior packing, they are quite unsaleable. ⑪

Because we believe designers are more valuable than ever to businesses today, we commissioned the 2019 Product Design Hiring Report to help those responsible for