<jupyter_start><jupyter_text>Semantic Role Labeling(SRL)copyright 2022, <NAME>, MIT License.The notebook is an implementation of the Allen Institute for AI BERT-based model. [Reference usage of the Notebook](https://demo.allennlp.org/semantic-role-labeling/MjE4NjI1Ng==)The BERT-based model is an implementation of [<NAME> and <NAME>, (2019), ‘Simple BERT Models for Relation Extraction and Semantic Role Labeling’]( https://arxiv.org/abs/1904.05255) Intalling Allen NLP<jupyter_code>!pip install allennlp==2.1.0 allennlp-models==2.1.0<jupyter_output>Collecting allennlp==2.1.0
  Downloading allennlp-2.1.0-py3-none-any.whl (585 kB)
[K     |████████████████████████████████| 585 kB 4.8 MB/s 
[?25hCollecting allennlp-models==2.1.0
  Downloading allennlp_models-2.1.0-py3-none-any.whl (407 kB)
[K     |████████████████████████████████| 407 kB 50.7 MB/s 
[?25hRequirement already satisfied: h5py in /usr/local/lib/python3.7/dist-packages (from allennlp==2.1.0) (3.1.0)
Collecting sentencepiece
  Downloading sentencepiece-0.1.96-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)
[K     |████████████████████████████████| 1.2 MB 40.2 MB/s 
[?25hCollecting overrides==3.1.0
  Downloading overrides-3.1.0.tar.gz (11 kB)
Collecting jsonpickle
  Downloading jsonpickle-2.1.0-py2.py3-none-any.whl (38 kB)
Collecting jsonnet>=0.10.0
  Downloading jsonnet-0.18.0.tar.gz (592 kB)
[K     |████████████████████████████████| 592 kB 45.9 MB/s 
[?25hCollecting transformers<4.4,>=4.1
  Downloading transformers-4.3.3-py3-none-any.whl (1.9 MB)[...]<jupyter_text>Importing the tagging predictor<jupyter_code>from allennlp.predictors.predictor import Predictor
import allennlp_models.tagging
import json

predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/structured-prediction-srl-bert.2020.12.15.tar.gz")<jupyter_output>[nltk_data] Downloading package punkt to /root/nltk_data...
[nltk_data]   Unzipping tokenizers/punkt.zip.
[nltk_data] Downloading package wordnet to /root/nltk_data...
[nltk_data]   Unzipping corpora/wordnet.zip.<jupyter_text>Defining two display options<jupyter_code>def head(prediction):
  # Iterating through the json to display excerpt of the prediciton
  for i in prediction['verbs']:
    print('Verb:',i['verb'],i['description'])
def full(prediction):
  #print the full prediction
  print(json.dumps(prediction, indent = 1, sort_keys=True))<jupyter_output><empty_output><jupyter_text>Sample 1: Did Bob really think he could prepare a meal for 50 people in only a few hours?<jupyter_code>prediction=predictor.predict(
    sentence="Did Bob really think he could prepare a meal for 50 people in only a few hours?"
)
head(prediction)
full(prediction)<jupyter_output>{
 "verbs": [
  {
   "description": "[V: Did] Bob really think he could prepare a meal for 50 people in only a few hours ?",
   "tags": [
    "B-V",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O"
   ],
   "verb": "Did"
  },
  {
   "description": "Did [ARG0: Bob] [ARGM-ADV: really] [V: think] [ARG1: he could prepare a meal for 50 people in only a few hours] ?",
   "tags": [
    "O",
    "B-ARG0",
    "B-ARGM-ADV",
    "B-V",
    "B-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "O"
   ],
   "verb": "think"
  },
  {
   "description": "Did Bob really think he [V: could] [ARG1: prepare a meal for 50 people in only a few hours] ?",
   "tags": [
    "O",
    "O",
    "O",
    "O",
    "O",
    "B-V",
    "B-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
   [...]<jupyter_text>Sample 2: Mrs. and Mr. Tomaso went to Europe for vacation and visited Paris and first went to visit the Eiffel Tower.<jupyter_code>prediction=predictor.predict(
    sentence="Mrs. and Mr. Tomaso went to Europe for vacation and visited Paris and first went to visit the Eiffel Tower."
)
head(prediction)
full(prediction)<jupyter_output>{
 "verbs": [
  {
   "description": "[ARG0: Mrs. and Mr. Tomaso] [V: went] [ARG4: to Europe] [ARGM-PRP: for vacation] and visited Paris and first went to visit the Eiffel Tower .",
   "tags": [
    "B-ARG0",
    "I-ARG0",
    "I-ARG0",
    "I-ARG0",
    "B-V",
    "B-ARG4",
    "I-ARG4",
    "B-ARGM-PRP",
    "I-ARGM-PRP",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O"
   ],
   "verb": "went"
  },
  {
   "description": "[ARG0: Mrs. and Mr. Tomaso] went to Europe for vacation and [V: visited] [ARG1: Paris] and first went to visit the Eiffel Tower .",
   "tags": [
    "B-ARG0",
    "I-ARG0",
    "I-ARG0",
    "I-ARG0",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "B-V",
    "B-ARG1",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O"
   ],
   "verb": "visited"
  },
  {
   "description": "[ARG0: Mrs. and Mr. Tomaso] went to Europe for vacation and visited Paris and [ARGM-TMP: first] [V: w[...]<jupyter_text>Sample 3:John wanted to drink tea, Mary likes to drink coffee but Karim drank some cool water and Faiza would like to drink tomato juice.<jupyter_code>prediction=predictor.predict(
    sentence="John wanted to drink tea, Mary likes to drink coffee but Karim drank some cool water and Faiza would like to drink tomato juice."
)
head(prediction)
full(prediction)<jupyter_output>{
 "verbs": [
  {
   "description": "[ARG0: John] [V: wanted] [ARG1: to drink tea] , Mary likes to drink coffee but Karim drank some cool water and Faiza would like to drink tomato juice .",
   "tags": [
    "B-ARG0",
    "B-V",
    "B-ARG1",
    "I-ARG1",
    "I-ARG1",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O"
   ],
   "verb": "wanted"
  },
  {
   "description": "[ARG0: John] wanted to [V: drink] [ARG1: tea] , Mary likes to drink coffee but Karim drank some cool water and Faiza would like to drink tomato juice .",
   "tags": [
    "B-ARG0",
    "O",
    "O",
    "B-V",
    "B-ARG1",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O"
   ],
   "verb": "drink"
  },
  {
   "description": "John wanted to drink t[...]<jupyter_text>Sample 4: Alice, whose husband went jogging every Sunday, liked to go to a dancing class in the meantime.<jupyter_code>prediction=predictor.predict(
    sentence="Alice, whose husband went jogging every Sunday, liked to go to a dancing class in the meantime."
)
head(prediction)
full(prediction)<jupyter_output>{
 "verbs": [
  {
   "description": "Alice , [ARG0: whose husband] [V: went] [ARG1: jogging] [ARGM-TMP: every Sunday] , liked to go to a dancing class in the meantime .",
   "tags": [
    "O",
    "O",
    "B-ARG0",
    "I-ARG0",
    "B-V",
    "B-ARG1",
    "B-ARGM-TMP",
    "I-ARGM-TMP",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O"
   ],
   "verb": "went"
  },
  {
   "description": "Alice , [ARG0: whose husband] went [V: jogging] [ARGM-TMP: every Sunday] , liked to go to a dancing class in the meantime .",
   "tags": [
    "O",
    "O",
    "B-ARG0",
    "I-ARG0",
    "O",
    "B-V",
    "B-ARGM-TMP",
    "I-ARGM-TMP",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O",
    "O"
   ],
   "verb": "jogging"
  },
  {
   "description": "[ARG0: Alice , whose husband went jogging every Sunday] , [V: liked] [ARG1: to go to a dancing class in the meantime] .",
   "tags": [
    "B-ARG0"[...]<jupyter_text>Sample 5: The bright sun, the blue sky, the warm sand, the palm trees, everything round off.<jupyter_code>prediction=predictor.predict(
    sentence="The bright sun, the blue sky, the warm sand, the palm trees, everything round off."
)
head(prediction)
full(prediction)
prediction=predictor.predict(
    sentence="The bright sun, the blue sky, the warm sand, the palm trees, everything rounds off."
)
head(prediction)
full(prediction)<jupyter_output>{
 "verbs": [
  {
   "description": "[ARG1: The bright sun , the blue sky , the warm sand , the palm trees , everything] [V: rounds] [ARGM-PRD: off] .",
   "tags": [
    "B-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "I-ARG1",
    "B-V",
    "B-ARGM-PRD",
    "O"
   ],
   "verb": "rounds"
  }
 ],
 "words": [
  "The",
  "bright",
  "sun",
  ",",
  "the",
  "blue",
  "sky",
  ",",
  "the",
  "warm",
  "sand",
  ",",
  "the",
  "palm",
  "trees",
  ",",
  "everything",
  "rounds",
  "off",
  "."
 ]
}<jupyter_text>Sample 6 Ice pucks<jupyter_code>prediction=predictor.predict(
    sentence="Now, ice pucks guys!"
)
head(prediction)
full(prediction)
prediction=predictor.predict(
    sentence="Though the customer seemed unhappy, she was, in fact satisfied but thinking of something else at the time, which gave a false impression?"
)
head(prediction)<jupyter_output>Verb: seemed Though the customer [V: seemed] [ARG1: unhappy] , she was , in fact satisfied but thinking of something else at the time , which gave a false impression ?
Verb: was [ARGM-ADV: Though the customer seemed unhappy] , [ARG1: she] [V: was] , [ARGM-DIS: in fact] [ARG2: satisfied but thinking of something else at the time , which gave a false impression] ?
Verb: thinking [ARGM-ADV: Though the customer seemed unhappy] , [ARG0: she] was , in fact satisfied but [V: thinking] [ARG1: of something else] [ARGM-TMP: at the time] , [ARGM-ADV: which gave a false impression] ?
Verb: gave Though the customer seemed unhappy , she was , in fact satisfied but thinking of [ARG0: something else] at the time , [R-ARG0: which] [V: gave] [ARG1: a false impression] ?