From Natural Language Specifications to Program Input Parsers Tao - - PowerPoint PPT Presentation

from natural language specifications to program input
SMART_READER_LITE
LIVE PREVIEW

From Natural Language Specifications to Program Input Parsers Tao - - PowerPoint PPT Presentation

From Natural Language Specifications to Program Input Parsers Tao Lei , Fan Long, Regina Barzilay, Martin Rinard CSAIL, MIT 1 Translating Natural Language to Input Parser Input Parser: Input Specification: Defines the format of input data


slide-1
SLIDE 1

From Natural Language Specifications to Program Input Parsers

Tao Lei, Fan Long, Regina Barzilay, Martin Rinard CSAIL, MIT

1

slide-2
SLIDE 2

Translating Natural Language to Input Parser

2 Input Specification: Input Parser:

Defines the format of input data

  • The input starts with a line

containing two integers n and r.

  • This is followed by n lines,

each containing two integers xi, yi, giving the coordinates of the polygon vertices.

Part of a program that reads and stores data Two Input Examples: 3 6 0 4 0 0 5 1 4 10

  • 8 2

8 14 0 14 0 6

int n, r, x[], y[]; Scanner scanner = new Scanner(new File(“input.txt”)); n = scanner.nextInt(); r = scanner.nextInt(); x = new int[n]; y = new int[n]; for (int i = 0; i < n; i++) { x[i] = scanner.nextInt(); y[i] = scanner.nextInt(); }

slide-3
SLIDE 3

Translating Natural Language to Input Parser

3 Input Specification: Input Parser:

Defines the format of input data

  • The input starts with a line

containing two integers n and r.

  • This is followed by n lines,

each containing two integers xi, yi, giving the coordinates of the polygon vertices.

Part of a program that reads and stores data Two Input Examples: 3 6 0 4 0 0 5 1 4 10

  • 8 2

8 14 0 14 0 6

int n, r, x[], y[]; Scanner scanner = new Scanner(new File(“input.txt”)); n = scanner.nextInt(); r = scanner.nextInt(); x = new int[n]; y = new int[n]; for (int i = 0; i < n; i++) { x[i] = scanner.nextInt(); y[i] = scanner.nextInt(); }

Goal: generating input parser by reading natural language

slide-4
SLIDE 4

Motivation

4

  • Reading and processing data is a common task
  • Writing input parsers is mechanical, tedious and time-consuming

John ate an apple NN VB DT NN SUBJ ROOT MOD OBJ 2 4 2 The dog barks DT NN VB MOD SUBJ ROOT 2 3 MST dependency data format This DT is VBZ a DT short JJ sentence NN . . So RB is VBZ this DT 1 Cathy Cathy N N … 2 su 2 zag zie V V … 0 ROOT 3 hen hen Pron Pron … 2 obj1 4 wild wild Adj Adj … 5 mod 5 zwaaien zwaai N N … 2 vc 6 . . Punc Punc … 5 punct … POS tagger data format CONLL dependency data format

slide-5
SLIDE 5

Motivation

5

  • Reading and processing data is a common task
  • Writing input parsers is mechanical, tedious and time-consuming

Parser Generator (our model) Input Parser (in C++, Java, …)

Input Example: 10 abc xyz uvw efg … Input Specification: “The input is one integer followed by a list of strings.”

Allows natural language as the interface to specify input

slide-6
SLIDE 6

Motivation

6

  • Reading and processing data is a common task
  • Writing input parsers is mechanical, tedious and time-consuming

Parser Generator (our model) Input Parser (in C++, Java, …)

Input Example: 10 abc xyz uvw efg … Input Specification: “The input is one integer followed by a list of strings.”

Allows natural language as the interface to specify input

Advantage: reducing programming effort and the chance of making code mistakes

slide-7
SLIDE 7

How to Translate NL to Input Parser?

7

  • Need an abstraction that connects NL and input parser

Input Specification:

The input consists of multiple sentences.

  • The first line of each sentence is the list of

