{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "ATE_ABSITA_SA_baseline.ipynb", "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "code", "metadata": { "id": "t_vCY7lRiEC3", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "e444d144-e81b-4ea9-d26f-bee78b86fc2c" }, "source": [ "!pip install ndjson\n", "import pandas as pd\n", "import ndjson\n", "import numpy as np\n", "dataframe = pd.DataFrame()\n", "\n", "#LOADING TRAINING SET\n", "with open(\"ate_absita_training.ndjson\") as f:\n", " reader = ndjson.reader(f)\n", "\n", " for post in reader:\n", " df = pd.DataFrame([post], columns=post.keys())\n", " dataframe = pd.concat([dataframe, df],\n", " axis=0,\n", " ignore_index=True)" ], "execution_count": 4, "outputs": [ { "output_type": "stream", "text": [ "Requirement already satisfied: ndjson in /usr/local/lib/python3.6/dist-packages (0.3.1)\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "KGgBSejQiaOB", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 589 }, "outputId": "09ffa5d0-cb20-4c17-d286-edca1b3c4a70" }, "source": [ "dataframe" ], "execution_count": 5, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sentenceid_sentencescorepolaritiesaspects_positionaspects
0Ottimo prodotto di marca, la qualità é veramen...4b7254a1-3f31-4143-ab22-a8558aa4a73b5[[0, 0], [0, 1], [1, 0]][[120, 142], [71, 79], [29, 36]][provvisto di una tasca, capiente, qualità]
1Ottimo rasoio dal semplice utilizzo. Rade molt...4b74d99d-891f-4526-bbd3-549fa244cd1c5[[1, 0], [1, 0], [1, 0], [1, 0]][[18, 26], [37, 41], [79, 86], [99, 105]][semplice, Rade, Pratico, pulire]
2Un quarto delle dimensioni dello Show original...4b7ff44f-fa9f-4ef0-97c8-e295e70ccc9b5[[1, 0], [1, 0], [1, 0], [0, 0]][[118, 132], [51, 62], [65, 70], [16, 26]][modalità notte, prestazioni, suono, dimensioni]
3Il prodotto si presenta esattamente come in fo...4b80c2fe-62eb-44ee-b7b0-6e7de7dfd1565[[1, 0], [1, 0], [1, 0]][[147, 158], [132, 140], [24, 48]][vestibilità, capienza, esattamente come in foto]
4Superlativa, velocità in scrittura superiore a...4b848496-b45c-4cc7-b378-7a047e2033c45[[1, 0]][[13, 21]][velocità]
.....................
3049Da la impressione che sia robusto ed impermeab...ff8810f6-a402-40d0-bac2-b7babce8d4cb2[[0, 0], [0, 0]][[37, 49], [26, 33]][impermeabile, robusto]
3050Purtroppo non andavano bene per la mia stampanteff9f0918-3277-43e6-82b4-44300bcb0a765[[0, 1]][[10, 27]][non andavano bene]
3051Lo stiamo usando in famiglia da qualche mese, ...ffb7deb3-d2c5-49d7-94c0-b55511f226003[[0, 1], [0, 1], [1, 0]][[126, 134], [105, 112], [83, 90]][rumoroso, pesante, qualità]
3052elettrodomestico che già dall'apparenza risult...ffd880a5-57ad-4d4c-b677-e875b181de3f5[[1, 0], [1, 0], [1, 0], [1, 0]][[106, 125], [146, 153], [199, 207], [57, 64]][il suo lavoro lo fa, potente, utilizzo, qualità]
3053Ottima alternativa a device di fascia alta..fffc61ff-f6ea-4c41-9527-8f486f057de15[[1, 0]][[7, 42]][alternativa a device di fascia alta]
\n", "

3054 rows × 6 columns

\n", "
" ], "text/plain": [ " sentence ... aspects\n", "0 Ottimo prodotto di marca, la qualità é veramen... ... [provvisto di una tasca, capiente, qualità]\n", "1 Ottimo rasoio dal semplice utilizzo. Rade molt... ... [semplice, Rade, Pratico, pulire]\n", "2 Un quarto delle dimensioni dello Show original... ... [modalità notte, prestazioni, suono, dimensioni]\n", "3 Il prodotto si presenta esattamente come in fo... ... [vestibilità, capienza, esattamente come in foto]\n", "4 Superlativa, velocità in scrittura superiore a... ... [velocità]\n", "... ... ... ...\n", "3049 Da la impressione che sia robusto ed impermeab... ... [impermeabile, robusto]\n", "3050 Purtroppo non andavano bene per la mia stampante ... [non andavano bene]\n", "3051 Lo stiamo usando in famiglia da qualche mese, ... ... [rumoroso, pesante, qualità]\n", "3052 elettrodomestico che già dall'apparenza risult... ... [il suo lavoro lo fa, potente, utilizzo, qualità]\n", "3053 Ottima alternativa a device di fascia alta.. ... [alternativa a device di fascia alta]\n", "\n", "[3054 rows x 6 columns]" ] }, "metadata": { "tags": [] }, "execution_count": 5 } ] }, { "cell_type": "code", "metadata": { "id": "6qKfKy_WiaUr", "colab_type": "code", "colab": {} }, "source": [ "X = dataframe['sentence']\n", "y = dataframe['score']" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "mep6vqfjiQUs", "colab_type": "code", "colab": {} }, "source": [ "#RMSE function\n", "def rmse(predictions, targets):\n", " return np.sqrt(((predictions - targets) ** 2).mean())\n" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "QDuArRI1iiII", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "f0d078ea-13de-4601-8724-635f1ca8a34b" }, "source": [ "#Baseline 1 - MOST FREQUENT SCORE\n", "r = []\n", "for k in range(0,len(y)):\n", " r.append(5)\n", "\n", "\n", "rmse_val = rmse(y, r)\n", "print(\"RMS error is: \" + str(rmse_val))\n", "#ON TRAINING SET 1.16458" ], "execution_count": 8, "outputs": [ { "output_type": "stream", "text": [ "RMS error is: 1.1645832271644636\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "iDUM9syuimzr", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "45675ba8-4a92-43ed-d0e4-bd46d8cb32a2" }, "source": [ "#Baseline 2 - MOST AVERAGE SCORE\n", "r = []\n", "avg = np.average(y)\n", "for k in range(0,len(y)):\n", " r.append(avg)\n", "\n", "\n", "rmse_val = rmse(y, r)\n", "print(\"RMS error is: \" + str(rmse_val))\n", "#ON TRAINING SET 1.03338" ], "execution_count": 9, "outputs": [ { "output_type": "stream", "text": [ "RMS error is: 1.0333849184367256\n" ], "name": "stdout" } ] } ] }