Weighted Automata Extraction from Recurrent Neural...

83
Weighted Automata Extraction from Recurrent Neural Networks via Regression 回帰による再帰型ニューラルネットワークからの 重み付きオートマトンの抽出 1 Takamasa Okudono Masaki Waga Taro Sekiyama Ichiro Hasuo {tokudono,mwaga,hasuo,sekiyama}@nii.ac.jp NII & SOKENDAI To appear at AAAI 2020 ( ) Preprint: https://arxiv.org/abs/1904.02931

Transcript of Weighted Automata Extraction from Recurrent Neural...

Page 1: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Weighted Automata Extraction from Recurrent Neural Networks via Regression

回帰による再帰型ニューラルネットワークからの重み付きオートマトンの抽出

1

Takamasa Okudono Masaki WagaTaro Sekiyama Ichiro Hasuo

{tokudono,mwaga,hasuo,sekiyama}@nii.ac.jpNII & SOKENDAI

To appear at AAAI 2020

( )

Preprint: https://arxiv.org/abs/1904.02931

Page 2: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Recurrent neural networks (RNNs)

Neural networks expandable according toinput sequences with variable lengths😄 Great success in learning sequential data,

especially thanks to LSTMs/GRUs!

2

Page 3: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Recurrent neural networks (RNNs)

Neural networks expandable according toinput sequences with variable lengths😄 Great success in learning sequential data,

especially thanks to LSTMs/GRUs!🤨 But there are drawbacks such that: ■Hard to interpret what they learnt ■Hard to verify their behavior ■Computationally costly (even for inference)

3

Page 4: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

4

Page 5: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

4

Apparent state transition

Page 6: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

4

Apparent state transition

Many analysis algorithms

Page 7: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

4

Apparent state transition

Many analysis algorithms

Less operations

Page 8: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

4

Apparent state transition

Many analysis algorithms

Less operations

} ExtractingFAsfrom

discrete-input RNNs

Page 9: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

4

Apparent state transition

Many analysis algorithms

Less operations

[Omlin+’96] } ExtractingFAsfrom

discrete-input RNNs

Page 10: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

4

Apparent state transition

Many analysis algorithms

Less operations

[Omlin+’96]

[Luis+’03] } ExtractingFAsfrom

discrete-input RNNs

Page 11: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

4

Apparent state transition

Many analysis algorithms

Less operations

[Omlin+’96]

[Luis+’03]

[Wang+’17] } ExtractingFAsfrom

discrete-input RNNs

Page 12: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

4

Apparent state transition

Many analysis algorithms

Less operations

[Omlin+’96]

[Luis+’03]

[Wang+’17]

[Weiss+’18]} ExtractingFAsfrom

discrete-input RNNs

Page 13: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Surrogate of RNNsFinite automata (FAs) ■More interpretable■More verifiable■More efficient

5

Apparent state transition

Many analysis algorithms

Less operations

[Omlin+’96]

[Luis+’03]

[Wang+’17]

[Weiss+’18]} Extractingdeterministic FAs

from discrete-input, dBoolean-output RNNs

Page 14: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Our workExtracting weighted FAs (WFAs)from discrete-input, real-output RNNs ■Based on a weighted extension of [Angluin’87, Balle+’15]

□Technical contribution:Answering equivalence queries b/w WFAs and RNNs by regression on their state spaces

■Experiments to answer:□How close the extracted WFAs are to the given RNNs□How applicable our method is to expressive RNNs□How efficient the extracted WFAs are

L*

6

Page 15: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Outline1. Introduction2. Preliminaries

A. Abstract definitions of RNNs and WFAsB. Weighted extension of Angluin’s

3. Our work: extraction of WFAs from RNNs4. Experiments

L*

7

Page 16: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

RNNs

8

Input

Output

Page 17: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

RNNs

8

Input

Output

Given inputx1x2⋯xn ∈ Σ*

x1 x2

xn

y ∈ ℝ

Page 18: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

RNNs

8

Input

Output

Given inputx1x2⋯xn ∈ Σ*

■Can be viewed as state-passing machines□ States s1, s2, ⋯, sn ∈ ℝd

s1 s2 sn

x1 x2

xn

