-
Notifications
You must be signed in to change notification settings - Fork 4
AllenNLP Event2mind Classification
- AllenNLP Introduction
- Event2mind Downloading
- Event2mind Prediction
- Code Reference
- Author
Official Website: AllenNLP
Try to play with the demo website to know the usage of Event2mind: Event2mind Demo
An open-source NLP research library, built on PyTorch. AllenNLP makes it easy to design and evaluate new deep learning models for nearly any NLP problem, along with the infrastructure to easily run them in the cloud or on your laptop. AllenNLP includes reference implementations of high quality models for both core NLP problems (e.g. semantic role labeling) and NLP applications (e.g. textual entailment).
Use the code below to download the pre-trained Event2mind model from website.
wget.download("https://s3-us-west-2.amazonaws.com/allennlp/models/event2mind-2018.10.26.tar.gz", {model_path})
The Event2Mind dataset proposes a commonsense inference task between events and mental states. In particular, it takes events as lightly preprocessed text and produces likely intents and reactions for participants of the event. This model is a reimplementation of the original Event2Mind neural inference model (Rashkin et al, 2018) and was trained on the Event2Mind corpus. It achieved unigram recall of 36% for Person X’s intent, 41% for Person X’s reaction and 65% for others’ reactions.
Prediction as a Library:
from allennlp.predictors.predictor import Predictor
predictor = Predictor.from_path({model_path})
predictor.predict(source="I like wildfire.")
The execution result for this code will be a dictionary containing Person X's top 10 intents, Person X's top 10 reactions, and Person Y's top 10 reactions. The result of this code is as follows:
{'xintent_top_k_predicted_tokens': [['none'], ['mean'], ['attractive'], ['have', 'fun'], ['a', 'good', 'friend'], ['make', 'a', 'prank'], ['make', 'someone', 'laugh'], ['make', 'someone', 'happy'], ['make', 'the', 'other', 'person', 'happy'], ['make', 'the', 'other', 'person', 'feel', 'better']], 'xintent_top_k_log_probabilities': [-0.1883258819580078, -4.705990314483643, -5.4968461990356445, -5.911465167999268, -7.005738258361816, -7.461881160736084, -7.9720072746276855, -7.977940559387207, -8.405348777770996, -9.5105619430542], 'xreact_top_k_predicted_tokens': [['none'], ['sad'], ['happy'], ['ashamed'], ['@@UNKNOWN@@'], ['excited'], ['good'], ['bad'], ['guilty'], ['satisfied']], 'xreact_top_k_log_probabilities': [-0.39972591400146484, -3.357102394104004, -3.613973617553711, -4.240993499755859, -4.460747718811035, -4.897525787353516, -5.065600395202637, -5.164129257202148, -5.199481964111328, -5.453139305114746], 'oreact_top_k_predicted_tokens': [['happy'], ['sad'], ['excited'], ['none'], ['upset'], ['surprised'], ['nervous'], ['relieved'], ['pleased'], ['@@UNKNOWN@@']], 'oreact_top_k_log_probabilities': [-1.8458991050720215, -1.9932141304016113, -2.9893176555633545, -3.011362314224243, -3.7318172454833984, -3.763343572616577, -3.783658266067505, -3.8919694423675537, -4.176591873168945, -4.228587627410889]}
Related code include event2mind classifier, dumper and runnable, in the path of Wildfires/backend/classifiers/event2mind_classifier.py
, Wildfires/backend/data_preparation/dumper/event2mind_dumper.py
, and Wildfires/backend/task/event2mind_classification_runnable.py
respectively.
Yutong Wang / @RainyTong