>::~basic_filebuf()@GLIBCXX_3.4'\n",
"collect2: error: ld returned 1 exit status\n"
]
}
],
"source": [
"# 初始化Trainer\n",
"trainer = Trainer(\n",
" model=model,\n",
" args=training_args,\n",
" train_dataset=tokenized_datasets['train'],\n",
" eval_dataset=tokenized_datasets['test'],\n",
" data_collator=data_collator\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "a9cd936a-5ea6-43e3-9848-27080f818606",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
"
\n",
" [19980/19980 21:55, Epoch 3/3]\n",
"
\n",
" \n",
" \n",
" \n",
" Step | \n",
" Training Loss | \n",
"
\n",
" \n",
" \n",
" \n",
" 500 | \n",
" 2.335700 | \n",
"
\n",
" \n",
" 1000 | \n",
" 2.184100 | \n",
"
\n",
" \n",
" 1500 | \n",
" 2.178500 | \n",
"
\n",
" \n",
" 2000 | \n",
" 2.172400 | \n",
"
\n",
" \n",
" 2500 | \n",
" 2.171400 | \n",
"
\n",
" \n",
" 3000 | \n",
" 2.171900 | \n",
"
\n",
" \n",
" 3500 | \n",
" 2.163100 | \n",
"
\n",
" \n",
" 4000 | \n",
" 2.159300 | \n",
"
\n",
" \n",
" 4500 | \n",
" 2.161000 | \n",
"
\n",
" \n",
" 5000 | \n",
" 2.160200 | \n",
"
\n",
" \n",
" 5500 | \n",
" 2.158400 | \n",
"
\n",
" \n",
" 6000 | \n",
" 2.151600 | \n",
"
\n",
" \n",
" 6500 | \n",
" 2.153700 | \n",
"
\n",
" \n",
" 7000 | \n",
" 2.129500 | \n",
"
\n",
" \n",
" 7500 | \n",
" 2.119100 | \n",
"
\n",
" \n",
" 8000 | \n",
" 2.119800 | \n",
"
\n",
" \n",
" 8500 | \n",
" 2.121600 | \n",
"
\n",
" \n",
" 9000 | \n",
" 2.122500 | \n",
"
\n",
" \n",
" 9500 | \n",
" 2.122300 | \n",
"
\n",
" \n",
" 10000 | \n",
" 2.121500 | \n",
"
\n",
" \n",
" 10500 | \n",
" 2.119500 | \n",
"
\n",
" \n",
" 11000 | \n",
" 2.123500 | \n",
"
\n",
" \n",
" 11500 | \n",
" 2.119600 | \n",
"
\n",
" \n",
" 12000 | \n",
" 2.119300 | \n",
"
\n",
" \n",
" 12500 | \n",
" 2.121800 | \n",
"
\n",
" \n",
" 13000 | \n",
" 2.123500 | \n",
"
\n",
" \n",
" 13500 | \n",
" 2.103200 | \n",
"
\n",
" \n",
" 14000 | \n",
" 2.080700 | \n",
"
\n",
" \n",
" 14500 | \n",
" 2.082100 | \n",
"
\n",
" \n",
" 15000 | \n",
" 2.082900 | \n",
"
\n",
" \n",
" 15500 | \n",
" 2.086400 | \n",
"
\n",
" \n",
" 16000 | \n",
" 2.086600 | \n",
"
\n",
" \n",
" 16500 | \n",
" 2.083800 | \n",
"
\n",
" \n",
" 17000 | \n",
" 2.085000 | \n",
"
\n",
" \n",
" 17500 | \n",
" 2.082800 | \n",
"
\n",
" \n",
" 18000 | \n",
" 2.077600 | \n",
"
\n",
" \n",
" 18500 | \n",
" 2.080300 | \n",
"
\n",
" \n",
" 19000 | \n",
" 2.086600 | \n",
"
\n",
" \n",
" 19500 | \n",
" 2.084200 | \n",
"
\n",
" \n",
"
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"TrainOutput(global_step=19980, training_loss=2.1272921145021977, metrics={'train_runtime': 1315.5944, 'train_samples_per_second': 121.485, 'train_steps_per_second': 15.187, 'total_flos': 2.08804995072e+16, 'train_loss': 2.1272921145021977, 'epoch': 3.0})"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 开始训练\n",
"trainer.train()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "315aae76-44b4-4513-8139-40ef22934873",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Saved model to: gpt_ft/final\n"
]
}
],
"source": [
"save_dir = 'gpt_ft/final'\n",
"trainer.save_model(save_dir)\n",
"print(\"Saved model to:\", save_dir)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "28d2dbbc-02ff-4120-b230-b19905a786cd",
"metadata": {},
"outputs": [],
"source": [
"ave_dir = 'gpt_ft/final'\n",
"finetuned_model = GPT2LMHeadModel.from_pretrained(save_dir, local_files_only=True)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "08987c3c-063a-4e9b-9ebb-e637b0b5bccd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"GPT2LMHeadModel(\n",
" (transformer): GPT2Model(\n",
" (wte): Embedding(90000, 768)\n",
" (wpe): Embedding(1024, 768)\n",
" (drop): Dropout(p=0.1, inplace=False)\n",
" (h): ModuleList(\n",
" (0-11): 12 x GPT2Block(\n",
" (ln_1): LayerNorm((768,), eps=1e-05, elementwise_affine=True)\n",
" (attn): GPT2SdpaAttention(\n",
" (c_attn): Conv1D(nf=2304, nx=768)\n",
" (c_proj): Conv1D(nf=768, nx=768)\n",
" (attn_dropout): Dropout(p=0.1, inplace=False)\n",
" (resid_dropout): Dropout(p=0.1, inplace=False)\n",
" )\n",
" (ln_2): LayerNorm((768,), eps=1e-05, elementwise_affine=True)\n",
" (mlp): GPT2MLP(\n",
" (c_fc): Conv1D(nf=3072, nx=768)\n",
" (c_proj): Conv1D(nf=768, nx=3072)\n",
" (act): NewGELUActivation()\n",
" (dropout): Dropout(p=0.1, inplace=False)\n",
" )\n",
" )\n",
" )\n",
" (ln_f): LayerNorm((768,), eps=1e-05, elementwise_affine=True)\n",
" )\n",
" (lm_head): Linear(in_features=768, out_features=90000, bias=False)\n",
")"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"finetuned_model"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "d75010e8-6d6a-40ef-852e-0d705adc3da8",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"input (test): Below is an instruction that describes a task. Write a response that appropriately completes the request.\n",
"\n",
"### Instruction:\n",
"Determine core promoter detection of following dna sequence, The result will be one of the following: Non-promoter, promoter.\n",
"\n",
"### Input:\n",
"CCAGGATGCGCTGACGACCCGGCTGGCAGGCGGGTCCTCGTGGGCGAGGCGAGGGAGGCGGCGAGAGAGGAGCAATAGTTTCCCACCGCTCCCTCTCAGGCGCAGGGTCTAGAGAAGCGCGAGGGGATCTAGAGAAGCCGGAGGGGAGGAAGCGCGAGTCCGCGGCCCGCCCCGTTGCGTCCCACCCACCGCGTCCCCTCCCCTCCCCTCCCGCTGCGGGAAAAGCGGCCGCGGGCGGCGGCGCCCACTGTGGGGCGGGCGGAGCGCCGCGGGAGGCGGACGAGATGCGAGCGCGGCCGC\n",
"\n",
"### Response:\n",
"\n",
"--------------------------\n",
"\n",
"model's answer: \n",
"\n",
"promoterpromoterpromo\n",
"--------------------------\n",
"\n",
"real answer: \n",
"\n",
"promoter\n"
]
}
],
"source": [
"print(\"input (test):\", input_text)\n",
"\n",
"print(\"--------------------------\\n\")\n",
"\n",
"print(\"model's answer: \\n\")\n",
"print(inference(input_text, finetuned_model, tokenizer))\n",
"\n",
"print(\"--------------------------\\n\")\n",
"print(\"real answer: \\n\")\n",
"print(data[\"test\"][0][\"output\"])"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "64365e15-510e-4abf-92f5-c78b660b37dc",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n",
"The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
"Setting `pad_token_id` to `eos_token_id`:0 for open-end generation.\n"
]
}
],
"source": [
"test_data = data[\"test\"].select(range(100))\n",
"\n",
"data_list = []\n",
"\n",
"for entry in test_data:\n",
" input_text = format_input(entry)\n",
" #print(input_text)\n",
" response_text = inference(input_text, finetuned_model, tokenizer)\n",
" #print(response_text)\n",
" data = {\n",
" \"instruction\":entry[\"instruction\"],\n",
" \"input\":entry[\"input\"],\n",
" \"output\":entry[\"output\"],\n",
" \"model_response\":response_text\n",
" }\n",
"\n",
" data_list.append(data)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "a45fb780-fc3f-401c-b6e0-6f7d0c1682de",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"\n",
"# 定义输出文件路径\n",
"output_file = 'gpt2-small3-1024.json'\n",
"\n",
"# 将 Dataset 对象导出为 JSON 文件\n",
"# test_data.to_json(output_file)\n",
"with open(output_file, \"w\") as file:\n",
" json.dump(data_list, file, indent=4) # \"indent\" for pretty-printing\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a83c8881-c763-4bba-8b85-584a6722a38e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"promoter |||||||||||| promoterpromoterpromo\n",
"Non-promoter |||||||||||| Non-promoter\n",
"Non-promoter |||||||||||| Non-promoter\n",
"presicion 0.94 same 0.49\n"
]
}
],
"source": [
"import json\n",
"\n",
"\n",
"output_file = 'gpt2-small3-1024.json'\n",
"\n",
"with open(output_file, \"r\") as file:\n",
" test_data = json.load(file)\n",
"\n",
"all_num = len(test_data)\n",
"right_sum = 0\n",
"same_sum = 0\n",
"for item in test_data:\n",
" output = item[\"output\"]\n",
" #output = \" \".join(tokenizer.tokenize(output))\n",
" model_response = item[\"model_response\"]\n",
"\n",
" print(output,\"||||||||||||\", model_response)\n",
"\n",
" if model_response == output: #same it\n",
" same_sum = same_sum + 1\n",
" \n",
" if output.find(\"Non\")==-1: # no Non\n",
" if model_response.find(output)!=-1 and model_response.find(\"Non\")==-1: #find it, but no Non\n",
" right_sum = right_sum + 1\n",
" else:\n",
" if model_response.find(output)!=-1: #find it\n",
" right_sum = right_sum + 1\n",
"\n",
"\n",
"print(\"Accuracy\", right_sum/all_num, \"same\", same_sum/all_num)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8bf88885-fb33-406e-9644-cd174a8a2f28",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}