Weighted Automata Extraction from Recurrent Neural Networks via Regression on State Spaces Takamasa Okudono, Masaki Waga, Taro Sekiyama, Ichiro Hasuo SOKENDAI, the Graduate University for Advanced Studies, Japan /National Institute of Informatics, Japan LearnAut19, Vancouver, Canada 23 June 2019 1
RNN RNN is a neural network equipped with a internal state Drawing by François Deloche ( CC BY-SA 4.0 ) 2
Goal π : Ξ£ β β β ) Input: RNN π whose output is in β (defines π π΅(π) : Ξ£ β β β ) s.t. π Output: WFA π΅(π) (defines π π΅(π) β π π Transition func. Transition matrix RNN WFA Initial vector Final vector Final func. Initial state 3
Motivation β’ Getting lighter (faster to infer) model of an RNN β’ Because the inference of RNNs are sometimes heavy β’ Investigate the behavior of RNN π via the extracted WFA π΅ π β’ WFA equips many operations and leads to model checking? β’ In research line of RNN β DFA conversion as an acceptor β’ Ours is a quantitative extension 4
Contribution β’ Proposed a method to apply Balle and Mohriβs algorithm for the extraction β’ The key is checking if π β π΅ by using regression β’ Our method extracts +7% more accurate models than the baseline β’ The extracted WFAs are about 1,000 times faster to infer than the target RNNs 5
Def. of RNN (Mathematically, in this work) RNN π (of alphabet Ξ£ and dimension π ) consists of Need not to be β’ π½ β β π : Initial state linear β’ πΎ: β π β β : Final function β’ π π : β π Γ Ξ£ β β π : Transition function β’ π π : β π Γ Ξ£ β β β π is induced recursively β π : Ξ£ β β β is induced by π π π π₯ 1 β¦ π₯ π = πΎ β π π (π½, π₯ 1 β¦ π₯ π ) The configuration for π₯ 1 β¦ π₯ π is defined by π π π₯ 1 β¦ π₯ π = π π π½, π₯ 1 β¦ π₯ π βinternal stateβ 6
Def. of Weighted Finite Automaton (WFA) WFA π΅ (of size π and alphabet Ξ£ ) consists of β’ π½ β β π : Initial vector β’ πΎ β β π : Final vector β’ π΅ π β β πΓπ : Transition matrix ( π β Ξ£ ) β π΅ : Ξ£ β β β WFA π΅ is a formalism to define π (c.f.) A DFA is a formalism to define π: Ξ£ β β 2 WFA is an extension of DFA via the matrix representation. 7
Def. of WFA π΅ : Ξ£ β β β as β’ WFA π΅ induces the function π π π΅ π₯ 1 β¦ π₯ π = π½π΅ π₯ 1 β¦ π΅ π₯ π πΎ β’ The configuration (βinternal stateβ) of WFA π΅ is π π΅ π₯ 1 β¦ π₯ π = π½π΅ π₯ 1 β¦ π΅ π₯ π β β π For example: 0.2 , πΎ = 0.9 0.7 , π΅ 0 = 0 1 0 , π΅ 1 = 0.9 0.1 β’ Ξ£ = 0, 1 , π½ = 0.8 1 0.5 0.5 0.9 0.1 0 1 0.9 β’ π π΅ 10 = 0.8 0.7 = 0.736 0.2 0.5 0.5 1 0 0.9 0.1 0 1 β’ π π΅ 10 = 0.8 0 = 0.18 0.2 0.82 0.5 0.5 1 8
RNN and WFA RNN π (of alphabet Ξ£ and dimension π ) consists of β’ π½ β β π : Initial state β’ πΎ: β π β β : Final function β’ π π : β π Γ Ξ£ β β π : Transition function β WFA π΅ (of alphabet Ξ£ and size π ) consists of β’ π½ β β π : Initial vector Similar formalism! β’ πΎ β β π : Final vector Can we approximate RNN by WFA? β’ π΅ π β β πΓπ : Transition matrix ( π β Ξ£ ) β 9
Goal and Our Approach Goal π : Ξ£ β β β ) Input: RNN π whose output is in β (defines π π΅(π) : Ξ£ β β β ) s.t. π Output: WFA π΅(π) (defines π π΅(π) β π π Approach: Use Balle and Mohriβs algorithm β’ The challenge is to give the procedure to check if π π for π΅ β π a candidate WFA π΅ 10
Balle and Mohriβs Algorithm An extension of Angluinβs L* Algorithm for WFA β’ Input: β’ Membership query procedure m: Ξ£ β β β β’ Equivalence query procedure e: WFAs β Equivalent β Ξ£ β β’ Output: Called β’ Minimal WFA π΅β² βCounterexampleβ β’ Property: Given WFA π΅ , if π = π π΅ and π΅ = αEquivalent ; π π΅ = π ΰ·¨ π΅ π α π₯ ; π π΅ π₯ β π ΰ·¨ π΅ (π₯) then, it terminates by calling π, π polynomial times and π π΅ = π π΅β² 11
Idea of Overall Architecture (Detailed) Implement β’ Membership query π to be the RNNβs induced function π π β’ Equivalence query π to be Generally it π΅ = αEquivalent ; π π β π ΰ·¨ cannot be β=β π΅ π α π₯ ; π π π₯ β π ΰ·¨ π΅ (π₯) Then we would be able to get a WFA α π΅ s.t. π π΅ ! π β π ΰ·¨ But how can we implement such an equivalence query π ? 12
How do we know π π΅ ? π β π π π π₯ β π π΅ (π₯) β πΎ π β π π π½ π , π₯ 1 β¦ π₯ π β π π΅ (π₯ 1 β¦ π₯ π )πΎ π΅ Both calculate their configurations (βinternal statesβ) If there is a βgoodβ relation between π π and π π΅ , π΅ and π would behave similarly 13
βGoodβ relation between π π and π π΅ β’ This work views π: β π β β π satisfying the following property as a good relation: βπ₯ β Ξ£ β . p π π w β π π΅ (π₯) 14
Equivalence Query by approximating π Letβs approximate configuration translator π: β π β β π such that βπ₯ β Ξ£ β . p π π w β π π΅ (π₯) by applying regression on sampled data. The data is sampled by observing Ξ£ β in Breadth-First Search. 15
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π½ π γ» π½ π΅ 16
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π½ π γ» π½ π΅ 17
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π π (0) γ» π π΅ (0) γ» π½ π γ» π½ π΅ 18
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π π (0) γ» π π΅ (0) γ» π½ π γ» π½ π΅ 19
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π π΅ (1) γ» π π (0) γ» π π (1) γ» π π΅ (0) γ» π½ π γ» π½ π΅ 20
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π π΅ (1) γ» π π (0) γ» π π (1) γ» π π΅ (0) γ» π½ π γ» π½ π΅ 21
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π π΅ (00) γ» π π (00) γ» π π΅ (1) γ» π π (0) γ» π π (1) γ» π π΅ (0) γ» π½ π γ» π½ π΅ 22
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π π΅ (00) γ» π π (00) γ» π π΅ (1) γ» π π (0) γ» π π (1) γ» π π΅ (0) γ» π½ π γ» π½ π΅ 23
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π π΅ (00) γ» π π (00) γ» π π΅ (1) γ» π π (01) γ» π π (0) γ» π π (1) γ» π π΅ 0 β π π΅ (01) γ» π½ π γ» π½ π΅ 24
Relation π between π and π΅ config. space of π΅ ( β π ) config. space of π ( β π ) γ» π π΅ (00) γ» π π (00) γ» π π΅ (1) γ» π π (01) γ» π π (0) γ» π π (1) γ» π π΅ 0 β π π΅ (01) γ» π½ π γ» π½ π΅ 25
BFS-based Equivalence Query Pop w Add w βs next from words to queue queue Equivalence query proceeds based on Breadth-First Search 26
Maintaining π Pop w Check if π Add w βs next YES from words to should be queue queue refined NO Refine π We want it to satisfy βπ₯ β π. p π π w β π π΅ (π₯) 27
Check if π should be refined config. space of π ( β π ) config. space of π΅ ( β π ) π γ» π π π₯β² γ» π π΅ π₯ β² = π(π π΅ π₯ β² ) π₯β² : a word already visited in the BFS loop π₯ : a word just popped 28
Check if π should be refined config. space of π ( β π ) config. space of π΅ ( β π ) γ» π π (π₯) π γ» π π π₯β² γ» π π΅ π₯ β² = π π π΅ π₯ β² = π π΅ (π₯) π₯β² : a word already visited in the BFS loop π₯ : a word just popped 29
Check if π should be refined config. space of π΅ ( β π ) config. space of π ( β π ) γ» π π (π₯) π γ» π π π₯β² γ» π π΅ π₯ β² = π π π΅ π₯ β² π = π π΅ π₯ = π(π π π₯ ) config. space of π ( β π ) config. space of π΅ ( β π ) π γ» π π (π₯) γ» π(π π π₯ ) π γ» π π π₯β² γ» π π΅ π₯ β² = π π π΅ π₯ β² = π π΅ (π₯) π₯β² : a word already visited in the BFS loop 30 π₯ : a word just popped
Recommend
More recommend