words in the sentence;

  • The second line of each sentence contains

the POS tokens;

  • The third line are dependency labels;
  • The last line are integers representing the

positions of each word’s parent.

Input Parser:

sentence = [ ]; with open(“input.txt”) as fin: line = fin.readline().strip(); while line: if line != “”: word = line.split(); pos = fin.readline().split(); label = fin.readline().split(); parent = fin.readline().split(); parent = [ int(x) for x in parent ]; sentence.append( (word, pos, label, parent) ); line = fin.readline().strip();

?

slide-8
SLIDE 8

Input Example:

John ate an apple NN VB DT NN SUBJ ROOT MOD OBJ 2 4 2 The dog barks DT NN VB MOD SUBJ ROOT 2 3

8

How to Translate NL to Input Parser?

  • Need an abstraction that connects NL and input parser
slide-9
SLIDE 9

Input Example:

John ate an apple NN VB DT NN SUBJ ROOT MOD OBJ 2 4 2 The dog barks DT NN VB MOD SUBJ ROOT 2 3

… Input

9

How to Translate NL to Input Parser?

  • Need an abstraction that connects NL and input parser
slide-10
SLIDE 10

Sentences

Input Input Example:

John ate an apple NN VB DT NN SUBJ ROOT MOD OBJ 2 4 2 The dog barks DT NN VB MOD SUBJ ROOT 2 3

10

How to Translate NL to Input Parser?

  • Need an abstraction that connects NL and input parser
slide-11
SLIDE 11

Sentences

Input

Words

Input Example:

John ate an apple NN VB DT NN SUBJ ROOT MOD OBJ 2 4 2 The dog barks DT NN VB MOD SUBJ ROOT 2 3

11

How to Translate NL to Input Parser?

  • Need an abstraction that connects NL and input parser
slide-12
SLIDE 12

Sentences

Input

Words POS Tokens

Input Example:

John ate an apple NN VB DT NN SUBJ ROOT MOD OBJ 2 4 2 The dog barks DT NN VB MOD SUBJ ROOT 2 3

12

How to Translate NL to Input Parser?

  • Need an abstraction that connects NL and input parser
slide-13
SLIDE 13

Sentences

Input

Words POS Tokens Labels

Input Example:

John ate an apple NN VB DT NN SUBJ ROOT MOD OBJ 2 4 2 The dog barks DT NN VB MOD SUBJ ROOT 2 3

13

How to Translate NL to Input Parser?

  • Need an abstraction that connects NL and input parser
slide-14
SLIDE 14

Sentences

Input

Words POS Tokens Labels Position Integers

Input Example:

John ate an apple NN VB DT NN SUBJ ROOT MOD OBJ 2 4 2 The dog barks DT NN VB MOD SUBJ ROOT 2 3

14

How to Translate NL to Input Parser?

  • Need an abstraction that connects NL and input parser
slide-15
SLIDE 15

Sentences

Input

Words POS Tokens Labels Position Integers

Specification Tree

Input Example:

John ate an apple NN VB DT NN SUBJ ROOT MOD OBJ 2 4 2 The dog barks DT NN VB MOD SUBJ ROOT 2 3

15

How to Translate NL to Input Parser?

  • Need an abstraction that connects NL and input parser
  • Specification tree of nested input formats
slide-16
SLIDE 16

16

How to Translate NL to Input Parser?

Specification Tree Input Specification Input Parser

The input parser is deterministically generated from the specification tree.

  • Need an abstraction that connects NL and input parser
  • Specification tree of nested input formats
slide-17
SLIDE 17

17

How to Translate NL to Input Parser?

The input parser is deterministically generated from the specification tree.

Focus: translating input specifications into specification trees

  • Need an abstraction that connects NL and input parser
  • Specification tree of nested input formats

Specification Tree Input Specification Input Parser

slide-18
SLIDE 18

How to Translate NL to Specification Tree?

18 Specification Tree Input Specification

