{ "cells": [ { "cell_type": "markdown", "id": "9949dcdb", "metadata": {}, "source": [ "# Prepare SST data for gender annotation\n", "\n", "* Import SST data from huggingface\n", "* Use word lists to automatically annotate (pre-annotate?) sentences for gender\n", "* Subsample gendered sentences: 400 masculine, 400 feminine, 400 neutral\n", "* Prepare CSVs for human annotation" ] }, { "cell_type": "markdown", "id": "5badcb9d", "metadata": {}, "source": [ "## Import SST data from huggingface" ] }, { "cell_type": "code", "execution_count": 2, "id": "022eb689", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "id": "1f0b6c0f", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "846f46d502ab4b818dd0884151663b83", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading builder script: 0%| | 0.00/2.59k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "938ebd31e7e44fec8cf6558c0b3467e4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading metadata: 0%| | 0.00/1.17k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "No config specified, defaulting to: sst/default\n", "Reusing dataset sst (/Users/katygero/.cache/huggingface/datasets/sst/default/1.0.0/b8a7889ef01c5d3ae8c379b84cc4080f8aad3ac2bc538701cbe0ac6416fb76ff)\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7ece2dc64d6b4207949652de2450479a", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/3 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from datasets import load_dataset\n", "\n", "dataset = load_dataset(\"sst\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "453d8782", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'sentence': \"The Rock is destined to be the 21st Century 's new `` Conan '' and that he 's going to make a splash even greater than Arnold Schwarzenegger , Jean-Claud Van Damme or Steven Segal .\",\n", " 'label': 0.6944400072097778,\n", " 'tokens': \"The|Rock|is|destined|to|be|the|21st|Century|'s|new|``|Conan|''|and|that|he|'s|going|to|make|a|splash|even|greater|than|Arnold|Schwarzenegger|,|Jean-Claud|Van|Damme|or|Steven|Segal|.\",\n", " 'tree': '70|70|68|67|63|62|61|60|58|58|57|56|56|64|65|55|54|53|52|51|49|47|47|46|46|45|40|40|41|39|38|38|43|37|37|69|44|39|42|41|42|43|44|45|50|48|48|49|50|51|52|53|54|55|66|57|59|59|60|61|62|63|64|65|66|67|68|69|71|71|0'}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#splits: ['test', 'train', 'validation']\n", "dataset['train'][0]" ] }, { "cell_type": "code", "execution_count": 4, "id": "5f44b9c0", "metadata": {}, "outputs": [], "source": [ "train = pd.DataFrame(dataset['train'])\n", "train['split'] = 'train'\n", "\n", "val = pd.DataFrame(dataset['validation'])\n", "val['split'] = 'validation'\n", "\n", "test = pd.DataFrame(dataset['test'])\n", "test['split'] = 'test'\n", "\n", "data = pd.concat([train, val, test])" ] }, { "cell_type": "code", "execution_count": 5, "id": "bfc658d6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | sentence | \n", "label | \n", "tokens | \n", "tree | \n", "split | \n", "
---|---|---|---|---|---|
0 | \n", "The Rock is destined to be the 21st Century 's... | \n", "0.694440 | \n", "The|Rock|is|destined|to|be|the|21st|Century|'s... | \n", "70|70|68|67|63|62|61|60|58|58|57|56|56|64|65|5... | \n", "train | \n", "
1 | \n", "The gorgeously elaborate continuation of `` Th... | \n", "0.833330 | \n", "The|gorgeously|elaborate|continuation|of|``|Th... | \n", "71|70|69|69|67|67|66|64|63|62|62|61|61|58|57|5... | \n", "train | \n", "
2 | \n", "Singer\\/composer Bryan Adams contributes a sle... | \n", "0.625000 | \n", "Singer\\/composer|Bryan|Adams|contributes|a|sle... | \n", "72|71|71|70|68|68|67|67|66|63|62|62|60|60|58|5... | \n", "train | \n", "
3 | \n", "You 'd think by now America would have had eno... | \n", "0.500000 | \n", "You|'d|think|by|now|America|would|have|had|eno... | \n", "36|35|34|33|33|32|30|29|27|26|25|24|23|23|22|2... | \n", "train | \n", "
4 | \n", "Yet the act is still charming here . | \n", "0.722220 | \n", "Yet|the|act|is|still|charming|here|. | \n", "15|13|13|10|9|9|11|12|10|11|12|14|14|15|0 | \n", "train | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
2205 | \n", "An imaginative comedy\\/thriller . | \n", "0.777780 | \n", "An|imaginative|comedy\\/thriller|. | \n", "7|6|5|5|6|7|0 | \n", "test | \n", "
2206 | \n", "( A ) rare , beautiful film . | \n", "0.916670 | \n", "(|A|)|rare|,|beautiful|film|. | \n", "13|12|12|11|10|9|9|15|10|11|14|13|14|15|0 | \n", "test | \n", "
2207 | \n", "( An ) hilarious romantic comedy . | \n", "0.888890 | \n", "(|An|)|hilarious|romantic|comedy|. | \n", "12|11|11|9|8|8|10|9|10|13|12|13|0 | \n", "test | \n", "
2208 | \n", "Never ( sinks ) into exploitation . | \n", "0.625000 | \n", "Never|(|sinks|)|into|exploitation|. | \n", "11|10|9|9|8|8|13|12|10|11|12|13|0 | \n", "test | \n", "
2209 | \n", "( U ) nrelentingly stupid . | \n", "0.069444 | \n", "(|U|)|nrelentingly|stupid|. | \n", "10|9|9|7|7|8|8|11|10|11|0 | \n", "test | \n", "
11855 rows × 5 columns
\n", "\n", " | sentence | \n", "label | \n", "gender | \n", "
---|---|---|---|
0 | \n", "The Rock is destined to be the 21st Century 's new `` Conan '' and that he 's going to make a splash even greater than Arnold Schwarzenegger , Jean-Claud Van Damme or Steven Segal . | \n", "0.69444 | \n", "masc | \n", "
43 | \n", "`` Auto Focus '' works as an unusual biopic and document of male swingers in the Playboy era | \n", "0.65278 | \n", "masc | \n", "
44 | \n", "If Mr. Zhang 's subject matter is , to some degree at least , quintessentially American , his approach to storytelling might be called Iranian . | \n", "0.52778 | \n", "masc | \n", "
52 | \n", "( City ) reminds us how realistically nuanced a Robert De Niro performance can be when he is not more lucratively engaged in the shameless self-caricature of ` Analyze This ' ( 1999 ) and ` Analyze That , ' promised ( or threatened ) for later this year . | \n", "0.63889 | \n", "masc | \n", "
90 | \n", "Allen shows he can outgag any of those young whippersnappers making moving pictures today . | \n", "0.76389 | \n", "masc | \n", "
98 | \n", "It celebrates the group 's playful spark of nonconformity , glancing vividly back at what Hibiscus grandly called his ` angels of light . ' | \n", "0.72222 | \n", "masc | \n", "
136 | \n", "Writer\\/director Alexander Payne ( Election ) and his co-writer Jim Taylor brilliantly employ their quirky and fearless ability to look American angst in the eye and end up laughing . | \n", "0.75000 | \n", "masc | \n", "
141 | \n", "Pacino is the best he 's been in years and Keener is marvelous . | \n", "0.88889 | \n", "masc | \n", "
146 | \n", "So purely enjoyable that you might not even notice it 's a fairly straightforward remake of Hollywood comedies such as Father of the Bride . | \n", "0.79167 | \n", "masc | \n", "
150 | \n", "Robin Williams has thankfully ditched the saccharine sentimentality of Bicentennial Man in favour of an altogether darker side . | \n", "0.63889 | \n", "masc | \n", "
153 | \n", "Hoffman 's performance is authentic to the core of his being . | \n", "0.73611 | \n", "masc | \n", "
168 | \n", "Too often , Son of the Bride becomes an exercise in trying to predict when a preordained `` big moment '' will occur and not `` if . '' | \n", "0.30556 | \n", "masc | \n", "
170 | \n", "A solid piece of journalistic work that draws a picture of a man for whom political expedience became a deadly foreign policy . | \n", "0.54167 | \n", "masc | \n", "
181 | \n", "In The Pianist , Polanski is saying what he has long wanted to say , confronting the roots of his own preoccupations and obsessions , and he allows nothing to get in the way . | \n", "0.72222 | \n", "masc | \n", "
194 | \n", "With Dirty Deeds , David Caesar has stepped into the mainstream of filmmaking with an assurance worthy of international acclaim and with every cinematic tool well under his control -- driven by a natural sense for what works on screen . | \n", "0.81944 | \n", "masc | \n", "
230 | \n", "What 's not to like about a movie with a ` children 's ' song that includes the line ` My stepdad 's not mean , he 's just adjusting ' ? | \n", "0.72222 | \n", "masc | \n", "
231 | \n", "This English-language version ... does full honor to Miyazaki 's teeming and often unsettling landscape , and to the conflicted complexity of his characters . | \n", "0.58333 | \n", "masc | \n", "
240 | \n", "In its dry and forceful way , it delivers the same message as Jiri Menzel 's Closely Watched Trains and Danis Tanovic 's No Man 's Land . | \n", "0.68056 | \n", "masc | \n", "
249 | \n", "Beresford nicely mixes in as much humor as pathos to take us on his sentimental journey of the heart . | \n", "0.62500 | \n", "masc | \n", "
255 | \n", "Visually fascinating ... an often intense character study about fathers and sons , loyalty and duty . | \n", "0.70833 | \n", "masc | \n", "
\n", " | index | \n", "sentence | \n", "label | \n", "tokens | \n", "tree | \n", "split | \n", "gender | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "8204 | \n", "As pedestrian as they come . | \n", "0.18056 | \n", "As|pedestrian|as|they|come|. | \n", "10|9|9|8|7|7|8|11|10|11|0 | \n", "train | \n", "neut | \n", "
1 | \n", "2150 | \n", "Oft-described as the antidote to American Pie-... | \n", "0.33333 | \n", "Oft-described|as|the|antidote|to|American|Pie-... | \n", "55|54|53|53|52|51|50|49|49|48|47|46|43|41|41|4... | \n", "test | \n", "neut | \n", "
2 | \n", "3960 | \n", "I have a confession to make : I did n't partic... | \n", "0.25000 | \n", "I|have|a|confession|to|make|:|I|did|n't|partic... | \n", "44|43|42|41|40|40|45|39|36|36|37|34|34|32|31|3... | \n", "train | \n", "masc | \n", "
3 | \n", "1308 | \n", "Either a fascinating study of the relationship... | \n", "0.50000 | \n", "Either|a|fascinating|study|of|the|relationship... | \n", "42|38|37|37|36|34|34|33|33|40|30|30|31|28|27|2... | \n", "train | \n", "femm | \n", "
4 | \n", "2272 | \n", "Manages to please its intended audience -- chi... | \n", "0.72222 | \n", "Manages|to|please|its|intended|audience|--|chi... | \n", "35|33|31|29|28|28|27|26|26|25|23|22|22|21|20|1... | \n", "train | \n", "neut | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
1167 | \n", "5807 | \n", "( Janey ) forgets about her other obligations ... | \n", "0.23611 | \n", "(|Janey|)|forgets|about|her|other|obligations|... | \n", "74|73|73|69|68|67|66|66|70|65|64|62|62|61|57|5... | \n", "train | \n", "femm | \n", "
1168 | \n", "7125 | \n", "It 's a frightful vanity film that , no doubt ... | \n", "0.11111 | \n", "It|'s|a|frightful|vanity|film|that|,|no|doubt|... | \n", "43|41|39|38|37|37|36|35|33|33|32|30|30|29|27|2... | \n", "train | \n", "neut | \n", "
1169 | \n", "143 | \n", "It 's a hoot and a half , and a great way for ... | \n", "0.79167 | \n", "It|'s|a|hoot|and|a|half|,|and|a|great|way|for|... | \n", "67|64|58|58|59|57|57|61|62|55|54|54|53|52|51|5... | \n", "test | \n", "masc | \n", "
1170 | \n", "4452 | \n", "Eventually , they will have a showdown , but ,... | \n", "0.18056 | \n", "Eventually|,|they|will|have|a|showdown|,|but|,... | \n", "61|60|52|51|50|49|49|53|54|55|47|47|46|44|44|4... | \n", "train | \n", "neut | \n", "
1171 | \n", "2812 | \n", "Instead , she sees it as a chance to revitaliz... | \n", "0.68056 | \n", "Instead|,|she|sees|it|as|a|chance|to|revitaliz... | \n", "41|40|39|36|36|35|34|33|32|31|30|28|28|27|26|2... | \n", "train | \n", "femm | \n", "
1172 rows × 7 columns
\n", "