allenai

allenai / dependency_parsing / 0.1.0

README.md

Overview

This algorithm breaks a sentence down into "head" words and words that modify them.

It is a wrapper around the Dependency Parsing model put out by the AllenNLP team, which is based on Deep Biaffine Attention for Neural Dependency Parsing (Dozat, 2017).

Applicable Scenarios and Problems

Dependency parsing breaks a sentence down into "head" words and words that modify them. For example in the clause "I ate the plum" the head is "ate": it gives the overall structure of the clause and the other words "fill in the gaps" of what it's saying or otherwise modify it.

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
  • debug(optional): a boolean indicating whether to be in debug mode

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

Output

The following output field will always be present:

  • words: the tokens in the parsed sentence
  • predicted_heads: The predicted head (indicated by token index, counting from 1) for each token. 0 indicates a head.
  • predicted_dependencies: The part-of-speech modification each words makes to its head

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

  • hierplane_tree: a representation suitable for visualizing the parse with javascript

Examples

Example 1: Default Behavior

Input:

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

Output:

{
  "words": ["If", "I", "bring", "10", "dollars", "tomorrow", ",", "can", "you", "buy", "me", "lunch", "?"],
  "predicted_heads": [3, 3, 10, 5, 3, 3, 10, 10, 10, 0, 10, 10, 10],
  "predicted_dependencies": ["mark", "nsubj", "advcl", "num", "dobj", "tmod", "punct", "aux", "nsubj", "root", "iobj", "dobj", "punct"]
}

Example 2: Debug Mode

Input:

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

Output:

{
  "words": ["If", "I", "bring", "10", "dollars", "tomorrow", ",", "can", "you", "buy", "me", "lunch", "?"],
  "predicted_heads": [3, 3, 10, 5, 3, 3, 10, 10, 10, 0, 10, 10, 10],
  "predicted_dependencies": ["mark", "nsubj", "advcl", "num", "dobj", "tmod", "punct", "aux", "nsubj", "root", "iobj", "dobj", "punct"],
	"arc_loss":...

See Also