This module contains code relating to processing logical forms for semantic parsing. The main functionality provided by this code is:
1. A way of declaring a type system for use in processing logical forms. This determines which (lisp-like) logical forms are valid in your logical form language, and it enables us to parse statements in that language into logical expressions. We rely heavily on NLTK for the logic processing here. This is the
2. A way of specifying extra “context” that’s available to the parser / type system. Currently, this just consists of a
KnowledgeGraphthat can represent table entities, or question-specific entities. These entities can be made available to the type system to allow context-specific production rules. This is the
3. A way to bundle the two things above together in the context of a particular training / testing instance. This bundling is called a
World, and this is the primary means that a model should use to interact with the type system. The
Worldhas methods to get all possible actions in any state, all context entities that need to be linked, and so on. This is the
Note that the main reason you would use this code is to get the set of actions that are available at any point during constrained decoding. If you have some other means of doing that, you might not need this code at all.
ActionSpaceWalker(world: allennlp.semparse.worlds.world.World, max_path_length: int) → None¶
ActionSpaceWalkertakes a world, traverses all the valid paths driven by the valid action specification of the world to generate all possible logical forms (under some constraints). This class also has some utilities for indexing logical forms to efficiently retrieve required subsets.
- world :
The world from which valid actions will be taken.
- max_path_length :
The maximum path length till which the action space will be explored. Paths longer than this length will be discarded.
get_all_logical_forms(max_num_logical_forms: int = None) → typing.List[str]¶
get_logical_forms_with_agenda(agenda: typing.List[str], max_num_logical_forms: int = None) → typing.List[str]¶
- world :