percyliang / sempre

Semantic Parser with Execution
Other
828 stars 301 forks source link

Beginner Question: Adding more functions to Sempre #197

Closed SouLeo closed 4 years ago

SouLeo commented 4 years ago

Hello, I'm new to Sempre, and I want to try and construct a grammar for robotic tasks. I'd like to add additional functions such as

move turn rotate pause stop continue

in addition to the basic arithmetic formula made available to us. I was wondering, what is the best way to go about doing that?

Thank you!

ppasupat commented 4 years ago

The execution of functions is done by an Executor. The only public method, execute, takes a logical form and a context (e.g., world state) as input and produces a Response object.

The default executor is JavaExecutor, which executes call logical forms by looking up the Java function by name. For instance, (call java.lang.Math.cos (number 0)) in the TUTORIAL is executed by invoking cos on 0 (via Java reflection). There are a few built-in functions (e.g., + which aliases to plus) defined in JavaExecutor.

There are two main ways to add new functions:

SouLeo commented 4 years ago

Thank you!

I have one additional question. Is there a way (using SEMPRE's basic grammar features) to recurse through a complex sequence of actions within a single sentence?

For example:

“Go straight down the hallway past a bunch of rooms until you reach an intersection with a hallway on your left; turn left there."

The example above would invoke multiple actions I would create in my Executor such as: 1) (predicate: Go) (direction: straight) (extent/terminating condition: until you reach an intersection) 2) (predicate: Turn) (direction: left)

A simpler example might be:

"Robot, turn left at the door, go straight, and then turn right." 1) (predicate: Turn) (direction: left) 2) (predicate: Go) (direction: straight) 3) (predicate: Turn) (direction: right)

The point I'm trying to make is that I might have an "N" long sequence of actions invoked in a single command, and I want to know if there might be a better way to handle that then hardcoding the possible lengths.

Again, thank you so so much for your insight!

ppasupat commented 4 years ago

Unfortunately, I don't think there is a way to define a function with a variable-length argument list in JavaExecutor. I tried this before and couldn't get it to work. Besides hard-coding all possible lengths, another option is to make the execution recursive such as (call turn (call go (call turn ...) ...) ...).

SouLeo commented 4 years ago

Thanks so much!