31
SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

Embed Size (px)

Citation preview

Page 1: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

SmartSynth: Synthesizing Smartphone Automation

Scripts from Natural Language

Vu Le (UC Davis)Sumit Gulwani (MSR Redmond)

Zhendong Su (UC Davis)

Page 2: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

motivation

Page 4: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

natural languageWhen I receive a new SMS, if the phone is connected to my car’s bluetooth, it reads the message content and replies the sender “I’m driving.”

Page 5: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

scriptwhen (number, content) := MessageReceived()

if (IsConnectedToBTDevice(Car_BT) then

Speak(content);

SendMessage(number, "I'm driving");

Page 6: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

SmartScriptScript P ::= I E T C M

Parameter I ::= input (i1, …, in) | ε

Event E ::= (r1, …, rn) := when Event() | ε

Conversions T ::= F1; …; Fn;

Condition C ::= if (Π1 ∧ … ∧ Πn) then | ε

Body M ::= Stmt1; … ; Stmtn;

Conversion F ::= x := Convert(a)

Predicate Π ::= Predicate (a1, …, an)

Statement Stmt ::= S | foreach x in a do S1; … ; Sn; od

Atomic Stmt. S ::= A | F

Action A ::= (r1, …, rn) := Action (a1, …, an)

Argument a ::= x | i | r | l

Page 7: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

approach

Script = Components + Relations

Page 8: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

approach

Script = Components + Relations

Page 9: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

approach

Script = Components + Relations

Page 10: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

approach

Script = Components + Relations

Page 11: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

definitiono Component

• API: MessageReceived

• Entity• Literal: “I’m driving”

• API return value: MessageReceived.TextO

o Relation = <Entity, API parameter>• E.g., < “I’m driving”, SendMessage.TextI

>

Page 12: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

component discovery

Description Component

When I receive a new SMS

MessageReceived

if the phone is connected to

IsConnectedToBTDevice

my car’s bluetooth Car_BT

reads Speak

the message content MessageReceived.TextO

replies SendMessage

the sender MessageReceived.NumberO

“I’m driving” "I'm driving"

Page 13: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

mapping featureso Regular expressionso Bag of wordso Phrase lengtho Punctuationo Parse tree (Stanford NLP parser)

Page 14: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

relation discoveryo Rule-based relation detection

• Relative locations of APIs and entities

Return Value or Literal API Parameter

Car_BT IsConnectedToBTDevice.TextI

MessageReceived.TextO Speak.TextI

MessageReceived.NumberO

SendMessage.NumberI

“I’m driving” SendMessage.TextI

Page 15: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

script generationwhen (number, content) := MessageReceived()

if (IsConnectedToBTDevice(Car_BT) then

Speak(content);

SendMessage(number, "I'm driving");

Page 16: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

ambiguityDescription Possible Component

Mappings

When I receive a new SMS

MessageReceived

if the phone is connected to

IsConnectedToBTDevice

IsConnectedToWifiNetwork

IsConnectedToDataService

my car’s bluetooth Car_BT

reads Speak

the message content MessageReceived.TextO

repliesSendMessage

SendEmail

“I’m driving” "I'm driving"

Page 17: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

incompletenesswhen (number, content) := MessageReceived()

if (IsConnectedToBTDevice(Car_BT) then

Speak(content);

SendMessage(number, "I'm driving");

Page 18: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

insight

NLP + Program Synthesis

Page 19: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

ambiguity{ MessagedReceived, IsConnectedToBTDevice, Car_BT,

Speak, MessageReceived.TextO, (SendMessage OR

SendEmail), "I'm driving“ }

Ranking

Script 1 (SendMessage)

SendMessage

SendEmails

Script 1

Script 2

Synthesizer

Page 20: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

incompletenesso Search for most likely missing

relations

Page 21: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

q & ao Distinguishing multiple choice

questions• Question: API parameter

• Answers: Equally-likely related entitiesWhat do you want the phone to speak?A. The received message contentB. “I’m driving”

Page 22: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

architecture

Component Discovery

ScriptDiscovery

Natural LanguageDescription

MappingComponents

IntendedScript

Natural LanguageQ&A (Optional)

1

2

3

5

User

Feedback onDescription (Optional)

6

Feedback onComp. Mapping

4

Page 23: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

evaluationo 50 scripts collected from user forumso User study: give NL descriptions from

scripts• 11 students participated

• Each student was given 25 problems

• 640 correct descriptions (725 total)

Page 24: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

component mapping

[1] [1] [2] [1] [2] [3] [1][2][3][4] SmartSynth0

10

20

30

40

50

60

70

80

90

100

Series1[1] Regex + Bags-of-Words [2] Phrase length[3] Punctuation [4] Parse tree

Page 25: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

relation detection

1 2 3 4 7 80

1

2

3

4

5

# Relations

# D

etec

ted

Rela

tions

Page 26: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

completing ratio

0 1 2 3 4 7 80

50

100

150

200

250

Detected by NLP Engine Completed by Synthesis Engine

# Relations

# D

escr

iptio

ns

Page 27: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

synthesis time

2 3 4 5 6 7 8 10 11 120

1

2

3

4

5

6

7

Parsing time Total time

# Components

Tim

e (s

)

Page 28: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

related worko General purpose programming using

natural languageo Natural language interfaceso Specification extraction from natural

language

Page 29: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

thank you

Script = Components + Relations

NLP

Program Synthesis

Identify

Detect

Resolve

Complete

Page 30: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

v.s. Siri

Conversation

Single phone API

Composition of APIs

Siri

SmartSynth

Page 31: SmartSynth: Synthesizing Smartphone Automation Scripts from Natural Language Vu Le (UC Davis) Sumit Gulwani (MSR Redmond) Zhendong Su (UC Davis)

v.s. Tasker

TaskerSmartSynth

Time

Prod

uctiv

ity