allenai

allenai / constituency_parsing / 0.1.0

README.md

Overview

This algorithm provides state-of-the-art ability to break a sentence into its semantic parse tree.

It is a wrapper around the Constituency Parsing model put out by the AllenNLP team, which is described in Extending a Parser to Distant Domains Using a Few Dozen Partially Annotated Examples (Joshi et al, 2018).

Applicable Scenarios and Problems

Usage

By default the algorithm only returns only the actual answer to the question. However, if you run in debug mode it will return the entire output of AllenNLP's model.

Input

The input JSON blob should have the following fields:

  • sentence: the sentence to be parsed

Any additional fields will be passed through into the AllenNLP model.

Output

The following output field will always be present:

  • tokens: the parsed tokens of the sentence
  • trees: the parsed structure of the sentence including part-of-speech, expressed as a string with parentheses
  • pos_tags: the part-of-speech of each token

If you run the algorithm in debug mode there will be additional output fields, including:

  • hierplane_tree: a representation of the tree suitable for rendering in a browser

Examples

Example 1: Default Behavior

Input:

{
  "sentence": "If I bring 10 dollars tomorrow, can you buy me lunch?"
}

Output:

{
  "tokens": ["If", "I", "bring", "10", "dollars", "tomorrow", ",", "can", "you", "buy", "me", "lunch", "?"],
  "pos_tags": ["IN", "PRP", "VBP", "CD", "NNS", "NN", ",", "MD", "PRP", "VB", "PRP", "NN", "."],
  "trees": "(SQ (SBAR (IN If) (S (NP (PRP I)) (VP (VBP bring) (NP (CD 10) (NNS dollars)) (NP (NN tomorrow))))) (, ,) (MD can) (NP (PRP you)) (VP (VB buy) (NP (PRP me)) (NP (NN lunch))) (. ?))",
  "hierplane_tree": ...

Example 2: Debug Mode

Input:

{
  "sentence": "If I bring 10 dollars tomorrow, can you buy me lunch?",
  "debug": true
}

Output:

{
  "tokens": ["If", "I", "bring", "10", "dollars", "tomorrow", ",", "can", "you", "buy", "me", "lunch", "?"],
  "pos_tags": ["IN", "PRP", "VBP", "CD", "NNS", "NN", ",", "MD", "PRP", "VB", "PRP", "NN", "."],
  "trees": "(SQ (SBAR (IN If) (S (NP (PRP I)) (VP (VBP bring) (NP (CD 10) (NNS dollars)) (NP (NN tomorrow))))) (, ,) (MD can) (NP (PRP you)) (VP (VB buy) (NP (PRP me)) (NP (NN lunch))) (. ?))",
  "class_probabilities":...
}

See Also