{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Explicitly passing a `revision` is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.\n",
      "Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.\n",
      "Overriding torch_dtype=None with `torch_dtype=torch.float16` due to requirements of `bitsandbytes` to enable model loading in mixed int8. Either pass torch_dtype=torch.float16 or don't pass this argument at all to remove this warning.\n",
      "/root/miniconda3/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:136: UserWarning: /root/miniconda3 did not contain libcudart.so as expected! Searching further paths...\n",
      "  warn(msg)\n",
      "/root/miniconda3/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:136: UserWarning: WARNING: The following directories listed in your path were found to be non-existent: {PosixPath('Asia/Shanghai')}\n",
      "  warn(msg)\n",
      "/root/miniconda3/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:136: UserWarning: WARNING: The following directories listed in your path were found to be non-existent: {PosixPath('vs/workbench/api/node/extensionHostProcess')}\n",
      "  warn(msg)\n",
      "/root/miniconda3/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:136: UserWarning: WARNING: The following directories listed in your path were found to be non-existent: {PosixPath('//matplotlib_inline.backend_inline'), PosixPath('module')}\n",
      "  warn(msg)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===================================BUG REPORT===================================\n",
      "Welcome to bitsandbytes. For bug reports, please submit your error trace to: https://github.com/TimDettmers/bitsandbytes/issues\n",
      "================================================================================\n",
      "CUDA_SETUP: WARNING! libcudart.so not found in any environmental path. Searching /usr/local/cuda/lib64...\n",
      "CUDA SETUP: CUDA runtime path found: /usr/local/cuda/lib64/libcudart.so\n",
      "CUDA SETUP: Highest compute capability among GPUs detected: 8.6\n",
      "CUDA SETUP: Detected CUDA version 118\n",
      "CUDA SETUP: Loading binary /root/miniconda3/lib/python3.8/site-packages/bitsandbytes/libbitsandbytes_cuda118.so...\n"
     ]
    },
    {
     "data": {
      "application/json": {
       "ascii": false,
       "bar_format": null,
       "colour": null,
       "elapsed": 0.00835871696472168,
       "initial": 0,
       "n": 0,
       "ncols": null,
       "nrows": null,
       "postfix": null,
       "prefix": "Loading checkpoint shards",
       "rate": null,
       "total": 8,
       "unit": "it",
       "unit_divisor": 1000,
       "unit_scale": false
      },
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5712be31cc7443ee93eb6b7ff7082f72",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Loading checkpoint shards:   0%|          | 0/8 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from transformers import AutoModel\n",
    "import torch\n",
    "\n",
    "model_path = \"/root/.cache/huggingface/hub/models--THUDM--chatglm-6b/snapshots/658202d88ac4bb782b99e99ac3adff58b4d0b813\"\n",
    "model = AutoModel.from_pretrained(model_path, trust_remote_code=True, load_in_8bit=True, device_map='auto')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.\n"
     ]
    }
   ],
   "source": [
    "from transformers import AutoTokenizer\n",
    "tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from peft import PeftModel\n",
    "peft_path = \"/root/autodl-tmp/output\"\n",
    "model = PeftModel.from_pretrained(model, peft_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "instructions = json.load(open(\"/root/FinGPT-ChatGLM-Fineturning/data/title/dataset_title_test.json\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>input</th>\n",
       "      <th>output</th>\n",
       "      <th>context</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         instruction   \n",
       "0  What is the sentiment of this news?\\nAnswer:{v...  \\\n",
       "1  What is the sentiment of this news?\\nAnswer:{v...   \n",
       "\n",
       "                                               input   output   \n",
       "0  今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...  neutral  \\\n",
       "1  今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....  neutral   \n",
       "\n",
       "                                             context   target  \n",
       "0  Instruction: What is the sentiment of this new...  neutral  \n",
       "1  Instruction: What is the sentiment of this new...  neutral  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "instructions = pd.DataFrame(instructions)\n",
    "instructions.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "from cover_alpaca2jsonl import format_example\n",
    "instructions[[\"context\",\"target\"]] = instructions.apply(format_example, axis = 1, result_type=\"expand\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>input</th>\n",
       "      <th>output</th>\n",
       "      <th>context</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         instruction   \n",
       "0  What is the sentiment of this news?\\nAnswer:{v...  \\\n",
       "1  What is the sentiment of this news?\\nAnswer:{v...   \n",
       "\n",
       "                                               input   output   \n",
       "0  今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...  neutral  \\\n",
       "1  今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....  neutral   \n",
       "\n",
       "                                             context   target  \n",
       "0  Instruction: What is the sentiment of this new...  neutral  \n",
       "1  Instruction: What is the sentiment of this new...  neutral  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# input_text_list = []\n",
    "# out_list = []\n",
    "\n",
    "# for i in range(total_steps):\n",
    "#     tmp_context = context_list[i* batch_size:(i+1)* batch_size]\n",
    "    \n",
    "#     tmp_input_text = \n",
    "#     out = model.generate(\n",
    "#         input_ids=tmp_input_text,\n",
    "#         max_length=150,\n",
    "#         do_sample=False,\n",
    "#         temperature=0\n",
    "#     )\n",
    "#     out_text = tokenizer.decode(out[0])\n",
    "#     input_text_list.append(tmp_input_text)\n",
    "#     out_list.append(out_text)\n",
    "#     break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>input</th>\n",
       "      <th>output</th>\n",
       "      <th>context</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-05。\\n新闻标题为：\"振华科技本周深股通持股市值增加4293...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-06。\\n新闻标题为：\"振华科技本周融资净买入131.06万元...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-12。\\n新闻标题为：\"10家国防军工行业公司发布一季度业绩预...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1779</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2023-03-26。\\n新闻标题为：\"中国建筑本周沪股通持股市值增加3.74...</td>\n",
       "      <td>very positive</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>very positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1780</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2023-03-27。\\n新闻标题为：\"中国建筑本周融资净买入2.24亿元，两...</td>\n",
       "      <td>very positive</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>very positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1781</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2023-03-28。\\n新闻标题为：\"中国建筑03月27日获沪股通增持127...</td>\n",
       "      <td>very positive</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>very positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1782</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2023-03-29。\\n新闻标题为：\"中国建筑03月28日被沪股通减持231...</td>\n",
       "      <td>very positive</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>very positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1783</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2023-03-30。\\n新闻标题为：\"中国建筑：连续3日融资净偿还累计292...</td>\n",
       "      <td>very positive</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>very positive</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1784 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            instruction   \n",
       "0     What is the sentiment of this news?\\nAnswer:{v...  \\\n",
       "1     What is the sentiment of this news?\\nAnswer:{v...   \n",
       "2     What is the sentiment of this news?\\nAnswer:{v...   \n",
       "3     What is the sentiment of this news?\\nAnswer:{v...   \n",
       "4     What is the sentiment of this news?\\nAnswer:{v...   \n",
       "...                                                 ...   \n",
       "1779  What is the sentiment of this news?\\nAnswer:{v...   \n",
       "1780  What is the sentiment of this news?\\nAnswer:{v...   \n",
       "1781  What is the sentiment of this news?\\nAnswer:{v...   \n",
       "1782  What is the sentiment of this news?\\nAnswer:{v...   \n",
       "1783  What is the sentiment of this news?\\nAnswer:{v...   \n",
       "\n",
       "                                                  input         output   \n",
       "0     今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...        neutral  \\\n",
       "1     今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....        neutral   \n",
       "2     今天的日期为：2022-04-05。\\n新闻标题为：\"振华科技本周深股通持股市值增加4293...        neutral   \n",
       "3     今天的日期为：2022-04-06。\\n新闻标题为：\"振华科技本周融资净买入131.06万元...        neutral   \n",
       "4     今天的日期为：2022-04-12。\\n新闻标题为：\"10家国防军工行业公司发布一季度业绩预...        neutral   \n",
       "...                                                 ...            ...   \n",
       "1779  今天的日期为：2023-03-26。\\n新闻标题为：\"中国建筑本周沪股通持股市值增加3.74...  very positive   \n",
       "1780  今天的日期为：2023-03-27。\\n新闻标题为：\"中国建筑本周融资净买入2.24亿元，两...  very positive   \n",
       "1781  今天的日期为：2023-03-28。\\n新闻标题为：\"中国建筑03月27日获沪股通增持127...  very positive   \n",
       "1782  今天的日期为：2023-03-29。\\n新闻标题为：\"中国建筑03月28日被沪股通减持231...  very positive   \n",
       "1783  今天的日期为：2023-03-30。\\n新闻标题为：\"中国建筑：连续3日融资净偿还累计292...  very positive   \n",
       "\n",
       "                                                context         target  \n",
       "0     Instruction: What is the sentiment of this new...        neutral  \n",
       "1     Instruction: What is the sentiment of this new...        neutral  \n",
       "2     Instruction: What is the sentiment of this new...        neutral  \n",
       "3     Instruction: What is the sentiment of this new...        neutral  \n",
       "4     Instruction: What is the sentiment of this new...        neutral  \n",
       "...                                                 ...            ...  \n",
       "1779  Instruction: What is the sentiment of this new...  very positive  \n",
       "1780  Instruction: What is the sentiment of this new...  very positive  \n",
       "1781  Instruction: What is the sentiment of this new...  very positive  \n",
       "1782  Instruction: What is the sentiment of this new...  very positive  \n",
       "1783  Instruction: What is the sentiment of this new...  very positive  \n",
       "\n",
       "[1784 rows x 5 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Instruction: What is the sentiment of this news?\\nAnswer:{very negative/negative/neutral/positive/very positive}\\nInput: 今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，融资余额2.71亿元（03-31）\\n振华科技03月31日被深股通减持19.49万股\"\\nAnswer: '"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions.context[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_67452/2848644850.py:3: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at ../torch/csrc/utils/tensor_new.cpp:245.)\n",
      "  input_ids = torch.LongTensor([ids])\n"
     ]
    }
   ],
   "source": [
    "def encode(x):\n",
    "    ids = tokenizer.encode(x, max_length= 1024, return_tensors=\"np\", padding = \"max_length\")\n",
    "    input_ids = torch.LongTensor([ids])\n",
    "    return input_ids\n",
    "instructions[\"input_text\"] = instructions.context.apply(encode)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# instructions.to_pickle(\"instructions.pkl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import pandas as pd\n",
    "# instructions = pd.read_pickle(\"instructions.pkl\")[:1000]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1784, 6)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "111"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "batch_size = 16\n",
    "total_steps = instructions.shape[0]//batch_size\n",
    "total_steps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "input_text_list = instructions.input_text.tolist()\n",
    "torch.cuda.empty_cache()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  0%|          | 0/112 [00:00<?, ?it/s]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "/root/miniconda3/lib/python3.8/site-packages/transformers/generation/utils.py:1374: UserWarning: You are calling .generate() with the `input_ids` being on a device type different than your model's device. `input_ids` is on cpu, whereas the model is on cuda. You may experience unexpected behaviors or slower generation. Please make sure that you have put `input_ids` to the correct device by calling for example input_ids = input_ids.to('cuda') before running `.generate()`.\n",
      "  warnings.warn(\n",
      "The dtype of attention mask (torch.int64) is not bool\n",
      "  1%|          | 1/112 [00:08<15:35,  8.43s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "  2%|▏         | 2/112 [00:15<14:20,  7.82s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "  3%|▎         | 3/112 [00:23<13:52,  7.64s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "  4%|▎         | 4/112 [00:30<13:35,  7.55s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "  4%|▍         | 5/112 [00:38<13:21,  7.49s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "  5%|▌         | 6/112 [00:45<13:09,  7.45s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "  6%|▋         | 7/112 [00:52<13:00,  7.43s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "  7%|▋         | 8/112 [01:00<12:50,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "  8%|▊         | 9/112 [01:07<12:42,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "  9%|▉         | 10/112 [01:14<12:34,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 10%|▉         | 11/112 [01:22<12:25,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 11%|█         | 12/112 [01:29<12:17,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 12%|█▏        | 13/112 [01:37<12:10,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 12%|█▎        | 14/112 [01:44<12:05,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 13%|█▎        | 15/112 [01:51<11:59,  7.42s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 14%|█▍        | 16/112 [01:59<11:51,  7.42s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 15%|█▌        | 17/112 [02:06<11:43,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 16%|█▌        | 18/112 [02:14<11:34,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 17%|█▋        | 19/112 [02:21<11:27,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 18%|█▊        | 20/112 [02:28<11:18,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 19%|█▉        | 21/112 [02:36<11:13,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 20%|█▉        | 22/112 [02:43<11:05,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 21%|██        | 23/112 [02:51<10:58,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 21%|██▏       | 24/112 [02:58<10:52,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 22%|██▏       | 25/112 [03:05<10:44,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 23%|██▎       | 26/112 [03:13<10:35,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 24%|██▍       | 27/112 [03:20<10:28,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 25%|██▌       | 28/112 [03:28<10:20,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 26%|██▌       | 29/112 [03:35<10:13,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 27%|██▋       | 30/112 [03:42<10:05,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 28%|██▊       | 31/112 [03:50<09:58,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 29%|██▊       | 32/112 [03:57<09:51,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 29%|██▉       | 33/112 [04:04<09:43,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 30%|███       | 34/112 [04:12<09:35,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 31%|███▏      | 35/112 [04:19<09:27,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 32%|███▏      | 36/112 [04:27<09:20,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 33%|███▎      | 37/112 [04:34<09:12,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 34%|███▍      | 38/112 [04:41<09:06,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 35%|███▍      | 39/112 [04:49<08:57,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 36%|███▌      | 40/112 [04:56<08:51,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 37%|███▋      | 41/112 [05:04<08:46,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 38%|███▊      | 42/112 [05:11<08:38,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 38%|███▊      | 43/112 [05:18<08:30,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 39%|███▉      | 44/112 [05:26<08:22,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 40%|████      | 45/112 [05:33<08:16,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 41%|████      | 46/112 [05:41<08:09,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 42%|████▏     | 47/112 [05:48<08:01,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 43%|████▎     | 48/112 [05:55<07:53,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 44%|████▍     | 49/112 [06:03<07:46,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 45%|████▍     | 50/112 [06:10<07:38,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 46%|████▌     | 51/112 [06:18<07:31,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 46%|████▋     | 52/112 [06:25<07:26,  7.44s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 47%|████▋     | 53/112 [06:33<07:21,  7.48s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 48%|████▊     | 54/112 [06:40<07:11,  7.45s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 49%|████▉     | 55/112 [06:47<07:03,  7.42s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 50%|█████     | 56/112 [06:55<06:54,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 51%|█████     | 57/112 [07:02<06:46,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 52%|█████▏    | 58/112 [07:10<06:39,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 53%|█████▎    | 59/112 [07:17<06:32,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 54%|█████▎    | 60/112 [07:24<06:24,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 54%|█████▍    | 61/112 [07:32<06:17,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 55%|█████▌    | 62/112 [07:39<06:10,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 56%|█████▋    | 63/112 [07:47<06:02,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 57%|█████▋    | 64/112 [07:54<05:54,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 58%|█████▊    | 65/112 [08:01<05:46,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 59%|█████▉    | 66/112 [08:09<05:39,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 60%|█████▉    | 67/112 [08:16<05:32,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 61%|██████    | 68/112 [08:23<05:25,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 62%|██████▏   | 69/112 [08:31<05:18,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 62%|██████▎   | 70/112 [08:38<05:12,  7.43s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 63%|██████▎   | 71/112 [08:46<05:04,  7.42s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 64%|██████▍   | 72/112 [08:53<04:56,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 65%|██████▌   | 73/112 [09:01<04:48,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 66%|██████▌   | 74/112 [09:08<04:41,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 67%|██████▋   | 75/112 [09:15<04:33,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 68%|██████▊   | 76/112 [09:23<04:26,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 69%|██████▉   | 77/112 [09:30<04:18,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 70%|██████▉   | 78/112 [09:37<04:10,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 71%|███████   | 79/112 [09:45<04:03,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 71%|███████▏  | 80/112 [09:52<03:56,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 72%|███████▏  | 81/112 [10:00<03:48,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 73%|███████▎  | 82/112 [10:07<03:41,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 74%|███████▍  | 83/112 [10:15<03:36,  7.46s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 75%|███████▌  | 84/112 [10:22<03:28,  7.43s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 76%|███████▌  | 85/112 [10:29<03:20,  7.42s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 77%|███████▋  | 86/112 [10:37<03:12,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 78%|███████▊  | 87/112 [10:44<03:05,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 79%|███████▊  | 88/112 [10:52<02:57,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 79%|███████▉  | 89/112 [10:59<02:50,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 80%|████████  | 90/112 [11:06<02:42,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 81%|████████▏ | 91/112 [11:14<02:35,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 82%|████████▏ | 92/112 [11:21<02:27,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 83%|████████▎ | 93/112 [11:28<02:20,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 84%|████████▍ | 94/112 [11:36<02:12,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 85%|████████▍ | 95/112 [11:43<02:05,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 86%|████████▌ | 96/112 [11:51<01:58,  7.41s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 87%|████████▋ | 97/112 [11:58<01:50,  7.40s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 88%|████████▊ | 98/112 [12:05<01:43,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 88%|████████▊ | 99/112 [12:13<01:36,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 89%|████████▉ | 100/112 [12:20<01:28,  7.39s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 90%|█████████ | 101/112 [12:28<01:21,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 91%|█████████ | 102/112 [12:35<01:13,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 92%|█████████▏| 103/112 [12:42<01:06,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 93%|█████████▎| 104/112 [12:50<00:58,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 94%|█████████▍| 105/112 [12:57<00:51,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 95%|█████████▍| 106/112 [13:04<00:44,  7.38s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 96%|█████████▌| 107/112 [13:12<00:36,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 96%|█████████▋| 108/112 [13:19<00:29,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 97%|█████████▋| 109/112 [13:26<00:22,  7.36s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 98%|█████████▊| 110/112 [13:34<00:14,  7.36s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      " 99%|█████████▉| 111/112 [13:41<00:07,  7.37s/it]Input length of input_ids is 1024, but `max_length` is set to 128. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.\n",
      "100%|██████████| 112/112 [13:45<00:00,  7.37s/it]\n"
     ]
    }
   ],
   "source": [
    "from tqdm import tqdm\n",
    "out_list = []\n",
    "out_text_list = []\n",
    "\n",
    "for i in tqdm(range(total_steps+1)):\n",
    "    tmp_input_text = input_text_list[i* batch_size:(i+1)* batch_size]\n",
    "    tmp_input_text = [i[0] for i in tmp_input_text]\n",
    "    tmp_input_text = torch.concat(tmp_input_text, dim = 0)\n",
    "    with torch.no_grad():\n",
    "        out = model.generate(\n",
    "            input_ids=tmp_input_text,\n",
    "            max_length=128,\n",
    "            do_sample=False,\n",
    "            temperature=0\n",
    "        )\n",
    "    out = [tokenizer.decode(o) for o in out]\n",
    "    out_text = [o.split(\"Answer: \")[1] for o in out]\n",
    "    out_list += out\n",
    "    out_text_list += out_text\n",
    "    torch.cuda.empty_cache()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import accuracy_score,f1_score,roc_auc_score,recall_score,precision_score, auc\n",
    "import pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1784"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(out_text_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_text_list_new =  [o.split(\"Answer: \")[1:] for o in out_list]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Instruction: What is the sentiment of this news?\\nAnswer:{very negative/negative/neutral/positive/very positive}\\nInput: 今天的日期为:2022-04-12。\\n新闻标题为:\"10家国防军工行业公司发布一季度业绩预告 近八成预喜\\n国盛证券维持振华科技买入评级 预计2021年净利润同比增长146.54%\\n振华科技4月12日盘中涨幅达5%\\n振华科技4月12日快速上涨\\n振华科技:连续6日融资净偿还累计1437.84万元(04-11)\\n振华科技04月11日获深股通增持5.34万股\\n振华科技发布首季预增公告 净利润同比增长122.16%~155.40%\\n振华科技:预计22年一季度归母净利润同比增长122.16%至155.40%\\n预增!振华科技:预计2022年第一季度净利润为5.48亿元~6.3亿元 同比增长122.16%~155.4%\"\\nAnswer: The'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "out_list[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_text_list = [\" \".join(o) for o in out_text_list]\n",
    "# out_text_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['replace', 'positive', 'positive']"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [\"replace\", \"Positive\", \"positive\"]\n",
    "a = [aa.replace(\"Positive\", \"positive\") for aa in a]\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'The',\n",
       " 'The',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'positive',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'negative',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'negative',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'negative',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'negative',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'positive',\n",
       " 'neutral',\n",
       " 'The',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " 'neutral',\n",
       " ...]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "out_text_list = [o.replace(\"Positive\", \"positive\") for o in out_text_list]\n",
    "out_text_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "root_path = \"/root/autodl-tmp/results\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1784, 8)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions = pd.read_csv(f\"{root_path}/results_new.csv\")\n",
    "instructions.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1784, 8)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ori_instructions = pd.read_csv(f\"{root_path}/results.csv\")\n",
    "ori_instructions.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "instructions_ori =pd.read_csv(\"/root/FinGPT-ChatGLM-Fineturning/data/title/dataset_title_test.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1784, 5)"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions_ori.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>input</th>\n",
       "      <th>output</th>\n",
       "      <th>context</th>\n",
       "      <th>target</th>\n",
       "      <th>input_text</th>\n",
       "      <th>new_pred_out</th>\n",
       "      <th>new_pred</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>tensor([[[     3,      3,      3,  ...,     12...</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>tensor([[[     3,      3,      3,  ...,     12...</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         instruction   \n",
       "0  What is the sentiment of this news?\\nAnswer:{v...  \\\n",
       "1  What is the sentiment of this news?\\nAnswer:{v...   \n",
       "\n",
       "                                               input   output   \n",
       "0  今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...  neutral  \\\n",
       "1  今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....  neutral   \n",
       "\n",
       "                                             context   target   \n",
       "0  Instruction: What is the sentiment of this new...  neutral  \\\n",
       "1  Instruction: What is the sentiment of this new...  neutral   \n",
       "\n",
       "                                          input_text   \n",
       "0  tensor([[[     3,      3,      3,  ...,     12...  \\\n",
       "1  tensor([[[     3,      3,      3,  ...,     12...   \n",
       "\n",
       "                                        new_pred_out new_pred  \n",
       "0  Instruction: What is the sentiment of this new...  neutral  \n",
       "1  Instruction: What is the sentiment of this new...  neutral  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000733.sz</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000733.sz</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000733.sz</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000733.sz</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000733.sz</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1779</th>\n",
       "      <td>601668.sh</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1780</th>\n",
       "      <td>601668.sh</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1781</th>\n",
       "      <td>601668.sh</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1782</th>\n",
       "      <td>601668.sh</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1783</th>\n",
       "      <td>601668.sh</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1784 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      code_name\n",
       "0     000733.sz\n",
       "1     000733.sz\n",
       "2     000733.sz\n",
       "3     000733.sz\n",
       "4     000733.sz\n",
       "...         ...\n",
       "1779  601668.sh\n",
       "1780  601668.sh\n",
       "1781  601668.sh\n",
       "1782  601668.sh\n",
       "1783  601668.sh\n",
       "\n",
       "[1784 rows x 1 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions_ori[[\"code_name\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1784, 8)"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1784, 9)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions = pd.concat([instructions, instructions_ori[[\"code_name\"]]],axis = 1)\n",
    "instructions.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1784, 9)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ori_instructions = pd.concat([ori_instructions, instructions_ori[[\"code_name\"]]],axis = 1)\n",
    "ori_instructions.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "instructions.to_csv(f\"{root_path}/results_new.csv\")\n",
    "ori_instructions.to_csv(f\"{root_path}/results.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.48094170403587444"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accuracy_score(instructions[\"target\"], instructions['new_pred'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4501121076233184"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accuracy_score(ori_instructions[\"target\"], ori_instructions['new_pred'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(908, 8)"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions_no_neutral = instructions[instructions.target != \"neutral\"]\n",
    "instructions_no_neutral.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(908, 8)"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions_no_neutral_ori = ori_instructions[ori_instructions.target != \"neutral\"]\n",
    "instructions_no_neutral_ori.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.019927536231884053"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f1_score(instructions_no_neutral[\"target\"], instructions_no_neutral[\"new_pred\"], average = \"macro\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.01221001221001221"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f1_score(instructions_no_neutral_ori[\"target\"], instructions_no_neutral_ori[\"new_pred\"], average = \"macro\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f1_score(instructions_no_neutral[\"target\"], instructions_no_neutral[\"new_pred\"], average = \"macro\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.12814725954095882"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f1_score(instructions[\"target\"], out_text_list, average = \"macro\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0914057621978414"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f1_score(ori_instructions[\"target\"], ori_instructions[\"new_pred\"], average = \"macro\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "000733.sz (204, 9) 0.9607843137254902\n",
      "300014.sz (295, 9) 0.0\n",
      "600188.sh (125, 9) 0.136\n",
      "600196.sh (196, 9) 0.025510204081632654\n",
      "600219.sh (210, 9) 0.9714285714285714\n",
      "600233.sh (264, 9) 0.9318181818181818\n",
      "600989.sh (198, 9) 0.9595959595959596\n",
      "601668.sh (292, 9) 0.0\n"
     ]
    }
   ],
   "source": [
    "for id, tmp in instructions.groupby(\"code_name\"):\n",
    "    print(id, end = \" \")\n",
    "    print(tmp.shape, end = \" \")\n",
    "    print(accuracy_score(tmp[\"target\"], tmp['new_pred']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "000733.sz (204, 9) 0.8970588235294118\n",
      "300014.sz (295, 9) 0.0\n",
      "600188.sh (125, 9) 0.08\n",
      "600196.sh (196, 9) 0.025510204081632654\n",
      "600219.sh (210, 9) 0.9142857142857143\n",
      "600233.sh (264, 9) 0.8825757575757576\n",
      "600989.sh (198, 9) 0.9090909090909091\n",
      "601668.sh (292, 9) 0.0\n"
     ]
    }
   ],
   "source": [
    "for id, tmp in ori_instructions.groupby(\"code_name\"):\n",
    "    print(id, end = \" \")\n",
    "    print(tmp.shape, end = \" \")\n",
    "    print(accuracy_score(tmp[\"target\"], tmp['new_pred']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_text_path = f\"{root_path}/out_text_list_new.pkl\"\n",
    "with open(out_text_path, \"wb\") as f:\n",
    "    pickle.dump(out_text_list, f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_path = f\"{root_path}/out_list_new.pkl\"\n",
    "with open(out_path, \"wb\") as f:\n",
    "    pickle.dump(out_list, f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "instructions[\"new_pred_out\"] = out_list\n",
    "instructions[\"new_pred\"] = out_text_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>input</th>\n",
       "      <th>output</th>\n",
       "      <th>context</th>\n",
       "      <th>target</th>\n",
       "      <th>input_text</th>\n",
       "      <th>new_pred_out</th>\n",
       "      <th>new_pred</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>[[[tensor(3), tensor(3), tensor(3), tensor(3),...</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>What is the sentiment of this news?\\nAnswer:{v...</td>\n",
       "      <td>今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....</td>\n",
       "      <td>neutral</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "      <td>[[[tensor(3), tensor(3), tensor(3), tensor(3),...</td>\n",
       "      <td>Instruction: What is the sentiment of this new...</td>\n",
       "      <td>neutral</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         instruction   \n",
       "0  What is the sentiment of this news?\\nAnswer:{v...  \\\n",
       "1  What is the sentiment of this news?\\nAnswer:{v...   \n",
       "\n",
       "                                               input   output   \n",
       "0  今天的日期为：2022-04-01。\\n新闻标题为：\"振华科技：融资净偿还402.57万元，...  neutral  \\\n",
       "1  今天的日期为：2022-04-02。\\n新闻标题为：\"振华科技04月01日获深股通增持12....  neutral   \n",
       "\n",
       "                                             context   target   \n",
       "0  Instruction: What is the sentiment of this new...  neutral  \\\n",
       "1  Instruction: What is the sentiment of this new...  neutral   \n",
       "\n",
       "                                          input_text   \n",
       "0  [[[tensor(3), tensor(3), tensor(3), tensor(3),...  \\\n",
       "1  [[[tensor(3), tensor(3), tensor(3), tensor(3),...   \n",
       "\n",
       "                                        new_pred_out new_pred  \n",
       "0  Instruction: What is the sentiment of this new...  neutral  \n",
       "1  Instruction: What is the sentiment of this new...  neutral  "
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instructions.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "result_path = f\"{root_path}/results_new.csv\"\n",
    "instructions.to_csv(result_path,index = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1784, 8)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ori_instructions = pd.read_csv(f\"{root_path}/results.csv\")\n",
    "ori_instructions.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4501121076233184"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accuracy_score(ori_instructions[\"target\"], ori_instructions[\"new_pred\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "instructions_ori = json.load(open(\"/root/FinGPT-ChatGLM-Fineturning/data/title/dataset_title_test.json\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/root/miniconda3/lib/python3.8/site-packages/transformers/generation/utils.py:1374: UserWarning: You are calling .generate() with the `input_ids` being on a device type different than your model's device. `input_ids` is on cpu, whereas the model is on cuda. You may experience unexpected behaviors or slower generation. Please make sure that you have put `input_ids` to the correct device by calling for example input_ids = input_ids.to('cuda') before running `.generate()`.\n",
      "  warnings.warn(\n",
      "The dtype of attention mask (torch.int64) is not bool\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Instruction: What is the sentiment of this news?\n",
      "Answer:{very negative/negative/neutral/positive/very positive}\n",
      "Input: 今天的日期为:2023-03-31。\n",
      "新闻标题为:\"平安银行:融资净买入1084.02万元,融资余额39.17亿元(03-30)\"。\n",
      "Answer: neutral\n",
      "### 1.Answer:\n",
      " neutral \n",
      "\n",
      "\n",
      "Instruction: What is the sentiment of this news?\n",
      "Answer:{very negative/negative/neutral/positive/very positive}\n",
      "Input: 今天的日期为:2023-03-31。\n",
      "新闻标题为:\"平安银行03月30日获深股通增持766.05万股\"。\n",
      "Answer: neutral\n",
      "### 2.Answer:\n",
      " neutral \n",
      "\n",
      "\n",
      "Instruction: What is the sentiment of this news?\n",
      "Answer:{very negative/negative/neutral/positive/very positive}\n",
      "Input: 今天的日期为:2023-03-30。\n",
      "新闻标题为:\"平安银行:融资净买入719.35万元,融资余额39.07亿元(03-29)\"。\n",
      "Answer: neutral\n",
      "### 3.Answer:\n",
      " neutral \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "answers = []\n",
    "from cover_alpaca2jsonl import format_example\n",
    "\n",
    "\n",
    "with torch.no_grad():\n",
    "    for idx, item in enumerate(instructions_ori[:3]):\n",
    "        feature = format_example(item)\n",
    "        input_text = feature['context']\n",
    "        ids = tokenizer.encode(input_text)\n",
    "        input_ids = torch.LongTensor([ids])\n",
    "        out = model.generate(\n",
    "            input_ids=input_ids,\n",
    "            max_length=150,\n",
    "            do_sample=False,\n",
    "            temperature=0\n",
    "        )\n",
    "        out_text = tokenizer.decode(out[0])\n",
    "        answer = out_text.replace(input_text, \"\").replace(\"\\nEND\", \"\").strip()\n",
    "        item['infer_answer'] = answer\n",
    "        print(out_text)\n",
    "        print(f\"### {idx+1}.Answer:\\n\", item.get('output'), '\\n\\n')\n",
    "        answers.append({'index': idx, **item})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[ 37010,     12,    526,    107,    100,  16334,    101,    121,   1066,\n",
       "             31,      4,  13049,     12,     50,   8167,   1451,     26,   6595,\n",
       "             26,  16807,     26,   4792,     26,   8167,    862,     39,      4,\n",
       "           3430,     12,  87544,  67913,  63834,     12,     10,      8,     10,\n",
       "             13,     11,      8,     13,     11,     13,      8,  63823,      4,\n",
       "          65252,  69259,  63834,     90,  67142,  64490,     12,  66526,  65526,\n",
       "          67129,     25,      9,     18,      7,     13,     15,  64352,      6,\n",
       "          66526,  74661,     13,     18,      7,      8,     25,  64402,     20,\n",
       "              8,     13,     11,     10,     18,     14, 125656,      4,  13049,\n",
       "             12, 130001, 130004]])"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_ids"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "25273a2a68c96ebac13d7fb9e0db516f9be0772777a0507fe06d682a441a3ba7"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