y ∈ ℝ

Page 19: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

RNNs■RNN comprises□ : initial state

□ : final function

□ : state transition function

RαR ∈ ℝd

βR ∈ ℝd → ℝgR ∈ ℝd × Σ → ℝd

9

x1 x2

xn

y ∈ ℝ

s1 s2 sn…αR

βRgR

Page 20: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

RNNs■RNN comprises□ : initial state

□ : final function

□ : state transition function

■Derived functions□

RαR ∈ ℝd

βR ∈ ℝd → ℝgR ∈ ℝd × Σ → ℝd

δR(x1x2⋯xn) = gR(⋯, gR(gR(αR, x1), x2), ⋯, xn)= sn ∈ ℝd

fR(x1x2⋯xn) = βR(δR(x1x2⋯xn)) = y ∈ ℝ10

x1 x2

xn

y ∈ ℝ

s1 s2 sn…αR

βRgR

Page 21: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

WFAs■Finite automata s.t.□Each state has an initial and final weight□Each transition is weighted

11

■State label “q/m/n” means initial and final weights at q are m and n, respectively

■Transition label “a,n” means transition by letter "a" is weighted by n

Page 22: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

WFAs■WFA with states comprises□ : initial vector (a collection of initial weights)

□ : final vector (a collection of final weights)

□ : transition function□ is the weight of the transition by from state to

■Derived functions

A nαA ∈ ℝn

βA ∈ ℝn

gA ∈ Σ → ℝn×n

gA(a)[i, j] a i j

δA(x1x2⋯xn) = αAgA(x1)gA(x2)⋯gA(xn) ∈ ℝn

fA(x1x2⋯xn) = δA(x1x2⋯xn) ⋅ βA ∈ ℝ

12

Page 23: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Outline1. Introduction2. Preliminaries

1. Abstract definitions of RNNs and WFAs2. Weighted extension of Angluin’s

3. Our method: extraction of WFAs from RNNs4. Experiments

L*

13

Page 24: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

algorithm for WFAs [Balle+’15]L*(m, e)

Learning a WFA from a black-box by queries■Input: answerers to two kinds of queries

□ for membership queries “What value does output for input ?”

□ for equivalence queries “Is a WFA being constructed equivalent to ?”

• Returns counterexample if not

■Output□A (minimum) WFA

B

m ∈ Σ* → ℝB w ∈ Σ*

e ∈ {WFAs} → {Eq} ⊎ Σ*B

w ∈ Σ*

14

Page 25: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Property of L*(m, e)

15

For a WFA , s.t.

where

AL*( fA, eA) = A0 fA = fA0

