{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f5e0b745", "metadata": {}, "outputs": [], "source": [ "from transformers import T5Tokenizer, T5ForConditionalGeneration\n", "from transformers import AutoModel, AutoTokenizer\n", "from transformers import MarianMTModel\n", "from transformers import XLMRobertaForSequenceClassification\n", "\n", "\n", "import os\n", "import pandas as pd\n", "from tqdm import tqdm\n", "\n", "tqdm.pandas()" ] }, { "cell_type": "code", "execution_count": 2, "id": "6e228528", "metadata": {}, "outputs": [], "source": [ "def detect_language(model, tokenizer, text):\n", " \n", " token_dict = tokenizer(text, return_tensors=\"pt\").to(\"cuda\")\n", " outputs = model(token_dict.input_ids)\n", " decoded = outputs.logits.argmax(-1).item()\n", " lang = model.config.id2label[decoded]\n", " return lang\n", "\n", "def translate(model, tokenizer, text):\n", " input_ids = tokenizer(text, return_tensors=\"pt\").input_ids.to(\"cuda\")\n", " outputs = model.generate(input_ids)\n", " decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)\n", " return decoded" ] }, { "cell_type": "code", "execution_count": 24, "id": "454ae3b6", "metadata": {}, "outputs": [ { "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", "
textlabel
INDEX
0Maybe the UN could talk to those asian and afr...1
1‘Juice (Jews) are worse that nukes.’ Caption t...1
2Foreigners on UK benefits leaps 41% in 5 years...1
3Jews cannot be patriots, since their allegianc...1
4Israel, Zionism and Jewish Supremacist control...1
.........
4998Woman are basically childlike.1
4999women should be submissive to men.1
5000Women are essentially childlike, unable to und...1
5001Women should be submissive to men.1
5002Women should not be allowed to vote, this is a...1
\n", "

5003 rows × 2 columns

\n", "
" ], "text/plain": [ " text label\n", "INDEX \n", "0 Maybe the UN could talk to those asian and afr... 1\n", "1 ‘Juice (Jews) are worse that nukes.’ Caption t... 1\n", "2 Foreigners on UK benefits leaps 41% in 5 years... 1\n", "3 Jews cannot be patriots, since their allegianc... 1\n", "4 Israel, Zionism and Jewish Supremacist control... 1\n", "... ... ...\n", "4998 Woman are basically childlike. 1\n", "4999 women should be submissive to men. 1\n", "5000 Women are essentially childlike, unable to und... 1\n", "5001 Women should be submissive to men. 1\n", "5002 Women should not be allowed to vote, this is a... 1\n", "\n", "[5003 rows x 2 columns]" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DATASET_PATH = \"../data/processed/\"\n", "\n", "df = pd.read_csv(DATASET_PATH, index_col=[0])\n", "df" ] }, { "cell_type": "code", "execution_count": 9, "id": "f2db3a80", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "0 2.0\n", "1 2.0\n", "2 4.0\n", "3 2.0\n", "4 4.0\n", " ... \n", "135551 2.0\n", "135552 2.0\n", "135553 1.0\n", "135554 2.0\n", "135555 2.0\n", "Name: status, Length: 135556, dtype: float64" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# PREPROCESSING\n", "# Need more preprocessing :\n", "# - stopwords : Name, URL\n", "\n", "# Worst 10%\n", "# df = df.loc[df.hate_speech_score > df.hate_speech_score.quantile(0.90)]\n", "\n", "# Get negative examples\n", "# n = 12785 # = number of gathered worst examples\n", "# df = df.loc[df.hate_speech_score < df.hate_speech_score.quantile(0.1)].iloc[:n]\n" ] }, { "cell_type": "markdown", "id": "5ca78b94", "metadata": {}, "source": [ "#### Language detection" ] }, { "cell_type": "code", "execution_count": 21, "id": "69fc7f94", "metadata": {}, "outputs": [], "source": [ "# Language detection model\n", "tokenizer = AutoTokenizer.from_pretrained(\"papluca/xlm-roberta-base-language-detection\")\n", "model = XLMRobertaForSequenceClassification.from_pretrained(\"papluca/xlm-roberta-base-language-detection\").to(\"cuda\")" ] }, { "cell_type": "code", "execution_count": 59, "id": "f05bbff2", "metadata": { "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|████████████████████████████████████████████████████████████████████████████████████████████| 135556/135556 [18:54<00:00, 119.45it/s]\n" ] } ], "source": [ "# Add language prediction for later filtering before applying language-dependent translation model\n", "df[\"lang\"] = df.text.progress_apply(lambda text: detect_language(model, tokenizer, text))" ] }, { "cell_type": "markdown", "id": "05d07356", "metadata": {}, "source": [ "#### Text translation\n", "\n", "- Process requires long processing time\n", "- Process should be run multiple times to complete" ] }, { "cell_type": "code", "execution_count": 19, "id": "a82a5eb3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "zsh:1: no matches found: temp/*\r\n" ] } ], "source": [ "! rm -rf temp/*" ] }, { "cell_type": "code", "execution_count": 25, "id": "3f3f1bfb", "metadata": {}, "outputs": [], "source": [ "def write_file(path, text):\n", " with open(path, \"w\") as f:\n", " f.write(text)\n", "\n", "LANGUAGE = \"en\"\n", "OUTPUT_DIR = \"../data/translated\"\n", "TEMP_DIR = \"../data/temp\"\n", "IN_MEMORY = True\n", "\n", "output_dir = os.path.join(OUTPUT_DIR, LANGUAGE)\n", "if not os.path.exists(OUTPUT_DIR):\n", " os.makedirs(output_dir)\n", "# os.mkdir(OUTPUT_DIR)\n", "if not os.path.exists(TEMP_DIR):\n", " os.mkdir(TEMP_DIR)" ] }, { "cell_type": "code", "execution_count": 7, "id": "b8122256", "metadata": {}, "outputs": [], "source": [ "# Translation model\n", "tokenizer = AutoTokenizer.from_pretrained(\"Abelll/marian-finetuned-kde4-en-to-fr\")\n", "model = MarianMTModel.from_pretrained(\"Abelll/marian-finetuned-kde4-en-to-fr\").to(\"cuda\")" ] }, { "cell_type": "code", "execution_count": 26, "id": "b9ef106d", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " 0%| | 0/5003 [00:00\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", "
textlabeltranslated
INDEX
0Maybe the UN could talk to those asian and afr...1Peut-être que l'Onu pourrait parler aux nation...
1‘Juice (Jews) are worse that nukes.’ Caption t...1« Juice (Juifs) sont pire que les nuées. « & #...
2Foreigners on UK benefits leaps 41% in 5 years...1Les étrangers au Royaume-Uni bénéficient d'un ...
3Jews cannot be patriots, since their allegianc...1Les Juifs ne peuvent pas être patriotes, car l...
4Israel, Zionism and Jewish Supremacist control...1Israël, le sionisme et le contrôle suprémacist...
............
4998Woman are basically childlike.1La femme ressemble à un enfant.
4999women should be submissive to men.1Les filles doivent être soumises aux hommes.
5000Women are essentially childlike, unable to und...1Les filles sont pour l'essentiel des filles, i...
5001Women should be submissive to men.1Les filles doivent être soumises aux hommes.
5002Women should not be allowed to vote, this is a...1Les femmes ne devraient pas être autorisées à ...
\n", "

5003 rows × 3 columns

\n", "" ], "text/plain": [ " text label \\\n", "INDEX \n", "0 Maybe the UN could talk to those asian and afr... 1 \n", "1 ‘Juice (Jews) are worse that nukes.’ Caption t... 1 \n", "2 Foreigners on UK benefits leaps 41% in 5 years... 1 \n", "3 Jews cannot be patriots, since their allegianc... 1 \n", "4 Israel, Zionism and Jewish Supremacist control... 1 \n", "... ... ... \n", "4998 Woman are basically childlike. 1 \n", "4999 women should be submissive to men. 1 \n", "5000 Women are essentially childlike, unable to und... 1 \n", "5001 Women should be submissive to men. 1 \n", "5002 Women should not be allowed to vote, this is a... 1 \n", "\n", " translated \n", "INDEX \n", "0 Peut-être que l'Onu pourrait parler aux nation... \n", "1 « Juice (Juifs) sont pire que les nuées. « & #... \n", "2 Les étrangers au Royaume-Uni bénéficient d'un ... \n", "3 Les Juifs ne peuvent pas être patriotes, car l... \n", "4 Israël, le sionisme et le contrôle suprémacist... \n", "... ... \n", "4998 La femme ressemble à un enfant. \n", "4999 Les filles doivent être soumises aux hommes. \n", "5000 Les filles sont pour l'essentiel des filles, i... \n", "5001 Les filles doivent être soumises aux hommes. \n", "5002 Les femmes ne devraient pas être autorisées à ... \n", "\n", "[5003 rows x 3 columns]" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 12, "id": "885ebb18", "metadata": {}, "outputs": [], "source": [ "df.to_csv(\"../data/ucberkeley-dlab_measuring-hate-speech_translated_positive.csv\")" ] }, { "cell_type": "code", "execution_count": 65, "id": "576a76f1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "translate English to French: for starters bend over the one in pink and kick that ass and pussy to get a taste until she's begging for a dick inside her.\n" ] }, { "data": { "text/plain": [ "\"j'ai lu cette vidéo et j'ai\"" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def translate(text):\n", " input_text = f\"translate {BASE_LANGUAGE} to French: \" + text.lower()\n", " print(input_text)\n", " input_ids = tokenizer(input_text, return_tensors=\"pt\").input_ids\n", " outputs = model.generate(input_ids)\n", " decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)\n", " return decoded\n", "\n", "translate(df.text[4])" ] }, { "cell_type": "code", "execution_count": 8, "id": "1bbc6dab", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MarianMTModel(\n", " (model): MarianModel(\n", " (shared): Embedding(59514, 512, padding_idx=59513)\n", " (encoder): MarianEncoder(\n", " (embed_tokens): Embedding(59514, 512, padding_idx=59513)\n", " (embed_positions): MarianSinusoidalPositionalEmbedding(512, 512)\n", " (layers): ModuleList(\n", " (0): MarianEncoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (activation_fn): SiLUActivation()\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (1): MarianEncoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (activation_fn): SiLUActivation()\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (2): MarianEncoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (activation_fn): SiLUActivation()\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (3): MarianEncoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (activation_fn): SiLUActivation()\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (4): MarianEncoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (activation_fn): SiLUActivation()\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (5): MarianEncoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (activation_fn): SiLUActivation()\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " )\n", " )\n", " (decoder): MarianDecoder(\n", " (embed_tokens): Embedding(59514, 512, padding_idx=59513)\n", " (embed_positions): MarianSinusoidalPositionalEmbedding(512, 512)\n", " (layers): ModuleList(\n", " (0): MarianDecoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (activation_fn): SiLUActivation()\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (encoder_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (encoder_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (1): MarianDecoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (activation_fn): SiLUActivation()\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (encoder_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (encoder_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (2): MarianDecoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (activation_fn): SiLUActivation()\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (encoder_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (encoder_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (3): MarianDecoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (activation_fn): SiLUActivation()\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (encoder_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (encoder_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (4): MarianDecoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (activation_fn): SiLUActivation()\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (encoder_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (encoder_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (5): MarianDecoderLayer(\n", " (self_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (activation_fn): SiLUActivation()\n", " (self_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (encoder_attn): MarianAttention(\n", " (k_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (v_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (q_proj): Linear(in_features=512, out_features=512, bias=True)\n", " (out_proj): Linear(in_features=512, out_features=512, bias=True)\n", " )\n", " (encoder_attn_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " (fc1): Linear(in_features=512, out_features=2048, bias=True)\n", " (fc2): Linear(in_features=2048, out_features=512, bias=True)\n", " (final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n", " )\n", " )\n", " )\n", " )\n", " (lm_head): Linear(in_features=512, out_features=59514, bias=False)\n", ")" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model" ] } ], "metadata": { "kernelspec": { "display_name": "sexism_detection", "language": "python", "name": "sexism_detection" }, "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.15" } }, "nbformat": 4, "nbformat_minor": 5 }