mirror of
https://github.com/wassname/peft.git
synced 2026-09-24 13:40:15 +08:00
1179 lines
59 KiB
Plaintext
1179 lines
59 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "9ff5004e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import argparse\n",
|
|
"import os\n",
|
|
"\n",
|
|
"import torch\n",
|
|
"from torch.optim import AdamW\n",
|
|
"from torch.utils.data import DataLoader\n",
|
|
"from peft import get_peft_config,get_peft_model, get_peft_model_state_dict, set_peft_model_state_dict, PeftType, \\\n",
|
|
"PrefixTuningConfig, PromptEncoderConfig, PromptTuningConfig\n",
|
|
"\n",
|
|
"import evaluate\n",
|
|
"from datasets import load_dataset\n",
|
|
"from transformers import AutoModelForSequenceClassification, AutoTokenizer, get_linear_schedule_with_warmup, set_seed\n",
|
|
"from tqdm import tqdm\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "e32c4a9e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"batch_size = 32\n",
|
|
"model_name_or_path = \"roberta-large\"\n",
|
|
"task = \"mrpc\"\n",
|
|
"peft_type = PeftType.PROMPT_TUNING\n",
|
|
"device = \"cuda\"\n",
|
|
"num_epochs = 20"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "622fe9c8",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"peft_config = PromptTuningConfig(\n",
|
|
" task_type=\"SEQ_CLS\",\n",
|
|
" num_virtual_tokens=10\n",
|
|
")\n",
|
|
"lr = 1e-3\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "74e9efe0",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Found cached dataset glue (/home/sourab/.cache/huggingface/datasets/glue/mrpc/1.0.0/dacbe3125aa31d7f70367a07a8a9e72a5a0bfeb5fc42e75c9db75b96da6053ad)\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "ba4b9c263d024b78aed68c147f3aec63",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
" 0%| | 0/3 [00:00<?, ?it/s]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Loading cached processed dataset at /home/sourab/.cache/huggingface/datasets/glue/mrpc/1.0.0/dacbe3125aa31d7f70367a07a8a9e72a5a0bfeb5fc42e75c9db75b96da6053ad/cache-121b991f592093a4.arrow\n",
|
|
"Loading cached processed dataset at /home/sourab/.cache/huggingface/datasets/glue/mrpc/1.0.0/dacbe3125aa31d7f70367a07a8a9e72a5a0bfeb5fc42e75c9db75b96da6053ad/cache-6c55b9fb8fbb12c7.arrow\n",
|
|
"Loading cached processed dataset at /home/sourab/.cache/huggingface/datasets/glue/mrpc/1.0.0/dacbe3125aa31d7f70367a07a8a9e72a5a0bfeb5fc42e75c9db75b96da6053ad/cache-b9740d82185f93e5.arrow\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"if any(k in model_name_or_path for k in (\"gpt\", \"opt\", \"bloom\")):\n",
|
|
" padding_side = \"left\"\n",
|
|
"else:\n",
|
|
" padding_side = \"right\"\n",
|
|
" \n",
|
|
"tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, padding_side=padding_side)\n",
|
|
"if getattr(tokenizer, \"pad_token_id\") is None:\n",
|
|
" tokenizer.pad_token_id = tokenizer.eos_token_id\n",
|
|
" \n",
|
|
"datasets = load_dataset(\"glue\", task)\n",
|
|
"metric = evaluate.load(\"glue\", task)\n",
|
|
"\n",
|
|
"def tokenize_function(examples):\n",
|
|
" # max_length=None => use the model max length (it's actually the default)\n",
|
|
" outputs = tokenizer(examples[\"sentence1\"], examples[\"sentence2\"], truncation=True, max_length=None)\n",
|
|
" return outputs\n",
|
|
"\n",
|
|
"tokenized_datasets = datasets.map(\n",
|
|
" tokenize_function,\n",
|
|
" batched=True,\n",
|
|
" remove_columns=[\"idx\", \"sentence1\", \"sentence2\"],\n",
|
|
")\n",
|
|
"\n",
|
|
"# We also rename the 'label' column to 'labels' which is the expected name for labels by the models of the\n",
|
|
"# transformers library\n",
|
|
"tokenized_datasets = tokenized_datasets.rename_column(\"label\", \"labels\")\n",
|
|
"\n",
|
|
"def collate_fn(examples):\n",
|
|
" return tokenizer.pad(examples, padding=\"longest\", return_tensors=\"pt\")\n",
|
|
"\n",
|
|
"# Instantiate dataloaders.\n",
|
|
"train_dataloader = DataLoader(\n",
|
|
" tokenized_datasets[\"train\"], shuffle=True, collate_fn=collate_fn, batch_size=batch_size\n",
|
|
")\n",
|
|
"eval_dataloader = DataLoader(\n",
|
|
" tokenized_datasets[\"validation\"], shuffle=False, collate_fn=collate_fn, batch_size=batch_size\n",
|
|
")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "a3c15af0",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Some weights of the model checkpoint at roberta-large were not used when initializing RobertaForSequenceClassification: ['lm_head.decoder.weight', 'lm_head.bias', 'lm_head.layer_norm.bias', 'lm_head.dense.bias', 'lm_head.layer_norm.weight', 'lm_head.dense.weight', 'roberta.pooler.dense.weight', 'roberta.pooler.dense.bias']\n",
|
|
"- This IS expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
|
|
"- This IS NOT expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n",
|
|
"Some weights of RobertaForSequenceClassification were not initialized from the model checkpoint at roberta-large and are newly initialized: ['classifier.dense.bias', 'classifier.out_proj.weight', 'classifier.out_proj.bias', 'classifier.dense.weight']\n",
|
|
"You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"trainable params: 1061890 || all params: 355372034 || trainable%: 0.29881079499913604\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"PETModelForSequenceClassification(\n",
|
|
" (base_model): RobertaForSequenceClassification(\n",
|
|
" (roberta): RobertaModel(\n",
|
|
" (embeddings): RobertaEmbeddings(\n",
|
|
" (word_embeddings): Embedding(50265, 1024, padding_idx=1)\n",
|
|
" (position_embeddings): Embedding(514, 1024, padding_idx=1)\n",
|
|
" (token_type_embeddings): Embedding(1, 1024)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (encoder): RobertaEncoder(\n",
|
|
" (layer): ModuleList(\n",
|
|
" (0): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (1): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (2): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (3): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (4): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (5): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (6): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (7): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (8): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (9): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (10): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (11): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (12): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (13): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (14): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (15): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (16): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (17): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (18): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (19): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (20): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (21): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (22): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (23): RobertaLayer(\n",
|
|
" (attention): RobertaAttention(\n",
|
|
" (self): RobertaSelfAttention(\n",
|
|
" (query): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (key): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (value): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" (output): RobertaSelfOutput(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (intermediate): RobertaIntermediate(\n",
|
|
" (dense): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
|
" (intermediate_act_fn): GELUActivation()\n",
|
|
" )\n",
|
|
" (output): RobertaOutput(\n",
|
|
" (dense): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
|
" (LayerNorm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" )\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (classifier): RobertaClassificationHead(\n",
|
|
" (dense): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
|
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
|
" (out_proj): Linear(in_features=1024, out_features=2, bias=True)\n",
|
|
" )\n",
|
|
" )\n",
|
|
" (word_embeddings): Embedding(50265, 1024, padding_idx=1)\n",
|
|
" (prompt_encoder): PromptEmbedding(\n",
|
|
" (embedding): Embedding(10, 1024)\n",
|
|
" )\n",
|
|
")"
|
|
]
|
|
},
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"model = AutoModelForSequenceClassification.from_pretrained(model_name_or_path, return_dict=True)\n",
|
|
"model = get_peft_model(model, peft_config)\n",
|
|
"model.print_trainable_parameters()\n",
|
|
"model"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "6d3c5edb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"optimizer = AdamW(params=model.parameters(), lr=lr)\n",
|
|
"\n",
|
|
"# Instantiate scheduler\n",
|
|
"lr_scheduler = get_linear_schedule_with_warmup(\n",
|
|
" optimizer=optimizer,\n",
|
|
" num_warmup_steps=0.06*(len(train_dataloader) * num_epochs),\n",
|
|
" num_training_steps=(len(train_dataloader) * num_epochs),\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"id": "4d279225",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 0%| | 0/115 [00:00<?, ?it/s]You're using a RobertaTokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.\n",
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:29<00:00, 3.92it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.42it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 0: {'accuracy': 0.6568627450980392, 'f1': 0.7727272727272726}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 4.01it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.42it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 1: {'accuracy': 0.6691176470588235, 'f1': 0.782608695652174}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 4.01it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.45it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 2: {'accuracy': 0.6985294117647058, 'f1': 0.8188512518409425}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 4.00it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.47it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 3: {'accuracy': 0.6838235294117647, 'f1': 0.8122270742358079}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 4.00it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.39it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 4: {'accuracy': 0.7156862745098039, 'f1': 0.8263473053892216}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 4.00it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.36it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 5: {'accuracy': 0.7107843137254902, 'f1': 0.8238805970149253}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 4.00it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.33it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 6: {'accuracy': 0.7107843137254902, 'f1': 0.824404761904762}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 4.00it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.41it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 7: {'accuracy': 0.7181372549019608, 'f1': 0.8270676691729323}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.99it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.42it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 8: {'accuracy': 0.6911764705882353, 'f1': 0.81524926686217}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.99it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.37it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 9: {'accuracy': 0.7352941176470589, 'f1': 0.8241042345276873}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.98it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.43it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 10: {'accuracy': 0.7254901960784313, 'f1': 0.8276923076923076}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.98it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.43it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 11: {'accuracy': 0.7230392156862745, 'f1': 0.8300751879699249}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.99it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.31it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 12: {'accuracy': 0.7230392156862745, 'f1': 0.8295625942684767}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.98it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.38it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 13: {'accuracy': 0.7132352941176471, 'f1': 0.8251121076233183}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.99it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.39it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 14: {'accuracy': 0.7205882352941176, 'f1': 0.8267477203647416}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.98it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.41it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 15: {'accuracy': 0.7401960784313726, 'f1': 0.8354037267080745}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.97it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.42it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 16: {'accuracy': 0.7475490196078431, 'f1': 0.8377952755905512}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.99it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.34it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 17: {'accuracy': 0.75, 'f1': 0.8401253918495298}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.98it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.41it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 18: {'accuracy': 0.7475490196078431, 'f1': 0.8403100775193798}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100%|█████████████████████████████████████████████████████████████| 115/115 [00:28<00:00, 3.98it/s]\n",
|
|
"100%|███████████████████████████████████████████████████████████████| 13/13 [00:01<00:00, 7.37it/s]"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"epoch 19: {'accuracy': 0.7377450980392157, 'f1': 0.8356374807987711}\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"model.to(device)\n",
|
|
"for epoch in range(num_epochs):\n",
|
|
" model.train()\n",
|
|
" for step, batch in enumerate(tqdm(train_dataloader)):\n",
|
|
" batch.to(device)\n",
|
|
" outputs = model(**batch)\n",
|
|
" loss = outputs.loss\n",
|
|
" loss.backward()\n",
|
|
" optimizer.step()\n",
|
|
" lr_scheduler.step()\n",
|
|
" optimizer.zero_grad()\n",
|
|
"\n",
|
|
" model.eval()\n",
|
|
" for step, batch in enumerate(tqdm(eval_dataloader)):\n",
|
|
" batch.to(device)\n",
|
|
" with torch.no_grad():\n",
|
|
" outputs = model(**batch)\n",
|
|
" predictions = outputs.logits.argmax(dim=-1)\n",
|
|
" predictions, references = predictions, batch[\"labels\"]\n",
|
|
" metric.add_batch(\n",
|
|
" predictions=predictions,\n",
|
|
" references=references,\n",
|
|
" )\n",
|
|
"\n",
|
|
" eval_metric = metric.compute()\n",
|
|
" print(f\"epoch {epoch}:\", eval_metric)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e839e449",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "0bf79cb5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"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.10.5 (v3.10.5:f377153967, Jun 6 2022, 12:36:10) [Clang 13.0.0 (clang-1300.0.29.30)]"
|
|
},
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|