eA(A′�) = {Eq (if fA = fA′ �)w (if fA(w) ≠ fA′�(w))

Page 26: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Outline1. Introduction2. Preliminaries3. Our work: extraction of WFAs from RNNs 4. Experiments

16

Page 27: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Our work■Using to obtain a WFA close to an RNNL*

17

For a WFA , s.t.

where

AL*( fA, eA) = A0 fA = fA0

eA(A′�) = {Eq (if fA = fA′ �)w (if fA(w) ≠ fA′�(w))

Property of L*

Page 28: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Our work■Using to obtain a WFA close to an RNN

L*

18

For an RNN , s.t.

where

RL*( fR, eR) = A0 fR ≃ fA0

eR(A′�) = {Eq (if fR ≃ fA′�)w (if fR(w) ≄ fA′�(w))

Our expectation

Page 29: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Our work■Using to obtain a WFA close to an RNN

■Challenge: how do we implement that answers if and returns an evidence if not

L*

eR(A)fR ≃ fA

19

For an RNN , s.t.

where

RL*( fR, eR) = A0 fR ≃ fA0

eR(A′�) = {Eq (if fR ≃ fA′�)w (if fR(w) ≄ fA′�(w))

Our expectation

Page 30: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Strategy for eR(A)Goal: implement

1. Trying to find counterexample s.t.

2(a). Returning if found2(b). Returning “ ” if no counterexample is

found even by sufficient search

eR(A) = {Eq (if fR ≃ fA)w (if fR(w) ≄ fA(w))

wfR(w) ≠ fA(w)

wEq

20

Page 31: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Strategy for eR(A)Goal: implement

1. Trying to find counterexample s.t.

2(a). Returning if found2(b). Returning “ ” if no counterexample is

found even by sufficient search

eR(A) = {Eq (if fR ≃ fA)w (if fR(w) ≄ fA(w))

wfR(w) ≠ fA(w)

wEq

20

Page 32: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Tree traversal for finding counterexamples

■Finding a node s.t. w fR(w) ≠ fA(w)

21

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Σ = {a, b, c}

Page 33: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Tree traversal for finding counterexamples

■Finding a node s.t. ■Question: What order of traversal can find

a counterexample effectively?

w fR(w) ≠ fA(w)

22

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Σ = {a, b, c}

Page 34: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Tree traversal for finding counterexamples

■Finding a node s.t. ■Question: What order of traversal can find

a counterexample effectively?

w fR(w) ≠ fA(w)

23

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Σ = {a, b, c}

Our approach: guiding the traversal bya relationship between WFA and RNN A R

Page 35: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Relationship b/t RNN and WFA R A

24

Working hypothesis

fR ≃ fA

Page 36: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Relationship b/t RNN and WFA R A

24

Working hypothesis

= βR ∘ δR

fR ≃ fA

Page 37: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Relationship b/t RNN and WFA R A

24

Working hypothesis

= βR ∘ δR = w ↦ δA(w) ⋅ βA

fR ≃ fA

Page 38: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Relationship b/t RNN and WFA R A

24

Working hypothesis

= βR ∘ δR = w ↦ δA(w) ⋅ βA

fR ≃ fA ⇔ Internal states obtained by and are relatedδR δA

Page 39: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Relationship b/t RNN and WFA R A

25

Working hypothesis

fR ≃ fA ⇔ Σ*

ℝd

ℝn

δR

δA

?

= βR ∘ δR = w ↦ δA(w) ⋅ βA

Page 40: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Relationship b/t RNN and WFA R A

26

Working hypothesis

fR ≃ fA ⇔for some p ∈ ℝd → ℝnΣ*

ℝd

ℝn

δR

δA

p

= βR ∘ δR = w ↦ δA(w) ⋅ βA

Page 41: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Relationship b/t RNN and WFA R A

■Utilizing to find counterexamples effectively

■Approximating by regression on state spacesp

p

26

Working hypothesis

fR ≃ fA ⇔for some p ∈ ℝd → ℝnΣ*

ℝd

ℝn

δR

δA

p

= βR ∘ δR = w ↦ δA(w) ⋅ βA

Page 42: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Traversal with p■ Idea:

27

Σ*

ℝd

ℝn

δR

δA

p

fR(w) ≄ fA(w) ⇔ p(δR(w)) ≄ δA(w)

Page 43: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Traversal with p■ Idea:

27

Σ*

ℝd

ℝn

δR

δA

p

if approximation is sufficiently close to

Dw = ∥p0(δR(w)) − δA(w)∥ ≫ 0p0

p

fR(w) ≄ fA(w) ⇔ p(δR(w)) ≄ δA(w)

Page 44: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Traversal with p■ Idea:

■ Traversal strategy:

nodes with larger have higher priorities

□ If is large but , is refined on

w DwDw fR(w) ≃ fA(w) p0 (δR(w), δA(w))

28

Σ*

ℝd

ℝn

δR

δA

p

if approximation is sufficiently close to

Dw = ∥p0(δR(w)) − δA(w)∥ ≫ 0p0

p

fR(w) ≄ fA(w) ⇔ p(δR(w)) ≄ δA(w)

Page 45: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

29

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Page 46: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

29

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Page 47: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

29

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Db > Da > Dc

Page 48: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

30

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Db > Da > Dc

Page 49: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

30

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Db > Da > Dc

fR(b) ≃ fA(b)

Page 50: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

30

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Db > Da > Dc

fR(b) ≃ fA(b)

Page 51: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

31

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbc > Dbb > ⋯

fR(b) ≃ fA(b)

Page 52: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

32

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbc > Dbb > ⋯

fR(b) ≃ fA(b)

Page 53: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

32

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbc > Dbb > ⋯

fR(b) ≃ fA(b)

Page 54: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

32

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbc > Dbb > ⋯

fR(b) ≃ fA(b)

Page 55: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

33

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

fR(b) ≃ fA(b)

Page 56: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

34

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

fR(b) ≃ fA(b)

Page 57: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

34

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

✔✘

fR(b) ≃ fA(b)

fR(bb) ≄ fA(bb)

Page 58: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Strategy for eR(A)Goal: implement

1. Trying to find counterexample s.t.

2(a). Returning if found2(b). Returning “ ” if no counterexample is

found even by sufficient search

eR(A) = {Eq (if fR ≃ fA)w (if fR(w) ≄ fA(w))

wfR(w) ≠ fA(w)

wEq

35

Page 59: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

36

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

Page 60: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

36

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

✔✔

Page 61: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

36

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

✔✔

Page 62: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

36

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

✔✔

Words (and their descendants) will not be checked if the “neighborhoods” of the WFA state for

have been investigated sufficiently

ww

Page 63: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

37

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

✔✔

Words (and their descendants) will not be checked if

for sufficiently many already visited words

wp(δR(w)) ≃ p(δR(w′�))

w′ �

Page 64: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

38

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

✔✔

Words (and their descendants) will not be checked if

for sufficiently many already visited words ( )

wp(δR(w)) ≃ p(δR(w′�))

M w′� M ∈ ℕ

Page 65: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Running example

38

ϵ

a b c

aa ab ac

… … …

ba bb bc

… … …

ca cb cc

… … …

Da Db Dc

Dbb > Da > ⋯

✔✔

Words (and their descendants) will not be checked if

for sufficiently many already visited words ( )

wp(δR(w)) ≃ p(δR(w′�))

M w′� M ∈ ℕ

2(b). Returning “ ” if words to check run outEq

Page 66: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

SummaryWe use to extract WFAs from RNNs

■ tells the output of an RNN for an input

■ seeks a counterexample by regression on internal state spaces of an RNN and a WFA□Deeming them equivalent if counterexamples

are not found by sufficient search

• "Sufficiency" is controlled by threshold

L*( fR, eR)fReR

M

39

Page 67: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Outline1. Introduction2. Preliminaries3. Our work: extraction of WFAs from RNNs4. Experiments

40

Page 68: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Research questionsRQ1. How well do the extracted WFAs

approximate to original RNNs?RQ2. How applicable is our method to RNNs

that are more expressive than WFAs?RQ3. How are efficient the extracted WFAs,

compared with original RNNs?

41

Page 69: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Experiment for RQ1Evaluating how well the WFAs extracted by our method approximate to original RNNs■Ours: RGR(M) (M is a threshold)□Using Gaussian process regression■Baseline: BFS(n) □By Breadth-First Search in tree traversal for finding

counterexamples

□Returning “ ” if no counterexample is found in consecutive n words (when the previous counterexample is the -th candidate word)

Eq+m

m42

Page 70: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Target RNNs■Architecture: two-layer LSTM networks■Training: performed so that the RNNs behave

similarly to randomly generated WFAs

■Training datasets: pairs

□ For “WFA-like”: is sampled from the uniform distrib.

□ For “Realistic”: is sampled from a non-uniform distrib.• Restricted to words where the occurrences of the

same letter have to be consecutive• E.g., ✔ “aabccc" ✘ “aabcca"

A(w, fA(w))

ww

43

Page 71: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Extraction from “WFA-like" RNNs

44

Each cell shows “MSE ( ) / extraction time (sec)”× 104

Observation & discussion ■MSEs are lower as extractions take longer times■ (Conjecture) Because the RNNs behave well for any

word and the amount of counterexamples investigated is more dominant than their “qualities”

Page 72: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Extraction from “WFA-like" RNNs

44

Each cell shows “MSE ( ) / extraction time (sec)”× 104

Observation & discussion ■MSEs are lower as extractions take longer times■ (Conjecture) Because the RNNs behave well for any

word and the amount of counterexamples investigated is more dominant than their “qualities”

Configurations■ : alphabet sizes■ : state sizes of WFAs

used for training RNNs

|Σ ||QA∙ |

Page 73: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Extraction from “WFA-like" RNNs

44

Ours: RGR(M)

Each cell shows “MSE ( ) / extraction time (sec)”× 104

Observation & discussion ■MSEs are lower as extractions take longer times■ (Conjecture) Because the RNNs behave well for any

word and the amount of counterexamples investigated is more dominant than their “qualities”

Configurations■ : alphabet sizes■ : state sizes of WFAs

used for training RNNs

|Σ ||QA∙ |

Page 74: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Extraction from “WFA-like" RNNs

44

Ours: RGR(M) Baseline: BFS(n)

Each cell shows “MSE ( ) / extraction time (sec)”× 104

Observation & discussion ■MSEs are lower as extractions take longer times■ (Conjecture) Because the RNNs behave well for any

word and the amount of counterexamples investigated is more dominant than their “qualities”

Configurations■ : alphabet sizes■ : state sizes of WFAs

used for training RNNs

|Σ ||QA∙ |

Page 75: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Extraction from “Realistic” RNNs

45

Ours: RGR(M) Baseline: BFS(n)

Each cell shows “MSE ( ) / extraction time (sec)”× 104

Observation & discussion ■RGR(2) performs the best■ (Conjecture) BFS(n) investigates the input space on

which the RNNs are NOT trained in more detail■ (Conjecture) RGR(2) avoids it by early pruning

Page 76: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Experiment for RQ2■Extraction from RNNs learning languages more

expressive than any WFAs

46

Page 77: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Experiment for RQ2■Extraction from RNNs learning languages more

expressive than any WFAs

■RNN learning target: (balanced parentheses)𝗐𝗉𝖺𝗋𝖾𝗇

47

𝗐𝗉𝖺𝗋𝖾𝗇(w) =001 − (1/2)N

(if contains unbalanced parentheses)

w

(otherwise; is the depth of deepest paren.)N

Example: 𝗐𝗉𝖺𝗋𝖾𝗇(′�′ �((a)(b))′ �′�) = 1 − (1/2)2 𝗐𝗉𝖺𝗋𝖾𝗇(′�′�((a)(b)′�′ �) = 0

Page 78: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Extraction result■The WFA extracted by RGR( ) □ Only largely weighted transitions by parentheses are shown□ Transition weights for letters other than parentheses are similar

5

48

by “(“by “)“

State label “q/m/n”:initial and final weightsat q are m and n, resp.

Page 79: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Extraction result■The WFA extracted by RGR( ) □ Only largely weighted transitions by parentheses are shown□ Transition weights for letters other than parentheses are similar

5

48

by “(“by “)“

State label “q/m/n”:initial and final weightsat q are m and n, resp.

is learnt successfully at least up to depth 1𝗐𝗉𝖺𝗋𝖾𝗇

Page 80: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Extraction result■The WFA extracted by RGR( ) □ Only largely weighted transitions by parentheses are shown□ Transition weights for letters other than parentheses are similar

15

49

by “(“by “)“

State label “q/m/n”:initial and final weightsat q are m and n, resp.

Page 81: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Extraction result■The WFA extracted by RGR( ) □ Only largely weighted transitions by parentheses are shown□ Transition weights for letters other than parentheses are similar

15

49

by “(“by “)“

State label “q/m/n”:initial and final weightsat q are m and n, resp.

is learnt successfully at least up to depth 2𝗐𝗉𝖺𝗋𝖾𝗇

Page 82: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Experiment for RQ3■Comparison of efficiency of running and

for RNN and the extracted WFA

■Result: is 1,300 times faster than in average□The RNNs are the same as in RQ1

fR fAR A

fA fR

50

Page 83: Weighted Automata Extraction from Recurrent Neural ...ibisml.org/ibis2019/files/2019/11/slide_sekiyama.pdf · [Luis+’03]} Extracting FAs from discrete-input RNNs. Surrogate of RNNs

Conclusion■Extracting WFAs from RNNs by

□ tells the output of an RNN for an input

□ seeks a counterexample by regressionon internal state spaces of an RNN and a WFA

■Future work□More sophisticated search for counterexamples□Dealing with huge alphabet sets□Theoretical guarantee (in an ideal case)

L*( fR, eR)fReR

51