зеркало из
				https://github.com/ssciwr/AMMICO.git
				synced 2025-10-30 21:46:04 +02:00 
			
		
		
		
	
		
			
				
	
	
		
			841 строка
		
	
	
		
			24 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			841 строка
		
	
	
		
			24 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| {
 | |
|  "cells": [
 | |
|   {
 | |
|    "attachments": {},
 | |
|    "cell_type": "markdown",
 | |
|    "id": "d2c4d40d-8aca-4024-8d19-a65c4efe825d",
 | |
|    "metadata": {},
 | |
|    "source": [
 | |
|     "# Facial Expression recognition with DeepFace"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "attachments": {},
 | |
|    "cell_type": "markdown",
 | |
|    "id": "51f8888b-d1a3-4b85-a596-95c0993fa192",
 | |
|    "metadata": {},
 | |
|    "source": [
 | |
|     "Facial expressions can be detected using [DeepFace](https://github.com/serengil/deepface) and [RetinaFace](https://github.com/serengil/retinaface).\n",
 | |
|     "\n",
 | |
|     "The first cell is only run on google colab and installs the [ammico](https://github.com/ssciwr/AMMICO) package.\n",
 | |
|     "\n",
 | |
|     "After that, we can import `ammico` and read in the files given a folder path."
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 1,
 | |
|    "id": "50c1c1c7",
 | |
|    "metadata": {
 | |
|     "execution": {
 | |
|      "iopub.execute_input": "2023-06-01T12:10:14.763268Z",
 | |
|      "iopub.status.busy": "2023-06-01T12:10:14.763012Z",
 | |
|      "iopub.status.idle": "2023-06-01T12:10:14.772386Z",
 | |
|      "shell.execute_reply": "2023-06-01T12:10:14.771746Z"
 | |
|     }
 | |
|    },
 | |
|    "outputs": [],
 | |
|    "source": [
 | |
|     "# if running on google colab\n",
 | |
|     "# flake8-noqa-cell\n",
 | |
|     "import os\n",
 | |
|     "\n",
 | |
|     "if \"google.colab\" in str(get_ipython()):\n",
 | |
|     "    # update python version\n",
 | |
|     "    # install setuptools\n",
 | |
|     "    # %pip install setuptools==61 -qqq\n",
 | |
|     "    # install ammico\n",
 | |
|     "    %pip install git+https://github.com/ssciwr/ammico.git -qqq\n",
 | |
|     "    # mount google drive for data and API key\n",
 | |
|     "    from google.colab import drive\n",
 | |
|     "\n",
 | |
|     "    drive.mount(\"/content/drive\")"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 2,
 | |
|    "id": "b21e52a5-d379-42db-aae6-f2ab9ed9a369",
 | |
|    "metadata": {
 | |
|     "execution": {
 | |
|      "iopub.execute_input": "2023-06-01T12:10:14.775826Z",
 | |
|      "iopub.status.busy": "2023-06-01T12:10:14.775358Z",
 | |
|      "iopub.status.idle": "2023-06-01T12:10:27.060820Z",
 | |
|      "shell.execute_reply": "2023-06-01T12:10:27.060074Z"
 | |
|     }
 | |
|    },
 | |
|    "outputs": [],
 | |
|    "source": [
 | |
|     "import ammico\n",
 | |
|     "from ammico import utils as mutils\n",
 | |
|     "from ammico import display as mdisplay"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "attachments": {},
 | |
|    "cell_type": "markdown",
 | |
|    "id": "a2bd2153",
 | |
|    "metadata": {},
 | |
|    "source": [
 | |
|     "We select a subset of image files to try facial expression detection on, see the `limit` keyword. The `find_files` function finds image files within a given directory:"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 3,
 | |
|    "id": "afe7e638-f09d-47e7-9295-1c374bd64c53",
 | |
|    "metadata": {
 | |
|     "execution": {
 | |
|      "iopub.execute_input": "2023-06-01T12:10:27.064821Z",
 | |
|      "iopub.status.busy": "2023-06-01T12:10:27.063992Z",
 | |
|      "iopub.status.idle": "2023-06-01T12:10:27.068527Z",
 | |
|      "shell.execute_reply": "2023-06-01T12:10:27.067749Z"
 | |
|     }
 | |
|    },
 | |
|    "outputs": [],
 | |
|    "source": [
 | |
|     "# Here you need to provide the path to your google drive folder\n",
 | |
|     "# or local folder containing the images\n",
 | |
|     "images = mutils.find_files(\n",
 | |
|     "    path=\"data/\",\n",
 | |
|     "    limit=10,\n",
 | |
|     ")"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "attachments": {},
 | |
|    "cell_type": "markdown",
 | |
|    "id": "705e7328",
 | |
|    "metadata": {},
 | |
|    "source": [
 | |
|     "We need to initialize the main dictionary that contains all information for the images and is updated through each subsequent analysis:"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 4,
 | |
|    "id": "b37c0c91",
 | |
|    "metadata": {
 | |
|     "execution": {
 | |
|      "iopub.execute_input": "2023-06-01T12:10:27.072171Z",
 | |
|      "iopub.status.busy": "2023-06-01T12:10:27.071518Z",
 | |
|      "iopub.status.idle": "2023-06-01T12:10:27.075197Z",
 | |
|      "shell.execute_reply": "2023-06-01T12:10:27.074457Z"
 | |
|     }
 | |
|    },
 | |
|    "outputs": [],
 | |
|    "source": [
 | |
|     "mydict = mutils.initialize_dict(images)"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "attachments": {},
 | |
|    "cell_type": "markdown",
 | |
|    "id": "a9372561",
 | |
|    "metadata": {},
 | |
|    "source": [
 | |
|     "To check the analysis, you can inspect the analyzed elements here. Loading the results takes a moment, so please be patient. If you are sure of what you are doing, you can skip this and directly export a csv file in the step below.\n",
 | |
|     "Here, we display the face recognition results provided by the DeepFace and RetinaFace libraries. Click on the tabs to see the results in the right sidebar. You may need to increment the `port` number if you are already running several notebook instances on the same server."
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 5,
 | |
|    "id": "992499ed-33f1-4425-ad5d-738cf565d175",
 | |
|    "metadata": {
 | |
|     "execution": {
 | |
|      "iopub.execute_input": "2023-06-01T12:10:27.078420Z",
 | |
|      "iopub.status.busy": "2023-06-01T12:10:27.078022Z",
 | |
|      "iopub.status.idle": "2023-06-01T12:10:27.133136Z",
 | |
|      "shell.execute_reply": "2023-06-01T12:10:27.132296Z"
 | |
|     }
 | |
|    },
 | |
|    "outputs": [
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "Dash is running on http://127.0.0.1:8050/\n",
 | |
|       "\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "data": {
 | |
|       "text/html": [
 | |
|        "\n",
 | |
|        "        <iframe\n",
 | |
|        "            width=\"100%\"\n",
 | |
|        "            height=\"650\"\n",
 | |
|        "            src=\"http://127.0.0.1:8050/\"\n",
 | |
|        "            frameborder=\"0\"\n",
 | |
|        "            allowfullscreen\n",
 | |
|        "            \n",
 | |
|        "        ></iframe>\n",
 | |
|        "        "
 | |
|       ],
 | |
|       "text/plain": [
 | |
|        "<IPython.lib.display.IFrame at 0x7fed2376d9d0>"
 | |
|       ]
 | |
|      },
 | |
|      "metadata": {},
 | |
|      "output_type": "display_data"
 | |
|     }
 | |
|    ],
 | |
|    "source": [
 | |
|     "analysis_explorer = mdisplay.AnalysisExplorer(mydict, identify=\"faces\")\n",
 | |
|     "analysis_explorer.run_server(port = 8050)"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "attachments": {},
 | |
|    "cell_type": "markdown",
 | |
|    "id": "6f974341",
 | |
|    "metadata": {},
 | |
|    "source": [
 | |
|     "Instead of inspecting each of the images, you can also directly carry out the analysis and export the result into a csv. This may take a while depending on how many images you have loaded."
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 6,
 | |
|    "id": "6f97c7d0",
 | |
|    "metadata": {
 | |
|     "execution": {
 | |
|      "iopub.execute_input": "2023-06-01T12:10:27.136466Z",
 | |
|      "iopub.status.busy": "2023-06-01T12:10:27.135988Z",
 | |
|      "iopub.status.idle": "2023-06-01T12:12:11.970293Z",
 | |
|      "shell.execute_reply": "2023-06-01T12:12:11.969492Z"
 | |
|     }
 | |
|    },
 | |
|    "outputs": [
 | |
|     {
 | |
|      "name": "stderr",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "Downloading data from 'https://github.com/serengil/deepface_models/releases/download/v1.0/retinaface.h5' to file '/home/runner/.cache/pooch/3be32af6e4183fa0156bc33bda371147-retinaface.h5'.\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stderr",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "Downloading data from 'https://github.com/chandrikadeb7/Face-Mask-Detection/raw/v1.0.0/mask_detector.model' to file '/home/runner/.cache/pooch/865b4b1e20f798935b70082440d5fb21-mask_detector.model'.\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stderr",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "Downloading data from 'https://github.com/serengil/deepface_models/releases/download/v1.0/age_model_weights.h5' to file '/home/runner/.cache/pooch/39859d3331cd91ac06154cc306e1acc8-age_model_weights.h5'.\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stderr",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "Downloading data from 'https://github.com/serengil/deepface_models/releases/download/v1.0/facial_expression_model_weights.h5' to file '/home/runner/.cache/pooch/dd5d5d6d8f5cecdc0fa6cb34d4d82d16-facial_expression_model_weights.h5'.\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stderr",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "Downloading data from 'https://github.com/serengil/deepface_models/releases/download/v1.0/gender_model_weights.h5' to file '/home/runner/.cache/pooch/2e0d8fb96c5ee966ade0f3f2360f6478-gender_model_weights.h5'.\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stderr",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "Downloading data from 'https://github.com/serengil/deepface_models/releases/download/v1.0/race_model_single_batch.h5' to file '/home/runner/.cache/pooch/382cb5446128012fa5305ddb9d608751-race_model_single_batch.h5'.\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\r",
 | |
|       "1/1 [==============================] - ETA: 0s"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
 | |
|       "1/1 [==============================] - 0s 419ms/step\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\r",
 | |
|       "1/1 [==============================] - ETA: 0s"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
 | |
|       "1/1 [==============================] - 0s 423ms/step\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\r",
 | |
|       "1/1 [==============================] - ETA: 0s"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
 | |
|       "1/1 [==============================] - 0s 415ms/step\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\r",
 | |
|       "1/1 [==============================] - ETA: 0s"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
 | |
|       "1/1 [==============================] - 0s 107ms/step\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\r",
 | |
|       "1/1 [==============================] - ETA: 0s"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
 | |
|       "1/1 [==============================] - 0s 236ms/step\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\r",
 | |
|       "1/1 [==============================] - ETA: 0s"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
 | |
|       "1/1 [==============================] - 0s 239ms/step\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\r",
 | |
|       "1/1 [==============================] - ETA: 0s"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
 | |
|       "1/1 [==============================] - 0s 234ms/step\n"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\r",
 | |
|       "1/1 [==============================] - ETA: 0s"
 | |
|      ]
 | |
|     },
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
 | |
|       "1/1 [==============================] - 0s 238ms/step\n"
 | |
|      ]
 | |
|     }
 | |
|    ],
 | |
|    "source": [
 | |
|     "for key in mydict.keys():\n",
 | |
|     "    mydict[key] = ammico.faces.EmotionDetector(mydict[key]).analyse_image()"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "attachments": {},
 | |
|    "cell_type": "markdown",
 | |
|    "id": "174357b1",
 | |
|    "metadata": {},
 | |
|    "source": [
 | |
|     "These steps are required to convert the dictionary of dictionarys into a dictionary with lists, that can be converted into a pandas dataframe and exported to a csv file."
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 7,
 | |
|    "id": "604bd257",
 | |
|    "metadata": {
 | |
|     "execution": {
 | |
|      "iopub.execute_input": "2023-06-01T12:12:11.990516Z",
 | |
|      "iopub.status.busy": "2023-06-01T12:12:11.990010Z",
 | |
|      "iopub.status.idle": "2023-06-01T12:12:11.999367Z",
 | |
|      "shell.execute_reply": "2023-06-01T12:12:11.998581Z"
 | |
|     }
 | |
|    },
 | |
|    "outputs": [],
 | |
|    "source": [
 | |
|     "outdict = mutils.append_data_to_dict(mydict)\n",
 | |
|     "df = mutils.dump_df(outdict)"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "attachments": {},
 | |
|    "cell_type": "markdown",
 | |
|    "id": "8373d9f8",
 | |
|    "metadata": {},
 | |
|    "source": [
 | |
|     "Check the dataframe:"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 8,
 | |
|    "id": "aa4b518a",
 | |
|    "metadata": {
 | |
|     "execution": {
 | |
|      "iopub.execute_input": "2023-06-01T12:12:12.004021Z",
 | |
|      "iopub.status.busy": "2023-06-01T12:12:12.003311Z",
 | |
|      "iopub.status.idle": "2023-06-01T12:12:12.079531Z",
 | |
|      "shell.execute_reply": "2023-06-01T12:12:12.078613Z"
 | |
|     }
 | |
|    },
 | |
|    "outputs": [
 | |
|     {
 | |
|      "data": {
 | |
|       "text/html": [
 | |
|        "<div>\n",
 | |
|        "<style scoped>\n",
 | |
|        "    .dataframe tbody tr th:only-of-type {\n",
 | |
|        "        vertical-align: middle;\n",
 | |
|        "    }\n",
 | |
|        "\n",
 | |
|        "    .dataframe tbody tr th {\n",
 | |
|        "        vertical-align: top;\n",
 | |
|        "    }\n",
 | |
|        "\n",
 | |
|        "    .dataframe thead th {\n",
 | |
|        "        text-align: right;\n",
 | |
|        "    }\n",
 | |
|        "</style>\n",
 | |
|        "<table border=\"1\" class=\"dataframe\">\n",
 | |
|        "  <thead>\n",
 | |
|        "    <tr style=\"text-align: right;\">\n",
 | |
|        "      <th></th>\n",
 | |
|        "      <th>filename</th>\n",
 | |
|        "      <th>face</th>\n",
 | |
|        "      <th>multiple_faces</th>\n",
 | |
|        "      <th>no_faces</th>\n",
 | |
|        "      <th>wears_mask</th>\n",
 | |
|        "      <th>age</th>\n",
 | |
|        "      <th>gender</th>\n",
 | |
|        "      <th>race</th>\n",
 | |
|        "      <th>emotion</th>\n",
 | |
|        "      <th>emotion (category)</th>\n",
 | |
|        "    </tr>\n",
 | |
|        "  </thead>\n",
 | |
|        "  <tbody>\n",
 | |
|        "    <tr>\n",
 | |
|        "      <th>0</th>\n",
 | |
|        "      <td>data/102730_eng.png</td>\n",
 | |
|        "      <td>Yes</td>\n",
 | |
|        "      <td>No</td>\n",
 | |
|        "      <td>1</td>\n",
 | |
|        "      <td>[No]</td>\n",
 | |
|        "      <td>[27]</td>\n",
 | |
|        "      <td>[Man]</td>\n",
 | |
|        "      <td>[asian]</td>\n",
 | |
|        "      <td>[sad]</td>\n",
 | |
|        "      <td>[Negative]</td>\n",
 | |
|        "    </tr>\n",
 | |
|        "    <tr>\n",
 | |
|        "      <th>1</th>\n",
 | |
|        "      <td>data/102141_2_eng.png</td>\n",
 | |
|        "      <td>Yes</td>\n",
 | |
|        "      <td>No</td>\n",
 | |
|        "      <td>1</td>\n",
 | |
|        "      <td>[Yes]</td>\n",
 | |
|        "      <td>[25]</td>\n",
 | |
|        "      <td>[Man]</td>\n",
 | |
|        "      <td>[None]</td>\n",
 | |
|        "      <td>[None]</td>\n",
 | |
|        "      <td>[None]</td>\n",
 | |
|        "    </tr>\n",
 | |
|        "    <tr>\n",
 | |
|        "      <th>2</th>\n",
 | |
|        "      <td>data/106349S_por.png</td>\n",
 | |
|        "      <td>Yes</td>\n",
 | |
|        "      <td>No</td>\n",
 | |
|        "      <td>1</td>\n",
 | |
|        "      <td>[Yes]</td>\n",
 | |
|        "      <td>[24]</td>\n",
 | |
|        "      <td>[Man]</td>\n",
 | |
|        "      <td>[None]</td>\n",
 | |
|        "      <td>[None]</td>\n",
 | |
|        "      <td>[None]</td>\n",
 | |
|        "    </tr>\n",
 | |
|        "  </tbody>\n",
 | |
|        "</table>\n",
 | |
|        "</div>"
 | |
|       ],
 | |
|       "text/plain": [
 | |
|        "                filename face multiple_faces  no_faces wears_mask   age  \\\n",
 | |
|        "0    data/102730_eng.png  Yes             No         1       [No]  [27]   \n",
 | |
|        "1  data/102141_2_eng.png  Yes             No         1      [Yes]  [25]   \n",
 | |
|        "2   data/106349S_por.png  Yes             No         1      [Yes]  [24]   \n",
 | |
|        "\n",
 | |
|        "  gender     race emotion emotion (category)  \n",
 | |
|        "0  [Man]  [asian]   [sad]         [Negative]  \n",
 | |
|        "1  [Man]   [None]  [None]             [None]  \n",
 | |
|        "2  [Man]   [None]  [None]             [None]  "
 | |
|       ]
 | |
|      },
 | |
|      "execution_count": 8,
 | |
|      "metadata": {},
 | |
|      "output_type": "execute_result"
 | |
|     }
 | |
|    ],
 | |
|    "source": [
 | |
|     "df.head(10)"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "attachments": {},
 | |
|    "cell_type": "markdown",
 | |
|    "id": "579cd59f",
 | |
|    "metadata": {},
 | |
|    "source": [
 | |
|     "Write the csv file - here you should provide a file path and file name for the csv file to be written."
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 9,
 | |
|    "id": "4618decb",
 | |
|    "metadata": {
 | |
|     "execution": {
 | |
|      "iopub.execute_input": "2023-06-01T12:12:12.084360Z",
 | |
|      "iopub.status.busy": "2023-06-01T12:12:12.083766Z",
 | |
|      "iopub.status.idle": "2023-06-01T12:12:12.096120Z",
 | |
|      "shell.execute_reply": "2023-06-01T12:12:12.095046Z"
 | |
|     }
 | |
|    },
 | |
|    "outputs": [],
 | |
|    "source": [
 | |
|     "df.to_csv(\"data_out.csv\")"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": null,
 | |
|    "id": "b1a80023",
 | |
|    "metadata": {},
 | |
|    "outputs": [],
 | |
|    "source": []
 | |
|   }
 | |
|  ],
 | |
|  "metadata": {
 | |
|   "kernelspec": {
 | |
|    "display_name": "Python 3 (ipykernel)",
 | |
|    "language": "python",
 | |
|    "name": "python3"
 | |
|   },
 | |
|   "language_info": {
 | |
|    "codemirror_mode": {
 | |
|     "name": "ipython",
 | |
|     "version": 3
 | |
|    },
 | |
|    "file_extension": ".py",
 | |
|    "mimetype": "text/x-python",
 | |
|    "name": "python",
 | |
|    "nbconvert_exporter": "python",
 | |
|    "pygments_lexer": "ipython3",
 | |
|    "version": "3.9.16"
 | |
|   },
 | |
|   "vscode": {
 | |
|    "interpreter": {
 | |
|     "hash": "da98320027a74839c7141b42ef24e2d47d628ba1f51115c13da5d8b45a372ec2"
 | |
|    }
 | |
|   },
 | |
|   "widgets": {
 | |
|    "application/vnd.jupyter.widget-state+json": {
 | |
|     "state": {
 | |
|      "28464916510c406b8a9930a847e2b1c8": {
 | |
|       "model_module": "@jupyter-widgets/output",
 | |
|       "model_module_version": "1.0.0",
 | |
|       "model_name": "OutputModel",
 | |
|       "state": {
 | |
|        "_dom_classes": [],
 | |
|        "_model_module": "@jupyter-widgets/output",
 | |
|        "_model_module_version": "1.0.0",
 | |
|        "_model_name": "OutputModel",
 | |
|        "_view_count": null,
 | |
|        "_view_module": "@jupyter-widgets/output",
 | |
|        "_view_module_version": "1.0.0",
 | |
|        "_view_name": "OutputView",
 | |
|        "layout": "IPY_MODEL_847a8f6b5b484ceaad648bf381f62501",
 | |
|        "msg_id": "",
 | |
|        "outputs": [
 | |
|         {
 | |
|          "name": "stdout",
 | |
|          "output_type": "stream",
 | |
|          "text": "\r1/1 [==============================] - ETA: 0s\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r1/1 [==============================] - 1s 930ms/step\n"
 | |
|         }
 | |
|        ],
 | |
|        "tabbable": null,
 | |
|        "tooltip": null
 | |
|       }
 | |
|      },
 | |
|      "3e38e74b8e6446a1b799b7a3f897b999": {
 | |
|       "model_module": "@jupyter-widgets/output",
 | |
|       "model_module_version": "1.0.0",
 | |
|       "model_name": "OutputModel",
 | |
|       "state": {
 | |
|        "_dom_classes": [],
 | |
|        "_model_module": "@jupyter-widgets/output",
 | |
|        "_model_module_version": "1.0.0",
 | |
|        "_model_name": "OutputModel",
 | |
|        "_view_count": null,
 | |
|        "_view_module": "@jupyter-widgets/output",
 | |
|        "_view_module_version": "1.0.0",
 | |
|        "_view_name": "OutputView",
 | |
|        "layout": "IPY_MODEL_c108421548da43eeabfb49787065d6e1",
 | |
|        "msg_id": "",
 | |
|        "outputs": [
 | |
|         {
 | |
|          "name": "stdout",
 | |
|          "output_type": "stream",
 | |
|          "text": "\r1/1 [==============================] - ETA: 0s\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r1/1 [==============================] - 1s 856ms/step\n"
 | |
|         }
 | |
|        ],
 | |
|        "tabbable": null,
 | |
|        "tooltip": null
 | |
|       }
 | |
|      },
 | |
|      "4bcbd82f5e8c486cb88cdbd0d8c91429": {
 | |
|       "model_module": "@jupyter-widgets/base",
 | |
|       "model_module_version": "2.0.0",
 | |
|       "model_name": "LayoutModel",
 | |
|       "state": {
 | |
|        "_model_module": "@jupyter-widgets/base",
 | |
|        "_model_module_version": "2.0.0",
 | |
|        "_model_name": "LayoutModel",
 | |
|        "_view_count": null,
 | |
|        "_view_module": "@jupyter-widgets/base",
 | |
|        "_view_module_version": "2.0.0",
 | |
|        "_view_name": "LayoutView",
 | |
|        "align_content": null,
 | |
|        "align_items": null,
 | |
|        "align_self": null,
 | |
|        "border_bottom": null,
 | |
|        "border_left": null,
 | |
|        "border_right": null,
 | |
|        "border_top": null,
 | |
|        "bottom": null,
 | |
|        "display": null,
 | |
|        "flex": null,
 | |
|        "flex_flow": null,
 | |
|        "grid_area": null,
 | |
|        "grid_auto_columns": null,
 | |
|        "grid_auto_flow": null,
 | |
|        "grid_auto_rows": null,
 | |
|        "grid_column": null,
 | |
|        "grid_gap": null,
 | |
|        "grid_row": null,
 | |
|        "grid_template_areas": null,
 | |
|        "grid_template_columns": null,
 | |
|        "grid_template_rows": null,
 | |
|        "height": null,
 | |
|        "justify_content": null,
 | |
|        "justify_items": null,
 | |
|        "left": null,
 | |
|        "margin": null,
 | |
|        "max_height": null,
 | |
|        "max_width": null,
 | |
|        "min_height": null,
 | |
|        "min_width": null,
 | |
|        "object_fit": null,
 | |
|        "object_position": null,
 | |
|        "order": null,
 | |
|        "overflow": null,
 | |
|        "padding": null,
 | |
|        "right": null,
 | |
|        "top": null,
 | |
|        "visibility": null,
 | |
|        "width": null
 | |
|       }
 | |
|      },
 | |
|      "7e163ce03c294930b5e87fcc27f7db19": {
 | |
|       "model_module": "@jupyter-widgets/output",
 | |
|       "model_module_version": "1.0.0",
 | |
|       "model_name": "OutputModel",
 | |
|       "state": {
 | |
|        "_dom_classes": [],
 | |
|        "_model_module": "@jupyter-widgets/output",
 | |
|        "_model_module_version": "1.0.0",
 | |
|        "_model_name": "OutputModel",
 | |
|        "_view_count": null,
 | |
|        "_view_module": "@jupyter-widgets/output",
 | |
|        "_view_module_version": "1.0.0",
 | |
|        "_view_name": "OutputView",
 | |
|        "layout": "IPY_MODEL_4bcbd82f5e8c486cb88cdbd0d8c91429",
 | |
|        "msg_id": "",
 | |
|        "outputs": [
 | |
|         {
 | |
|          "name": "stdout",
 | |
|          "output_type": "stream",
 | |
|          "text": "\r1/1 [==============================] - ETA: 0s\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r1/1 [==============================] - 1s 860ms/step\n"
 | |
|         }
 | |
|        ],
 | |
|        "tabbable": null,
 | |
|        "tooltip": null
 | |
|       }
 | |
|      },
 | |
|      "847a8f6b5b484ceaad648bf381f62501": {
 | |
|       "model_module": "@jupyter-widgets/base",
 | |
|       "model_module_version": "2.0.0",
 | |
|       "model_name": "LayoutModel",
 | |
|       "state": {
 | |
|        "_model_module": "@jupyter-widgets/base",
 | |
|        "_model_module_version": "2.0.0",
 | |
|        "_model_name": "LayoutModel",
 | |
|        "_view_count": null,
 | |
|        "_view_module": "@jupyter-widgets/base",
 | |
|        "_view_module_version": "2.0.0",
 | |
|        "_view_name": "LayoutView",
 | |
|        "align_content": null,
 | |
|        "align_items": null,
 | |
|        "align_self": null,
 | |
|        "border_bottom": null,
 | |
|        "border_left": null,
 | |
|        "border_right": null,
 | |
|        "border_top": null,
 | |
|        "bottom": null,
 | |
|        "display": null,
 | |
|        "flex": null,
 | |
|        "flex_flow": null,
 | |
|        "grid_area": null,
 | |
|        "grid_auto_columns": null,
 | |
|        "grid_auto_flow": null,
 | |
|        "grid_auto_rows": null,
 | |
|        "grid_column": null,
 | |
|        "grid_gap": null,
 | |
|        "grid_row": null,
 | |
|        "grid_template_areas": null,
 | |
|        "grid_template_columns": null,
 | |
|        "grid_template_rows": null,
 | |
|        "height": null,
 | |
|        "justify_content": null,
 | |
|        "justify_items": null,
 | |
|        "left": null,
 | |
|        "margin": null,
 | |
|        "max_height": null,
 | |
|        "max_width": null,
 | |
|        "min_height": null,
 | |
|        "min_width": null,
 | |
|        "object_fit": null,
 | |
|        "object_position": null,
 | |
|        "order": null,
 | |
|        "overflow": null,
 | |
|        "padding": null,
 | |
|        "right": null,
 | |
|        "top": null,
 | |
|        "visibility": null,
 | |
|        "width": null
 | |
|       }
 | |
|      },
 | |
|      "c108421548da43eeabfb49787065d6e1": {
 | |
|       "model_module": "@jupyter-widgets/base",
 | |
|       "model_module_version": "2.0.0",
 | |
|       "model_name": "LayoutModel",
 | |
|       "state": {
 | |
|        "_model_module": "@jupyter-widgets/base",
 | |
|        "_model_module_version": "2.0.0",
 | |
|        "_model_name": "LayoutModel",
 | |
|        "_view_count": null,
 | |
|        "_view_module": "@jupyter-widgets/base",
 | |
|        "_view_module_version": "2.0.0",
 | |
|        "_view_name": "LayoutView",
 | |
|        "align_content": null,
 | |
|        "align_items": null,
 | |
|        "align_self": null,
 | |
|        "border_bottom": null,
 | |
|        "border_left": null,
 | |
|        "border_right": null,
 | |
|        "border_top": null,
 | |
|        "bottom": null,
 | |
|        "display": null,
 | |
|        "flex": null,
 | |
|        "flex_flow": null,
 | |
|        "grid_area": null,
 | |
|        "grid_auto_columns": null,
 | |
|        "grid_auto_flow": null,
 | |
|        "grid_auto_rows": null,
 | |
|        "grid_column": null,
 | |
|        "grid_gap": null,
 | |
|        "grid_row": null,
 | |
|        "grid_template_areas": null,
 | |
|        "grid_template_columns": null,
 | |
|        "grid_template_rows": null,
 | |
|        "height": null,
 | |
|        "justify_content": null,
 | |
|        "justify_items": null,
 | |
|        "left": null,
 | |
|        "margin": null,
 | |
|        "max_height": null,
 | |
|        "max_width": null,
 | |
|        "min_height": null,
 | |
|        "min_width": null,
 | |
|        "object_fit": null,
 | |
|        "object_position": null,
 | |
|        "order": null,
 | |
|        "overflow": null,
 | |
|        "padding": null,
 | |
|        "right": null,
 | |
|        "top": null,
 | |
|        "visibility": null,
 | |
|        "width": null
 | |
|       }
 | |
|      }
 | |
|     },
 | |
|     "version_major": 2,
 | |
|     "version_minor": 0
 | |
|    }
 | |
|   }
 | |
|  },
 | |
|  "nbformat": 4,
 | |
|  "nbformat_minor": 5
 | |
| }
 | 
