allenai

allenai / event2mind / 0.1.0

README.md

Overview

This algorithm looks at a sentence and makes common-sense guesses about the mental states of the actors in it.

It is a wrapper around the Event2Mind put out by the AllenNLP team, which is based on the original Event2Mind neural inference model (Rashkin et al, 2018).

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:

  • source: the text 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:

  • xintent: the intentions of PersonX, along with their probabilities
  • xreact: the reactions of PersonX, along with their probabilities
  • oreact: the reactions of PersonX, along with their probabilities

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

  • xintent_top_k_predictions: a representation suitable for visualizing the parse with javascript
  • xintent_top_k_log_probabilities:
  • xintent_top_k_predicted_tokens:
  • Similar fields for xreact and oreact

Examples

Example 1: Default Behavior

Input:

{
  "source": "PersonX drops a hint"
}

Output:

{
  "xintent": [
		{"state": "none", "probability": 0.09853126381883905},
    {"state": "heard", "probability": 0.0653205319082833},
    {"state": "communicate", "probability": 0.034587512209303554},
    ...
  ],
  "xreact': [
    {"state": "secretive", "probability": 0.22708498804265329}, 
    {"state": "relieved", "probability": 0.06412349615819626}, 
    ...
  ],
  "oreact': [
    {"state": "none", "probability": 0.34621653366678967}, 
    {"state": "surprised", "probability": 0.11512464981379959}, 
    ...
  ]
}

Example 2: Debug Mode

Input:

{
  "source": "PersonX drops a hint",
  "debug": true
}

Output:

{
  "xintent": [
		{"state": "none", "probability": 0.09853126381883905},
    {"state": "heard", "probability": 0.0653205319082833},
    {"state": "communicate", "probability": 0.034587512209303554},
    ...
  ],
  "xreact': [
    {"state": "secretive", "probability": 0.22708498804265329}, 
    {"state": "relieved", "probability": 0.06412349615819626}, 
    ...
  ],
  "oreact': [
    {"state": "none", "probability": 0.34621653366678967}, 
    {"state": "surprised", "probability": 0.11512464981379959}, 
    ...
  ],
  "xintent_top_k_predictions": [
    [4, 3, 3, 3, 3, 3],
    [401, 3, 3, 3, 3, 3],
    ...
  ],
  ...
}

See Also