Conditional Program Generation for Bimodal Program Synthesis Swarat - - PowerPoint PPT Presentation

conditional program generation for bimodal program
SMART_READER_LITE
LIVE PREVIEW

Conditional Program Generation for Bimodal Program Synthesis Swarat - - PowerPoint PPT Presentation

Conditional Program Generation for Bimodal Program Synthesis Swarat Chaudhuri Rice University www.cs.rice.edu/~swarat (Joint work with Chris Jermaine, Vijay Murali, and Letao Qi) Program synthesis [Simon 1963, Summers 1977, Manna-Waldinger


slide-1
SLIDE 1

Conditional Program Generation for Bimodal Program Synthesis

(Joint work with Chris Jermaine, Vijay Murali, and Letao Qi)

Swarat Chaudhuri

Rice University

www.cs.rice.edu/~swarat

slide-2
SLIDE 2

Program synthesis

[Simon 1963, Summers 1977, Manna-Waldinger 1977, Pnueli-Rosner 1989]

Specification

Synthesizer

Program + Correctness Certificate Specification: Logical constraint that must be satisfied exactly Algorithm: Search for a program that satisfies the specification.

slide-3
SLIDE 3

“Bimodal” program synthesis

3

An idealized program

Candidate implementations

Prior distribution

Synthesizer

Posterior distribution

  • ver programs

Neural Sketch Learning for Conditional Program Generation. Murali, Qi, Chaudhuri, and Jermaine. Arxiv 2017.

Learned from a real-world code corpus Ambiguous “evidence” + Logical requirements

slide-4
SLIDE 4

“Bimodal” program synthesis

4

Ambiguous “evidence” + Logical requirements Candidate implementations

Prior distribution

Learned from a real-world code corpus

Synthesizer

Posterior distribution

  • ver programs
  • API calls or types that the program uses
  • “Soft” I/O examples or constraints
  • Natural language description of what the program does
  • ...

An idealized program

slide-5
SLIDE 5

The Bayou synthesizer: A demo

5

http://bit.ly/2zgP5fj

slide-6
SLIDE 6

Conditional program generation

Assume random variables 𝑌 and 𝑄𝑠𝑝𝑕, over labels and programs respectively, following a joint distribution 𝑅(𝑌, 𝑄𝑠𝑝𝑕). Offline:

  • You are given a set

𝑌*, 𝑄𝑠𝑝𝑕*

  • f samples from 𝑅(𝑌, 𝑄𝑠𝑝𝑕). From

this, learn a function 𝑕 that maps evidence to programs.

  • Learning goal: maximize 𝐹 ,,-./0 ∼2 𝐽 , where

Online: Given 𝑌, produce 𝑕(𝑌).

6

I = ⇢ 1 if g(X) ≡ Prog

  • therwise.
slide-7
SLIDE 7

In what we actually do

The map g is probabilistic. Learning is maximum conditional likelihood estimation:

  • Given {(𝑌*, 𝑄𝑠𝑝𝑕*)}, solve arg max

;

∑ log 𝑄 𝑄𝑠𝑝𝑕* 𝑌*, 𝜄)

  • *

.

7

slide-8
SLIDE 8

Programs

Language capturing the essence of API usage in Java.

8

Prog ::= skip | Prog1; Prog2 | call Call | let x = Call | if Exp then Prog1 else Prog2 | while Exp do Prog1 | try Prog1 Catch Exp ::= Sexp | Call | let x = Call : Exp1 Sexp ::= c | x Call ::= Sexp0.a(Sexp1, . . . , Sexpk) Catch ::= catch(x1) Prog1 . . . catch(xk) Progk

API method name API call

slide-9
SLIDE 9

Labels

Set of API calls

  • readline, write,…

Set of API datatypes

  • BufferedReader, FileReader,…

Set of keywords that may appear while describing program actions in English

  • read, file, write,…
  • Obtained from API calls and datatypes through a camel case

split

9

slide-10
SLIDE 10

Challenges

Directly learning over source code simply doesn’t work

  • Source code is full of low-level, program-specific names and
  • perations.
  • Programs need to satisfy structural and semantic constraints

such as type safety. Learning to satisfy these constraints is hard.

