{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# SST-dev revalidation analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "__author__ = 'Christopher Potts'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Set-up"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "\n",
    "import dynasent_utils as utils"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "src_filename = os.path.join(\n",
    "    \"dynasent-v1.1\", \"sst-dev-validated.jsonl\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load the dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "sst = utils.load_dataset(src_filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'hit_ids': ['s20533'],\n",
       " 'sentence': '-LRB- A -RRB- n utterly charming and hilarious film that reminded me of the best of the Disney comedies from the 60s.',\n",
       " 'tree': '(4 (2 (1 -LRB-) (2 (2 A) (3 -RRB-))) (4 (4 (2 n) (4 (3 (2 utterly) (4 (3 (4 charming) (2 and)) (4 hilarious))) (3 (2 film) (3 (2 that) (4 (4 (2 (2 reminded) (3 me)) (4 (2 of) (4 (4 (2 the) (4 best)) (2 (2 of) (3 (2 the) (3 (3 Disney) (2 comedies))))))) (2 (2 from) (2 (2 the) (2 60s)))))))) (2 .)))',\n",
       " 'text_id': 'sst-dev-validate-0000437',\n",
       " 'sst_label': '4',\n",
       " 'label_distribution': {'positive': ['w207', 'w3', 'w840', 'w135', 'w26'],\n",
       "  'negative': [],\n",
       "  'neutral': [],\n",
       "  'mixed': []},\n",
       " 'gold_label': 'positive'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sst[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Validation label distributions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "positive    2129\n",
       "negative    2052\n",
       "mixed        712\n",
       "neutral      612\n",
       "Total       5505\n",
       "dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "utils.get_label_distribution(sst, dist_labels=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "positive        433\n",
       "negative        421\n",
       "mixed           108\n",
       "neutral          75\n",
       "No Majority      64\n",
       "Total          1101\n",
       "Name: gold_label, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "utils.get_label_distribution(sst, dist_labels=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Relationship between validation labels and the original SST labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(sst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.gold_label = df.gold_label.fillna(\"no majority\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "cols = ['positive', 'negative', 'neutral', 'mixed', 'no majority']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "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>sst_label</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>gold_label</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>positive</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>64</td>\n",
       "      <td>207</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>negative</th>\n",
       "      <td>132</td>\n",
       "      <td>227</td>\n",
       "      <td>57</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>neutral</th>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>44</td>\n",
       "      <td>22</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mixed</th>\n",
       "      <td>6</td>\n",
       "      <td>29</td>\n",
       "      <td>39</td>\n",
       "      <td>32</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>no majority</th>\n",
       "      <td>1</td>\n",
       "      <td>23</td>\n",
       "      <td>25</td>\n",
       "      <td>13</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "sst_label      0    1   2    3    4\n",
       "gold_label                         \n",
       "positive       0    2  64  207  160\n",
       "negative     132  227  57    5    0\n",
       "neutral        0    8  44   22    1\n",
       "mixed          6   29  39   32    2\n",
       "no majority    1   23  25   13    2"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xtab5 = pd.crosstab(df.gold_label, df.sst_label)\n",
    "\n",
    "xtab5.loc[cols]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "sst_map = {\n",
    "    '0': 'negative', '1': 'negative',\n",
    "    '2': 'neutral',\n",
    "    '3': 'positive', '4': 'positive'}\n",
    "\n",
    "df['SST-3'] = df.sst_label.apply(lambda x: sst_map[x])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "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>SST-3</th>\n",
       "      <th>positive</th>\n",
       "      <th>negative</th>\n",
       "      <th>neutral</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>gold_label</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>positive</th>\n",
       "      <td>367</td>\n",
       "      <td>2</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>negative</th>\n",
       "      <td>5</td>\n",
       "      <td>359</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>neutral</th>\n",
       "      <td>23</td>\n",
       "      <td>8</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mixed</th>\n",
       "      <td>34</td>\n",
       "      <td>35</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>no majority</th>\n",
       "      <td>15</td>\n",
       "      <td>24</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "SST-3        positive  negative  neutral\n",
       "gold_label                              \n",
       "positive          367         2       64\n",
       "negative            5       359       57\n",
       "neutral            23         8       44\n",
       "mixed              34        35       39\n",
       "no majority        15        24       25"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xtab = pd.crosstab(df.gold_label, df['SST-3'])\n",
    "\n",
    "cols = ['positive', 'negative', 'neutral', 'mixed', 'no majority']\n",
    "\n",
    "xtab[cols[: 3]].loc[cols]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Distribution of validation response distributions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5    528\n",
       "4    278\n",
       "3    231\n",
       "dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "utils.get_dist_of_majority_dists(sst)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Worker distribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(103,)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "worker_dist = utils.get_global_worker_dist(sst)\n",
    "\n",
    "worker_dist.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "w135    280\n",
       "w55     241\n",
       "w3      220\n",
       "w352    172\n",
       "w26     171\n",
       "dtype: int64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "worker_dist.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "31.0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "worker_dist.median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    10\n",
       "dtype: int64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "worker_dist.mode()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAe4AAAE/CAYAAACAdSDcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAZlUlEQVR4nO3de7RkZX3m8e8jeCE0ogx6huDlGOM1tDcaYsSJ3d4VozgBhGVUxkubLDVq2slC1NEkk6x2JjqZSTIqRISZSex4AUVAEC8N6ijYrWijDNEx7Qj0EpWLtCGaxt/8Ufvo4VCnT0HXrur3nO9nrbNO1d679v69VX3q6XfvqvdNVSFJktpwl2kXIEmSRmdwS5LUEINbkqSGGNySJDXE4JYkqSEGtyRJDektuJPcP8lnklyZ5OtJXtstf1uSa5Jc3v08u68aJElabtLX97iTHAIcUlVfTnIAsBU4Bjge2FlVf97LgSVJWsb27WvHVbUD2NHdvjnJlcChd2ZfBx98cM3Ozo6xun79+Mc/Zv/99592GRNlm1cG27wy2Obp27p16w+q6j7D1vUW3PMlmQUeC1wKHAW8OsmLgS3Ahqq6YXePn52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ds+X/P3O8xiy2+jqjZ2p+ifDXyxC+0sUtMZLP68wOBM5I27+dzDPRi0Q5oKT5VLi3s9g1OpJwKnZzCN6z2BHwM3JZlhMK/vHXVkkgd1/zF4AfC5Bes/BRyb5L4w+EBXkgdm8Inzu1TVhxmcPn7cEsc5ANjR1f3CBeuOS3KXJA8GfgW4ikHP8/e67Uny0AxmUZpvsW0uAU7oroEfAqxbpKYrgV8dsvxSBpcdDs5gQpcTgYuBy7rl985g+tDfHrbTJA+uqm1V9XYGp7IfzuCMxEvnrmFn8MG4pZ4XqupHwD92Z1vmrt/PP+PyUG4/i5Y0Mfa4pe4a97z7FzD49PDLgSOr6uYklwBvrqq3JvkK8HXg2wxO0d5RXwA2MrgefAmDeYF/rqq+keTNwCe6cP8XBj3sW4D35RcfZrtdj3yBtzAIxO8wOHV/wLx1VzEIxhngd6vqn5P8DYNr31/O4Bzx9xlcI55vsW3OZnB9ehuDU+sXL1LTecAru/3Mb/OOJG8EPsOgp3x+VX0UIMmfde24FvgGcNOQ/b4uyToGnwf4BvDxqvpJkscAW5L8lMFMV6cs8bzMeSHwru51uCuDebq/2q07CvijIY+RJsLZwaQJSrIWeENVPWfatUxLks8Bz6mqG0fcflVV7ex63GcDp1fV2Us9rg9JHgv8QVW9aBrHl8BT5ZImbwPdvPUjelt3RuQK4B+Bj/RS1WgOZtBjl6bGHrckSQ2xxy1JUkMMbkmSGmJwS5LUEINbkqSGGNySJDXE4JYkqSH/Hyo33COVdyi0AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 576x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "utils.plot_global_worker_dist(worker_dist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Examples for the paper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sample_sst_examples_by_group(df, sst_labels, gold_labels, sampsize=0, random_state=1):\n",
    "    sf = df[(df.gold_label.isin(gold_labels)) & (df['SST-3'].isin(sst_labels))].copy()\n",
    "    sf['responses'] = sf['label_distribution'].apply(utils._format_dist)\n",
    "    if sampsize == 0:\n",
    "        samp = sf\n",
    "    else:\n",
    "        samp = sf.sample(sampsize, random_state=random_state)\n",
    "    samp = samp[['sentence', 'SST-3', 'responses']].reset_index(drop=True)\n",
    "    return samp.sort_values('SST-3')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "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>sentence</th>\n",
       "      <th>SST-3</th>\n",
       "      <th>responses</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Moretti's compelling anatomy of grief and the difficult process of adapting to loss.</td>\n",
       "      <td>negative</td>\n",
       "      <td>neu, pos, pos, pos, pos</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Nothing is sacred in this gut-buster.</td>\n",
       "      <td>negative</td>\n",
       "      <td>neg, neg, pos, pos, pos</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                               sentence  \\\n",
       "0  Moretti's compelling anatomy of grief and the difficult process of adapting to loss.   \n",
       "1                                                 Nothing is sacred in this gut-buster.   \n",
       "\n",
       "      SST-3                responses  \n",
       "0  negative  neu, pos, pos, pos, pos  \n",
       "1  negative  neg, neg, pos, pos, pos  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample_sst_examples_by_group(\n",
    "    df,\n",
    "    sst_labels=['negative'],\n",
    "    gold_labels=['positive'],\n",
    "    sampsize=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "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>sentence</th>\n",
       "      <th>SST-3</th>\n",
       "      <th>responses</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>... routine, harmless diversion and little else.</td>\n",
       "      <td>positive</td>\n",
       "      <td>mix, mix, neg, neg, neg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Hilariously inept and ridiculous.</td>\n",
       "      <td>positive</td>\n",
       "      <td>mix, neg, neg, neg, neg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Reign of Fire looks as if it was made without much thought--and is best watched that way.</td>\n",
       "      <td>positive</td>\n",
       "      <td>mix, neg, neg, neg, neg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>So much facile technique, such cute ideas, so little movie.</td>\n",
       "      <td>positive</td>\n",
       "      <td>mix, mix, neg, neg, neg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>While there's something intrinsically funny about Sir Anthony Hopkins saying ` Get in the car, bitch ,' this Jerry Bruckheimer production has little else to offer</td>\n",
       "      <td>positive</td>\n",
       "      <td>mix, neg, neg, neg, neg</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                                                                                                             sentence  \\\n",
       "0                                                                                                                    ... routine, harmless diversion and little else.   \n",
       "1                                                                                                                                   Hilariously inept and ridiculous.   \n",
       "2                                                                           Reign of Fire looks as if it was made without much thought--and is best watched that way.   \n",
       "3                                                                                                         So much facile technique, such cute ideas, so little movie.   \n",
       "4  While there's something intrinsically funny about Sir Anthony Hopkins saying ` Get in the car, bitch ,' this Jerry Bruckheimer production has little else to offer   \n",
       "\n",
       "      SST-3                responses  \n",
       "0  positive  mix, mix, neg, neg, neg  \n",
       "1  positive  mix, neg, neg, neg, neg  \n",
       "2  positive  mix, neg, neg, neg, neg  \n",
       "3  positive  mix, mix, neg, neg, neg  \n",
       "4  positive  mix, neg, neg, neg, neg  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample_sst_examples_by_group(\n",
    "    df,\n",
    "    sst_labels=['positive'],\n",
    "    gold_labels=['negative'],\n",
    "    sampsize=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "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>sentence</th>\n",
       "      <th>SST-3</th>\n",
       "      <th>responses</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Returning aggressively to his formula of dimwitted comedy and even dimmer characters, Sandler, who also executive produces, has made a film that makes previous vehicles look smart and sassy.</td>\n",
       "      <td>neutral</td>\n",
       "      <td>neg, neg, neg, neg, neg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>should be seen at the very least for its spasms of absurdist humor.</td>\n",
       "      <td>neutral</td>\n",
       "      <td>pos, pos, pos, pos, pos</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A workshop mentality prevails.</td>\n",
       "      <td>neutral</td>\n",
       "      <td>neu, neu, neu, neu, neu</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Van Wilder brings a whole new meaning to the phrase ` comedy gag . '</td>\n",
       "      <td>neutral</td>\n",
       "      <td>mix, neu, pos, pos, pos</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>` They' begins and ends with scenes so terrifying I'm still stunned.</td>\n",
       "      <td>neutral</td>\n",
       "      <td>neu, neu, pos, pos, pos</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Barely gets off the ground.</td>\n",
       "      <td>neutral</td>\n",
       "      <td>neg, neg, neg, neg, neg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>As a tolerable diversion, the film suffices; a Triumph, however, it is not.</td>\n",
       "      <td>neutral</td>\n",
       "      <td>mix, mix, mix, mix, neg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Christina Ricci comedy about sympathy, hypocrisy and love is a misfire.</td>\n",
       "      <td>neutral</td>\n",
       "      <td>neg, neg, neg, neg, neg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Jacquot's rendering of Puccini's tale of devotion and double-cross is more than just a filmed opera.</td>\n",
       "      <td>neutral</td>\n",
       "      <td>neg, neu, pos, pos, pos</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Candid Camera on methamphetamines.</td>\n",
       "      <td>neutral</td>\n",
       "      <td>neg, neg, neg, neu, pos</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                                                                                                                                         sentence  \\\n",
       "0  Returning aggressively to his formula of dimwitted comedy and even dimmer characters, Sandler, who also executive produces, has made a film that makes previous vehicles look smart and sassy.   \n",
       "1                                                                                                                             should be seen at the very least for its spasms of absurdist humor.   \n",
       "2                                                                                                                                                                  A workshop mentality prevails.   \n",
       "3                                                                                                                            Van Wilder brings a whole new meaning to the phrase ` comedy gag . '   \n",
       "4                                                                                                                            ` They' begins and ends with scenes so terrifying I'm still stunned.   \n",
       "5                                                                                                                                                                     Barely gets off the ground.   \n",
       "6                                                                                                                     As a tolerable diversion, the film suffices; a Triumph, however, it is not.   \n",
       "7                                                                                                                         Christina Ricci comedy about sympathy, hypocrisy and love is a misfire.   \n",
       "8                                                                                            Jacquot's rendering of Puccini's tale of devotion and double-cross is more than just a filmed opera.   \n",
       "9                                                                                                                                                              Candid Camera on methamphetamines.   \n",
       "\n",
       "     SST-3                responses  \n",
       "0  neutral  neg, neg, neg, neg, neg  \n",
       "1  neutral  pos, pos, pos, pos, pos  \n",
       "2  neutral  neu, neu, neu, neu, neu  \n",
       "3  neutral  mix, neu, pos, pos, pos  \n",
       "4  neutral  neu, neu, pos, pos, pos  \n",
       "5  neutral  neg, neg, neg, neg, neg  \n",
       "6  neutral  mix, mix, mix, mix, neg  \n",
       "7  neutral  neg, neg, neg, neg, neg  \n",
       "8  neutral  neg, neu, pos, pos, pos  \n",
       "9  neutral  neg, neg, neg, neu, pos  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample_sst_examples_by_group(\n",
    "    df,\n",
    "    sst_labels=['neutral'],\n",
    "    gold_labels=['positive', 'negative', 'mixed', 'neutral'],\n",
    "    sampsize=10)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