Specification tree is a dependency tree

  • ver noun phrases in the NL specification.

Input Specification: The input consists of multiple sentences.

  • The first line of each parse is the list of

words in the sentence;

  • The second line of each parse contains

the POS tokens;

  • The third line are dependency labels;
  • The last line are integers representing

the positions of each word’s parent.

Sentences

Input

Words POS Tokens Labels Position Integers

Task: translation as an NLP problem

slide-19
SLIDE 19

Learning Scenario

19

N input specifications 𝒙 = 𝑥1,… , 𝑥𝑂

Input

The input consists of a single test case. A test case consists of two lines. The first line contains an integer n indicating the number of molecule types. The second line contains n eight-character strings, each describing a single type of molecule, separated by single spaces. Each string consists of four two-character connector labels

some input examples for each specification

Input Example: 3 A+00A+A+ 00B+D+A- B-C+00C+ Input Example: 3 A+00A+A+ 00B+D+A- B-C+00C+ Input Example: 3 A+00A+A+ 00B+D+A- B-C+00C+

specification trees 𝒖 = 𝑢1,… , 𝑢𝑂 No human annotation corresponding input parsers

𝒖 ~ 𝑄 𝒖 𝒙

slide-20
SLIDE 20

Learning Scenario

20

N input specifications 𝒙 = 𝑥1,… , 𝑥𝑂

Input

The input consists of a single test case. A test case consists of two lines. The first line contains an integer n indicating the number of molecule types. The second line contains n eight-character strings, each describing a single type of molecule, separated by single spaces. Each string consists of four two-character connector labels

some input examples for each specification

Input Example: 3 A+00A+A+ 00B+D+A- B-C+00C+ Input Example: 3 A+00A+A+ 00B+D+A- B-C+00C+ Input Example: 3 A+00A+A+ 00B+D+A- B-C+00C+

specification trees 𝒖 = 𝑢1,… , 𝑢𝑂 No human annotation corresponding input parsers

𝒖 ~ 𝑄 𝒖 𝒙 Idea: learning from feedback -- testing input parser on input examples

slide-21
SLIDE 21

Key Intuitions

21 a correct tree should read all input examples successfully

5

  • 8

8

  • 8

a list of integers? a list of strings? a list of integer pairs?

Input Example Possible Interpretations

  • Necessary but NOT sufficient condition
  • False-positive parsers

Many input parsers can read the same input

slide-22
SLIDE 22

Key Intuitions

22 the correct trees should share common features

The input contains an integer Test case contains several strings Each line starts with two numbers X contains Y X starts with Y

a correct tree should read all input examples successfully

the input an integer test case several strings

Patterns Example Sentences Tree Structures

slide-23
SLIDE 23

Bayesian Generative Model

𝑄 𝜄 ⋅ 𝑄 𝑢𝑗 ⋅ 𝑄 𝑥𝑗 𝑢𝑗; 𝜄

𝑗

(i) Generating Parameters 𝜄⋅~ 𝐸𝑗𝑠𝑗𝑑ℎ𝑚𝑓𝑢 𝜷 (ii) Generating Specification Trees 𝑄 𝑢𝑗 ∝ 1 𝜗

parser of t i read input examples successfully

  • therwise

(iii) Generating Feature Observations 𝑄 𝑥𝑗 𝑢𝑗;𝜄 = 𝜄𝑔

𝑔∈𝜚 𝑥𝑗,𝑢𝑗

𝜚 𝑥𝑗, 𝑢𝑗 : set of features over (w

i, t i )

Idea: encode both intuitions in our model

23

the correct trees should share common features a correct tree should read all input examples successfully

slide-24
SLIDE 24

Inference: Gibbs Sampling

24

𝑢1 𝑢2 ⋯ 𝑢𝑗 ⋯ 𝑢𝑂

update specification tree t i for the i-th input specification Sample from conditional probability: 𝑢𝑗 ~ 𝑄 𝑢𝑗|𝒙,𝒖−𝑗

Intractable