10

slide-11
SLIDE 11

Language abstractions to the rescue! Learn not over programs, but typed, syntactic models of programs.

11

slide-12
SLIDE 12

Sketches

The sketch of a program is obtained by applying an abstraction function 𝛽. From sketch 𝑍 to program 𝑄𝑠𝑝𝑕: a fixed concretization distribution 𝑄(𝑄𝑠𝑝𝑕 | 𝑍). Learning goal changes to

  • Given {(𝑌*, 𝑍

*)}, solve arg max ;

∑ log 𝑄 𝑍

* 𝑌*, 𝜄)

  • *

.

12

slide-13
SLIDE 13

13

Abstract API call

Sketches

Y ::= Call | skip | while Cond do Y1 | Y1; Y2 | try Y1 Catch | if Cond then Y1 else Y2 Catch ::= catch(τ1) Y1 . . . catch(τk) Yk Cond ::= {Call1, . . . , Callk} Call ::= a(τ1, . . . , τk)

slide-14
SLIDE 14

Program synthesis

14

Combinatorial “concretization”

Sample sketches Sketch → Executable code

Implementations satisfying 𝜒

𝑄 𝑍 𝑌)

Evidence 𝑌 Logical requirement 𝜒

Type-directed, compositional synthesizer End-to-end differentiable neural architecture

Learned from 𝒀𝒋, 𝒁𝒋 pairs

slide-15
SLIDE 15

Program synthesis

15

Combinatorial “concretization”

Sample sketches Sketch → Executable code

Implementations satisfying 𝜒

𝑄 𝑍 𝑌)

Evidence 𝑌 Logical requirement 𝜒

Type-directed, compositional synthesizer End-to-end differentiable neural architecture

Learned from 𝒀𝒋, 𝒁𝒋 pairs

Not all sketches may be realizable as executable programs

slide-16
SLIDE 16

Learning using a probabilistic encoder-decoder

16

𝑌: Evidence 𝑍: Sketches 𝑎: Latent “intent”

Representation

  • f hidden intent

Prior for regularization

Encoder f Decoder g 𝑎 𝑔(𝑌) Y 𝑌

𝑎 𝑌 𝑍

slide-17
SLIDE 17

Learning using a probabilistic encoder-decoder

17

𝑌: Evidence 𝑍: Sketches 𝑎: Latent “intent”

Encoder f Decoder g 𝑎 𝑔(𝑌) Y 𝑌 𝑄 𝑎 = 𝑂𝑝𝑠𝑛𝑏𝑚 0, 𝐽 𝑄 𝑔(𝑌) 𝑎) = 𝑂𝑝𝑠𝑛𝑏𝑚 𝑎, 𝜏S𝐽

During learning, use Jensen’s inequality to get smooth loss function

slide-18
SLIDE 18

Learning using a probabilistic encoder-decoder

18

𝑌: Evidence 𝑍: Sketches 𝑎: Latent “intent”

Encoder f Decoder g 𝑎 𝑔(𝑌) Y 𝑌

𝑄 𝑎 = 𝑂𝑝𝑠𝑛𝑏𝑚 0, 𝐽 𝑄 𝑔(𝑌) 𝑎) = 𝑂𝑝𝑠𝑛𝑏𝑚 𝑎, 𝜏S𝐽 During inference, get P(Z | X) using normal-normal conjugacy

slide-19
SLIDE 19

Neural decoder

19

0.3 0.7

Distribution on rules that can be fired at a point, given history so far. History encoded as a real vector.

slide-20
SLIDE 20

Concretization

20

Ruled out by type system

slide-21
SLIDE 21

Results

  • Trained method on 100 million lines of Java/Android code. ~2500 API

methods, ~1500 types.

  • Synthesis of method bodies from scratch, given 2-3 API calls and

types.

  • Sketch learning critical to accuracy.
  • Good performance compared to GSNNs (state of the art conditional

generative model).

  • Good results on label-sketch pairs not encountered in training set.

21

slide-22
SLIDE 22

Thank you! Questions?

22

swarat@rice.edu http://www.cs.rice.edu/~swarat

(Research funded by the DARPA MUSE award #FA8750-14-2-0270)