diff --git a/Chapter10/Semantic_Role_Labeling_with_ChatGPT.ipynb b/Chapter10/Semantic_Role_Labeling_with_ChatGPT.ipynb
deleted file mode 100644
index 35b1d92..0000000
--- a/Chapter10/Semantic_Role_Labeling_with_ChatGPT.ipynb
+++ /dev/null
@@ -1,744 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "b_QjF04i9neT"
- },
- "source": [
- "#Semantic Role Labeling with ChatGPT\n",
- "Copyright 2023 Denis Rothman, MIT License\n",
- "\n",
- "This notebook shows how to use GPT-3.5(ChatGPT) with the OpenAI API to perform SRL tasks:\n",
- "\n",
- "1. Installing openai and your API key
\n",
- "2. Semantic Role Labeling as exaplained in *Tranformers for NLP, 2nd Edition, Chapter 10, Semantic Role Labeling.*\n",
- "\n",
- "To get the best out of this notebook:\n",
- "* read Transformers for NLP, *Chapter 7, The Rise of Suprahuman Transformers with GPT-3 Engines* to understand the architecture of GPT engines. ChatGPT is GPT-3.5 turbo, a GPT model trained a large dataset. A GPT-3.5 turbo engine is a variant of a GPT Model. \n",
- "\n",
- "* go through the notebooks in the [BONUS directory](https://github.com/Denis2054/Transformers-for-NLP-2nd-Edition/tree/main/Bonus#readme) to learn how to implement GPT-3.5 turbo(ChatGPT).\n",
- "\n",
- "* once you have understood the theory of GPT transformers and explored the BONUS notebooks, try different sentences you find on social media that you would like to analyze in this notebook.\n",
- "\n",
- "\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "lUn5YJeQvy-F",
- "outputId": "ca450620-0aa4-4301-937f-274ecf75d073"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
- "Requirement already satisfied: pip in /usr/local/lib/python3.9/dist-packages (22.0.4)\n",
- "Collecting pip\n",
- " Downloading pip-23.0.1-py3-none-any.whl (2.1 MB)\n",
- "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m30.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
- "\u001b[?25hInstalling collected packages: pip\n",
- " Attempting uninstall: pip\n",
- " Found existing installation: pip 22.0.4\n",
- " Uninstalling pip-22.0.4:\n",
- " Successfully uninstalled pip-22.0.4\n",
- "Successfully installed pip-23.0.1\n"
- ]
- }
- ],
- "source": [
- "!pip install --upgrade pip"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "Y-crABM8l3Xi"
- },
- "source": [
- "#1.Installing openai\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "ygFUriSCvTNb"
- },
- "source": [
- "## installing and importing openai"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "9G79pIy_Mg5Y",
- "outputId": "e103d33a-ea86-418e-d642-744e5d16f950"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
- "Collecting openai\n",
- " Downloading openai-0.27.2-py3-none-any.whl (70 kB)\n",
- "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m70.1/70.1 kB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
- "\u001b[?25hCollecting aiohttp\n",
- " Downloading aiohttp-3.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB)\n",
- "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m14.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
- "\u001b[?25hRequirement already satisfied: tqdm in /usr/local/lib/python3.9/dist-packages (from openai) (4.65.0)\n",
- "Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.9/dist-packages (from openai) (2.25.1)\n",
- "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests>=2.20->openai) (1.26.14)\n",
- "Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.9/dist-packages (from requests>=2.20->openai) (4.0.0)\n",
- "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests>=2.20->openai) (2.10)\n",
- "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests>=2.20->openai) (2022.12.7)\n",
- "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.9/dist-packages (from aiohttp->openai) (22.2.0)\n",
- "Collecting multidict<7.0,>=4.5\n",
- " Downloading multidict-6.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114 kB)\n",
- "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m114.2/114.2 kB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
- "\u001b[?25hCollecting aiosignal>=1.1.2\n",
- " Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)\n",
- "Collecting async-timeout<5.0,>=4.0.0a3\n",
- " Downloading async_timeout-4.0.2-py3-none-any.whl (5.8 kB)\n",
- "Collecting charset-normalizer<4.0,>=2.0\n",
- " Downloading charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199 kB)\n",
- "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m199.2/199.2 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
- "\u001b[?25hCollecting yarl<2.0,>=1.0\n",
- " Downloading yarl-1.8.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264 kB)\n",
- "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m264.6/264.6 kB\u001b[0m \u001b[31m7.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
- "\u001b[?25hCollecting frozenlist>=1.1.1\n",
- " Downloading frozenlist-1.3.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158 kB)\n",
- "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m158.8/158.8 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
- "\u001b[?25hInstalling collected packages: multidict, frozenlist, charset-normalizer, async-timeout, yarl, aiosignal, aiohttp, openai\n",
- "Successfully installed aiohttp-3.8.4 aiosignal-1.3.1 async-timeout-4.0.2 charset-normalizer-3.1.0 frozenlist-1.3.3 multidict-6.0.4 openai-0.27.2 yarl-1.8.2\n",
- "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
- "\u001b[0m"
- ]
- }
- ],
- "source": [
- "#Importing openai\n",
- "try:\n",
- " import openai\n",
- "except:\n",
- " !pip install openai\n",
- " import openai"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "R7YHxHaLmAEi"
- },
- "source": [
- "##API Key"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "Eb6gFplQqU5v",
- "outputId": "353cbe77-ed8a-46d1-8a4f-3de99c3a8047"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Mounted at /content/drive\n"
- ]
- }
- ],
- "source": [
- "#2.API Key\n",
- "#Store you key in a file and read it(you can type it directly in the notebook but it will be visible for somebody next to you)\n",
- "from google.colab import drive\n",
- "drive.mount('/content/drive')\n",
- "f = open(\"drive/MyDrive/files/api_key.txt\", \"r\")\n",
- "API_KEY=f.readline()\n",
- "f.close()\n",
- "\n",
- "#The OpenAI Key\n",
- "import os\n",
- "os.environ['OPENAI_API_KEY'] =API_KEY\n",
- "openai.api_key = os.getenv(\"OPENAI_API_KEY\")\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "U03EQHLtmZLl"
- },
- "source": [
- "#2.ChatGPT(gpt-3.5 turbo) dialog function"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "1moBmYTVp-ih"
- },
- "source": [
- "preparing the NLP message"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "id": "wl_ih8tPqebL"
- },
- "outputs": [],
- "source": [
- " def dialog(uinput):\n",
- " #preparing the prompt for OpenAI \n",
- " role=\"user\"\n",
- " \n",
- " #prompt=\"Where is Tahiti located?\" #maintenance or if you do not want to use a microphone\n",
- " line = {\"role\": role, \"content\": uinput}\n",
- "\n",
- " #creating the mesage\n",
- " assert1={\"role\": \"system\", \"content\": \"You are a Natural Language Processing Assistant.\"}\n",
- " assert2={\"role\": \"assistant\", \"content\": \"You are helping viewers analyze social medial better.\"}\n",
- " assert3=line\n",
- " iprompt = []\n",
- " iprompt.append(assert1)\n",
- " iprompt.append(assert2)\n",
- " iprompt.append(assert3)\n",
- "\n",
- " #sending the message to ChatGPT\n",
- " response=openai.ChatCompletion.create(model=\"gpt-3.5-turbo\",messages=iprompt) #ChatGPT dialog\n",
- " text=response[\"choices\"][0][\"message\"][\"content\"] #response in JSON\n",
- "\n",
- " return text"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "wk9lev33wDdA"
- },
- "source": [
- "# 5.Semantic Role Labeling(SRL)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "DmuWMj1b55od"
- },
- "source": [
- "The 3 **basic** text samples are relatively easy.
\n",
- "The 4 **difficult** text samples are challenging.\n",
- "\n",
- "**Basic**\n",
- "\n",
- "Sample1:\n",
- "\"Did Bob really think he could prepare a meal for 50 people in only a few hours?\"\n",
- "\n",
- "Sample 2:\n",
- "\"Mrs. and Mr. Tomaso went to Europe for vacation and visited Paris and first went to visit the Eiffel Tower.\"\n",
- "\n",
- "Sample 3:\n",
- "\"John wanted to drink tea, Mary likes to drink coffee but Karim drank some cool water and Faiza would like to drink tomato juice.\"\n",
- "\n",
- "**Difficult**\n",
- "\n",
- "Sample 4 :ambiguous subject
\n",
- "\"Alice, whose husband went jogging every Sunday, liked to go to a dancing class in the meantime.\"\n",
- "\n",
- "Sample 5: *round* can be a verb, a noun, preposition, etc.In this sentence, it is a verb
\n",
- "\"The bright sun, the blue sky, the warm sand, the palm trees, everything round off.\"\n",
- "\n",
- "Sample 6: *ice* can be a noun or verb in Hockey
\n",
- "\"Now, ice pucks guys!\"\n",
- "\n",
- "Sample 7:confusing sentence with mixed descriptions
\n",
- "\"Though the customer seemed unhappy, she was, in fact satisfied but thinking of something else at the time, which gave a false impression?\"\""
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "LCGc67ca2K8p"
- },
- "source": [
- "##Semantic Role Labeling(SRL) label list provided by ChatGPT"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "D82yoEG1wnXk",
- "outputId": "71f2c6e1-8aed-4c2e-d58f-4c6b05d40e52"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Viewer request Provide the list of labels for Semantic Role Labeling\n",
- "ChatGPT Sentiment Analysis: Semantic Role Labeling (SRL) aims to identify the predicate-argument structure of a sentence and assign semantic roles to each argument. The standard set of semantic roles defined by the Proposition Bank project includes the following labels:\n",
- "\n",
- "1. Arg0: The semantic role of the subject or agent of the predicate.\n",
- "2. Arg1: The semantic role of the direct object of the predicate.\n",
- "3. Arg2: The semantic role of the indirect object of the predicate.\n",
- "4. Arg3: The semantic role of another dependent of the predicate.\n",
- "5. Arg4: The semantic role of another dependent of the predicate.\n",
- "6. Arg5: The semantic role of another dependent of the predicate.\n",
- "7. Loc: The semantic role of a location, typically expressed by a prepositional phrase.\n",
- "8. Mnr: The semantic role of an instrument or manner, typically expressed by a prepositional phrase.\n",
- "9. Tmp: The semantic role of a temporal expression, typically expressed by a prepositional phrase.\n",
- "10. Ext: The semantic role of an extent, typically expressed by a prepositional phrase.\n",
- "11. Cau: The semantic role of the cause of an event or action, typically expressed by a prepositional phrase.\n",
- "12. Prd: The semantic role of the predicate itself, used to mark changes of state or condition.\n",
- "13. Prd0: The semantic role of the pivot of a ditransitive verb.\n",
- "14. GOL: The semantic role of the goal or endpoint of a motion event, typically expressed by a prepositional phrase.\n",
- "15. DIR: The semantic role of the direction of a motion event, typically expressed by a prepositional phrase.\n",
- "16. DSP: The semantic role of the starting point or source of a motion event, typically expressed by a prepositional phrase.\n",
- "Note that the above list is not exhaustive, and different SRL frameworks might define different sets of semantic roles.\n"
- ]
- }
- ],
- "source": [
- "uinput=\"Provide the list of labels for Semantic Role Labeling\"\n",
- "text=dialog(uinput) #preparing the messages for ChatGPT\n",
- "print(\"Viewer request\",uinput)\n",
- "print(\"ChatGPT Sentiment Analysis:\",text)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "6oGNrDUg52Jm"
- },
- "source": [
- "## Basic samples"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "h8na1xlR1GKA"
- },
- "source": [
- "Sample1:
\"Did Bob really think he could prepare a meal for 50 people in only a few hours?\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "ofo_ailR2TDg",
- "outputId": "7b23dc4d-88f0-47d6-dd61-99259516fe43"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Viewer request Perform Semantic Role Labeling on the following sentence:Did Bob really think he could prepare a meal for 50 people in only a few hours?\n",
- "ChatGPT Sentiment Analysis: Here's the Semantic Role Labeling (SRL) for the given sentence:\n",
- "\n",
- "Predicate: think\n",
- "\n",
- "Semantic Roles:\n",
- "- Bob: Agent\n",
- "- really: none\n",
- "- could prepare: none\n",
- "- a meal for 50 people: Theme\n",
- "- in only a few hours: Time\n",
- "\n",
- "SRL Representation: \n",
- "\n",
- "```\n",
- "Did Bob [Agent] really [none] think [Predicate] he [none] could prepare [none] a meal for 50 people [Theme] in only a few hours [Time]?\n",
- "```\n"
- ]
- }
- ],
- "source": [
- "uinput=\"Perform Semantic Role Labeling on the following sentence:Did Bob really think he could prepare a meal for 50 people in only a few hours?\"\n",
- "text=dialog(uinput) #preparing the messages for ChatGPT\n",
- "print(\"Viewer request\",uinput)\n",
- "print(\"ChatGPT Sentiment Analysis:\",text)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "j7SBUpJx1QKP"
- },
- "source": [
- "Sample 2:
\"Mrs. and Mr. Tomaso went to Europe for vacation and visited Paris and first went to visit the Eiffel Tower.\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "ZVvAd_DB08wF",
- "outputId": "2e8f949b-21de-483e-8991-843ea29949d3"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Viewer request Perform Semantic Role Labeling on the following sentence:Mrs. and Mr. Tomaso went to Europe for vacation and visited Paris and first went to visit the Eiffel Tower.\n",
- "ChatGPT Sentiment Analysis: Here is the Semantic Role Labeling for the given sentence:\n",
- "\n",
- "```\n",
- "Predicate: went\n",
- " Arg0: Mrs. and Mr. Tomaso\n",
- " Arg1: to Europe for vacation\n",
- "\n",
- "Predicate: visited\n",
- " Arg0: Mrs. and Mr. Tomaso\n",
- " Arg1: Paris\n",
- "\n",
- "Predicate: went\n",
- " Arg0: Mrs. and Mr. Tomaso\n",
- " Arg1: to visit Eiffel Tower\n",
- "\n",
- "```\n",
- "\n",
- "So, in this sentence, the predicate \"went\" has two arguments: Mrs. and Mr. Tomaso as Arg0, and \"to Europe for vacation\" as Arg1. Similarly, the predicate \"visited\" also has two arguments: Mrs. and Mr. Tomaso as Arg0, and \"Paris\" as Arg1. Finally, the predicate \"went\" has two arguments: Mrs. and Mr. Tomaso as Arg0, and \"to visit Eiffel Tower\" as Arg1.\n"
- ]
- }
- ],
- "source": [
- "uinput=\"Perform Semantic Role Labeling on the following sentence:Mrs. and Mr. Tomaso went to Europe for vacation and visited Paris and first went to visit the Eiffel Tower.\"\n",
- "text=dialog(uinput) #preparing the messages for ChatGPT\n",
- "print(\"Viewer request\",uinput)\n",
- "print(\"ChatGPT Sentiment Analysis:\",text)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "vMKLCFaD1VJA"
- },
- "source": [
- "Sample 3:
\n",
- "\"John wanted to drink tea, Mary likes to drink coffee but Karim drank some cool water and Faiza would like to drink tomato juice.\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "waNIZTR309aG",
- "outputId": "c2cb06f6-53ae-4e17-b097-576b36bd2835"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Viewer request Perform Semantic Role Labeling on the following sentence:ohn wanted to drink tea, Mary likes to drink coffee but Karim drank some cool water and Faiza would like to drink tomato juice.\n",
- "ChatGPT Sentiment Analysis: \n",
- "\n",
- "| Word | Predicate | Argument |\n",
- "|-------|-----------|----------------|\n",
- "| John | wanted | Subject: John |\n",
- "| wanted| _ | Object: tea |\n",
- "| to | drink | _ |\n",
- "| drink | _ | Object: tea |\n",
- "| tea | drink | _ |\n",
- "| Mary | likes | Subject: Mary |\n",
- "| likes | _ | Object: coffee |\n",
- "| to | drink | _ |\n",
- "| drink | _ | Object: coffee |\n",
- "| coffee| drink | _ |\n",
- "| but | _ | _ |\n",
- "| Karim | drank | Subject: Karim |\n",
- "| drank |_ | Object: cool water |\n",
- "| some | cool water| _ |\n",
- "| cool water| drank| _ |\n",
- "| and | _ | _ |\n",
- "| Faiza | would like| Subject: Faiza |\n",
- "| would like| _ | Object: tomato juice |\n",
- "| to | drink | _ |\n",
- "| drink | _ | Object: tomato juice |\n",
- "| tomato juice| drink| _ |\n",
- "\n",
- "In Semantic Role Labeling, each word in a sentence is assigned a specific role based on its relationship with the predicate verb. The table above shows the results of the SRL analysis of the given sentence.\n"
- ]
- }
- ],
- "source": [
- "uinput=\"Perform Semantic Role Labeling on the following 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.\"\n",
- "text=dialog(uinput) #preparing the messages for ChatGPT\n",
- "print(\"Viewer request\",uinput)\n",
- "print(\"ChatGPT Sentiment Analysis:\",text)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "dVMBJwp657Z6"
- },
- "source": [
- "## Difficult samples"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "XuPnvjx_1Zkq"
- },
- "source": [
- "Sample 4 :ambiguous subject
\n",
- "\"Alice, whose husband went jogging every Sunday, liked to go to a dancing class in the meantime.\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "eyVLcVj6091_",
- "outputId": "cbceeafe-0503-4ebe-c26e-7f8f30583fc8"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Viewer request Perform Semantic Role Labeling on the following sentence:Alice, whose husband went jogging every Sunday, liked to go to a dancing class in the meantime.\n",
- "ChatGPT Sentiment Analysis: Here is the result of Semantic Role Labeling on the given sentence:\n",
- "\n",
- "| Word | Role |\n",
- "|------|------|\n",
- "| Alice | A0 |\n",
- "| , | |\n",
- "| whose | |\n",
- "| husband | A1 |\n",
- "| went | V |\n",
- "| jogging | A4 |\n",
- "| every | A5 |\n",
- "| Sunday | A5 |\n",
- "| , | |\n",
- "| liked | V |\n",
- "| to | |\n",
- "| go | V |\n",
- "| to | |\n",
- "| a | |\n",
- "| dancing | A2 |\n",
- "| class | A2 |\n",
- "| in | |\n",
- "| the | |\n",
- "| meantime | A3 |\n",
- "\n",
- "Where, \n",
- "\n",
- "- A0: Agent\n",
- "- A1: Patient/Theme\n",
- "- A2: Location\n",
- "- A3: Time\n",
- "- A4: Manner\n",
- "- A5: Time\n"
- ]
- }
- ],
- "source": [
- "uinput=\"Perform Semantic Role Labeling on the following sentence:Alice, whose husband went jogging every Sunday, liked to go to a dancing class in the meantime.\"\n",
- "text=dialog(uinput) #preparing the messages for ChatGPT\n",
- "print(\"Viewer request\",uinput)\n",
- "print(\"ChatGPT Sentiment Analysis:\",text)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "utY0S4Sl1aDh"
- },
- "source": [
- "Sample 5: *round* can be a verb, a noun, preposition, etc.In this sentence, it is a verb
\n",
- "\"The bright sun, the blue sky, the warm sand, the palm trees, everything round off.\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "bHhHHddC0-L5",
- "outputId": "e8fe03ca-9e6b-4d40-d834-c40005859def"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Viewer request Perform Semantic Role Labeling on the following sentence:The bright sun, the blue sky, the warm sand, the palm trees, everything round off.\n",
- "ChatGPT Sentiment Analysis: Here is the Semantic Role Labeling of the given sentence:\n",
- "\n",
- "```\n",
- "Predicate: round off\n",
- "Arguments:\n",
- " - Arg0: everything\n",
- " - Arg1: the bright sun\n",
- " - Arg2: the blue sky\n",
- " - Arg3: the warm sand\n",
- " - Arg4: the palm trees\n",
- "```\n",
- "\n",
- "In this sentence, the verb \"round off\" is the predicate. The other words in the sentence are its arguments. They help to define the semantic roles of the sentence's components. The roles of the arguments in this sentence are as follows:\n",
- "\n",
- "- Arg0 (everything): this is the thing that is rounded off.\n",
- "- Arg1 (the bright sun): this is one of the things that contribute to the rounding off.\n",
- "- Arg2 (the blue sky): this is another thing that contributes to the rounding off.\n",
- "- Arg3 (the warm sand): this is yet another thing that contributes to the rounding off.\n",
- "- Arg4 (the palm trees): this is the last component that contributes to rounding off.\n"
- ]
- }
- ],
- "source": [
- "uinput=\"Perform Semantic Role Labeling on the following sentence:The bright sun, the blue sky, the warm sand, the palm trees, everything round off.\"\n",
- "text=dialog(uinput) #preparing the messages for ChatGPT\n",
- "print(\"Viewer request\",uinput)\n",
- "print(\"ChatGPT Sentiment Analysis:\",text)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "PP1-XWe21aw1"
- },
- "source": [
- "Sample 6: *ice* can be a noun or verb in Hockey
\n",
- "This sentence seems to difficult for ChatGPT. The model isn't good at neing hockey coach!
\n",
- "\"Now, ice pucks guys!\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "nD56SRycwLe-",
- "outputId": "964ef606-5025-4b71-9c13-c9c31092337c"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Viewer request Perform Semantic Role Labeling on the following sentence:Now, ice pucks guys!\n",
- "ChatGPT Sentiment Analysis: I'm sorry, but the given sentence \"Now, ice pucks guys!\" is not a grammatically correct sentence or a complete thought, so it cannot be analyzed for Semantic Role Labeling. A sentence must have a subject, a verb, and a complete sense to be analyzed for semantic roles. Can you please provide a valid sentence for me to perform Semantic Role Labeling on?\n"
- ]
- }
- ],
- "source": [
- "uinput=\"Perform Semantic Role Labeling on the following sentence:Now, ice pucks guys!\"\n",
- "text=dialog(uinput) #preparing the messages for ChatGPT\n",
- "print(\"Viewer request\",uinput)\n",
- "print(\"ChatGPT Sentiment Analysis:\",text)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "v6KxyIIt1bX-"
- },
- "source": [
- "Sample 7:confusing sentence with mixed descriptions
\n",
- "\"Though the customer seemed unhappy, she was, in fact satisfied but thinking of something else at the time, which gave a false impression?\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "FM3Bn0cNwYae",
- "outputId": "b527d8c4-d02f-40ce-ac8e-9a058b518d9d"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Viewer request Perform Semantic Role Labeling on the following sentence:Though the customer seemed unhappy, she was, in fact satisfied but thinking of something else at the time, which gave a false impression?\n",
- "ChatGPT Sentiment Analysis: Sure! Here's the Semantic Role Labeling for the given sentence:\n",
- "\n",
- "```\n",
- "Predicate: seemed\n",
- " └── Arg0: customer\n",
- " └── Arg1: unhappy\n",
- "\n",
- "Predicate: was\n",
- " └── Arg0: she\n",
- " └── Arg1: satisfied\n",
- " └── ArgManner: in fact\n",
- " └── Arg2: thinking of something else at the time\n",
- " └── Arg3: gave\n",
- " └── Arg4: false impression\n",
- "```\n",
- "\n",
- "The above output has identified the predicates of the sentence, along with their arguments and the Semantic Role associated with each argument. The Arg0 refers to the noun which performs the action in the predicate; Arg1 refers to the noun which is the recipient of the action in the predicate, ArgManner refers to the manner in which the action is performed, Arg2 refers to the noun which relates to the predicate and Arg3 and Arg4 refer to any other phrase which serves as an auxiliary meaning to the predicate.\n"
- ]
- }
- ],
- "source": [
- "uinput=\"Perform Semantic Role Labeling on the following sentence:Though the customer seemed unhappy, she was, in fact satisfied but thinking of something else at the time, which gave a false impression?\"\n",
- "text=dialog(uinput) #preparing the messages for ChatGPT\n",
- "print(\"Viewer request\",uinput)\n",
- "print(\"ChatGPT Sentiment Analysis:\",text)"
- ]
- }
- ],
- "metadata": {
- "colab": {
- "provenance": [],
- "toc_visible": true
- },
- "kernelspec": {
- "display_name": "Python 3",
- "name": "python3"
- },
- "language_info": {
- "name": "python"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 0
-}