𝒖 ~ 𝑄 𝒖 𝒙 = 𝑄 𝒖,𝜄 𝒙

𝜄

slide-25
SLIDE 25

Inference: Gibbs Sampling

25

𝑢1 𝑢2 ⋯ 𝑢𝑗 ⋯ 𝑢𝑂

(i) Estimate current parameters (ii) Sample a new tree (iii) Apply Metropolis-Hastings rule 𝜄∗ = 𝐹 𝜄|𝒙, 𝒖−𝑗 𝑢′~ 𝑅 𝑢′ ∝ 𝑄 𝑥𝑗|𝑢′; 𝜄∗ 𝑢𝑗 ≔ 𝑢′ with probability: min 1, 𝑄(𝑢𝑗)𝑅(𝑢′) 𝑄 𝑢′ 𝑅 𝑢𝑗

𝒖 ~ 𝑄 𝒖 𝒙 = 𝑄 𝒖,𝜄 𝒙

𝜄

update specification tree t i for the i-th input specification

slide-26
SLIDE 26

Experiments

26 Sentences: 424 Vocabulary: 781 # of Sent. in Document 1 ~ 8

  • Avg. Sent. Length

17.3 Text Statistics: Domain: Programming contest (ACM-ICPC) Training Data: 106 input specifications 100 input examples for each

relative clauses in sentences

slide-27
SLIDE 27

Evaluation Metrics

27

Recall: Precision: F-Score:

# correct specification trees # positive specification trees # correct specification trees # input specifications 2 × Precision × Recall Precision + Recall

slide-28
SLIDE 28

Baseline Models

28 Aggressive (Clarke et al. 2010) Trains a discriminative structure learner (SVMStruct) using all “positive” specification trees obtained in previous iteration; uses the learner to find the most plausible trees in the next iteration No Learning Does not learn feature parameters; randomly samples the specification tree until successfully reads all input examples Full Model - Oracle An “oracle” feedback tells our full model whether the specification tree is correct or not Aggressive - Oracle Trains SVM using perfect oracle supervision signal

slide-29
SLIDE 29

Overall Performance

80.00% 66.70% 54.50% 0% 20% 40% 60% 80% 100%

Full Model Aggressive No Learning 29 F-Score

  • Search space is exponential, and is large on difficult specifications
  • Cannot distinguish between correct parsers and false-positive parsers
slide-30
SLIDE 30

Overall Performance

80.00% 66.70% 54.50% 0% 20% 40% 60% 80% 100%

Full Model Aggressive No Learning 30 F-Score

  • Using false-positive parsers to train SVM will hurt the performance
slide-31
SLIDE 31

Overall Performance

80.00% 66.70% 54.50% 0% 20% 40% 60% 80% 100%

Full Model Aggressive No Learning 31 F-Score

  • Learns from feedback and feature observations in a joint, complementary fashion
slide-32
SLIDE 32

Comparison with Oracles

89.00% 84.10% 80.00% 50% 60% 70% 80% 90% 100%

Aggressive-Oracle Full Model-Oracle Full Model 32 F-Score

slide-33
SLIDE 33

Comparison with Oracles

89.00% 84.10% 80.00% 50% 60% 70% 80% 90% 100%

Aggressive-Oracle Full Model-Oracle Full Model 33

  • Discriminative model is better at learning from strong supervision
  • Generative model is itself much more constrained

F-Score

slide-34
SLIDE 34

Learning Curve as a Function of # Input Examples

34

  • May not be possible to obtain so many input examples
  • Retains high performance when just one example is available

totally unsupervised generative model

slide-35
SLIDE 35

Conclusion

  • A new problem in addition to generating database

queries or regular expressions from natural language

  • Our method can learn to ground natural language

descriptions of input data formats Code and data available at: http://groups.csail.mit.edu/rbg/code/nl2p

35

slide-36
SLIDE 36

36

slide-37
SLIDE 37

37

slide-38
SLIDE 38

38

slide-39
SLIDE 39

39