You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

fastnlp_tutorial_e2.ipynb 47 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# E2. 使用 Bert + prompt 完成 SST2 分类\n",
  8. "\n",
  9. "  1   基础介绍:`prompt-based model`简介、与`fastNLP`的结合\n",
  10. "\n",
  11. "  2   准备工作:`P-Tuning v2`原理概述、`P-Tuning v2`模型搭建\n",
  12. "\n",
  13. "  3   模型训练:加载`tokenizer`、预处理`dataset`、模型训练与分析"
  14. ]
  15. },
  16. {
  17. "cell_type": "markdown",
  18. "metadata": {},
  19. "source": [
  20. "### 1. 基础介绍:prompt-based model 简介、与 fastNLP 的结合\n",
  21. "\n",
  22. "  本示例使用`GLUE`评估基准中的`SST2`数据集,通过`prompt-based tuning`方式\n",
  23. "\n",
  24. "    微调`bert-base-uncased`模型,实现文本情感的二分类,在此之前本示例\n",
  25. "\n",
  26. "    将首先简单介绍提示学习模型的研究,以及与`fastNLP v0.8`结合的优势\n",
  27. "\n",
  28. "**`prompt`**,**提示词**,最早出自论文[Exploiting Cloze Questions for Few Shot TC and NLI](https://arxiv.org/pdf/2001.07676.pdf)中的**`PET`模型**\n",
  29. "\n",
  30. "    全称 **`Pattern-Exploiting Training`**,虽然文中并没有提到**`prompt`的说法,但仍视为其开山之作\n",
  31. "\n",
  32. "  其大致思路包括,对于文本分类任务,假定输入文本为,后来被称`prompt`,后来被称`verbalizer`,\n",
  33. "\n",
  34. "  其主要贡献在于,\n",
  35. "\n",
  36. "<img src=\"./figures/E2-fig-pet-model.png\" width=\"36%\" height=\"36%\" align=\"center\"></img>\n",
  37. "\n",
  38. "**`prompt-based tuning`**,**基于提示的微调**,\n",
  39. "\n",
  40. "&emsp; xxxx,更多参考[prompt综述](https://arxiv.org/pdf/2107.13586.pdf)\n",
  41. "\n",
  42. "&emsp; &emsp; 以下列举些经典的`prompt-based tuning`案例,简单地介绍下`prompt-based tuning`的脉络\n",
  43. "\n",
  44. "&emsp; 案例一:**`P-Tuning v1`**,详细内容参考[P-Tuning-v1论文](https://arxiv.org/pdf/2103.10385.pdf)\n",
  45. "\n",
  46. "&emsp; &emsp; 其主要贡献在于,\n",
  47. "\n",
  48. "&emsp; &emsp; 其方法大致包括,\n",
  49. "\n",
  50. "&emsp; 案例二:**`PromptTuning`**,详细内容参考[PromptTuning论文](https://arxiv.org/pdf/2104.08691.pdf)\n",
  51. "\n",
  52. "&emsp; &emsp; 其主要贡献在于,\n",
  53. "\n",
  54. "&emsp; &emsp; 其方法大致包括,\n",
  55. "\n",
  56. "&emsp; 案例三:**`PrefixTuning`**,详细内容参考[PrefixTuning论文](https://arxiv.org/pdf/2101.00190.pdf)\n",
  57. "\n",
  58. "&emsp; &emsp; 其主要贡献在于,\n",
  59. "\n",
  60. "&emsp; &emsp; 其方法大致包括,\n",
  61. "\n",
  62. "通过上述介绍可以发现`prompt-based tuning`只是模型微调方式,独立于预训练模型基础`backbone`\n",
  63. "\n",
  64. "&emsp; 目前,加载预训练模型的主流方法是使用`transformers`模块,而实现微调的框架则\n",
  65. "\n",
  66. "&emsp; &emsp; 可以是`pytorch`、`paddle`、`jittor`等,而不同框架间又存在不兼容的问题\n",
  67. "\n",
  68. "&emsp; 因此,**使用`fastNLP v0.8`实现`prompt-based tuning`**,可以**很好地解决`paddle`等框架**\n",
  69. "\n",
  70. "&emsp; &emsp; **和`transformers`模块之间的桥接**(`transformers`模块基于`pytorch`实现)\n",
  71. "\n",
  72. "本示例仍使用了`tutorial-E1`的`SST2`数据集、`distilbert-base-uncased`模型(便于比较\n",
  73. "\n",
  74. "&emsp; 使用`pytorch`框架,通过将连续的`prompt`与`model`拼接,解决`SST2`二分类任务"
  75. ]
  76. },
  77. {
  78. "cell_type": "code",
  79. "execution_count": 1,
  80. "metadata": {},
  81. "outputs": [
  82. {
  83. "data": {
  84. "text/html": [
  85. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  86. "</pre>\n"
  87. ],
  88. "text/plain": [
  89. "\n"
  90. ]
  91. },
  92. "metadata": {},
  93. "output_type": "display_data"
  94. },
  95. {
  96. "name": "stdout",
  97. "output_type": "stream",
  98. "text": [
  99. "4.18.0\n"
  100. ]
  101. }
  102. ],
  103. "source": [
  104. "import torch\n",
  105. "import torch.nn as nn\n",
  106. "from torch.optim import AdamW\n",
  107. "from torch.utils.data import DataLoader, Dataset\n",
  108. "\n",
  109. "import transformers\n",
  110. "from transformers import AutoTokenizer\n",
  111. "from transformers import AutoModelForSequenceClassification\n",
  112. "\n",
  113. "import sys\n",
  114. "sys.path.append('..')\n",
  115. "\n",
  116. "import fastNLP\n",
  117. "from fastNLP import Trainer\n",
  118. "from fastNLP.core.metrics import Accuracy\n",
  119. "\n",
  120. "print(transformers.__version__)\n",
  121. "\n",
  122. "task = 'sst2'\n",
  123. "model_checkpoint = 'distilbert-base-uncased' # 'bert-base-uncased'"
  124. ]
  125. },
  126. {
  127. "cell_type": "markdown",
  128. "metadata": {},
  129. "source": [
  130. "### 2. 准备工作:P-Tuning v2 原理概述、P-Tuning v2 模型搭建\n",
  131. "\n",
  132. "&emsp; 本示例使用`P-Tuning v2`作为`prompt-based tuning`与`fastNLP v0.8`结合的案例\n",
  133. "\n",
  134. "&emsp; &emsp; 以下首先简述`P-Tuning v2`的论文原理,并由此引出`fastNLP v0.8`的代码实践\n",
  135. "\n",
  136. "**`P-Tuning v2`**出自论文[Prompt Tuning Can Be Comparable to Fine-tuning Universally Across Scales and Tasks](https://arxiv.org/pdf/2110.07602.pdf)\n",
  137. "\n",
  138. "&emsp; 其主要贡献在于,**在`PrefixTuning`等深度提示学习基础上**,**提升了其在分类标注等`NLU`任务的表现**\n",
  139. "\n",
  140. "&emsp; &emsp; 并使之在中等规模模型,主要是**参数量在`100M-1B`区间的模型上**,**获得与全参数微调相同的效果**\n",
  141. "\n",
  142. "&emsp; 其结构如图所示,通过**在输入序列的分类符`[CLS]`之前**,**加入前缀序列**(**序号对应嵌入是待训练的连续值向量**\n",
  143. "\n",
  144. "&emsp; &emsp; **刺激模型在新任务下**,从`[CLS]`对应位置,**输出符合微调任务的输出**,从而达到适应微调任务的目的\n",
  145. "\n",
  146. "<img src=\"./figures/E2-fig-p-tuning-v2-model.png\" width=\"60%\" height=\"60%\" align=\"center\"></img>\n",
  147. "\n",
  148. "本示例使用`bert-base-uncased`模型,作为`P-Tuning v2`的基础`backbone`,设置`requires_grad=False`\n",
  149. "\n",
  150. "&emsp; &emsp; 固定其参数不参与训练,**设置`pre_seq_len`长的`prefix_tokens`作为输入的提示前缀序列**\n",
  151. "\n",
  152. "&emsp; **使用基于`nn.Embedding`的`prefix_encoder`为提示前缀嵌入**,通过`get_prompt`函数获取,再将之\n",
  153. "\n",
  154. "&emsp; &emsp; 拼接至批量内每笔数据前得到`inputs_embeds`,同时更新自注意力掩模`attention_mask`\n",
  155. "\n",
  156. "&emsp; 将`inputs_embeds`、`attention_mask`和`labels`输入`backbone`,**得到输出包括`loss`和`logits`**"
  157. ]
  158. },
  159. {
  160. "cell_type": "code",
  161. "execution_count": 2,
  162. "metadata": {},
  163. "outputs": [],
  164. "source": [
  165. "class SeqClsModel(nn.Module):\n",
  166. " def __init__(self, model_checkpoint, num_labels, pre_seq_len):\n",
  167. " nn.Module.__init__(self)\n",
  168. " self.num_labels = num_labels\n",
  169. " self.back_bone = AutoModelForSequenceClassification.from_pretrained(model_checkpoint, \n",
  170. " num_labels=num_labels)\n",
  171. " self.embeddings = self.back_bone.get_input_embeddings()\n",
  172. "\n",
  173. " for param in self.back_bone.parameters():\n",
  174. " param.requires_grad = False\n",
  175. " \n",
  176. " self.pre_seq_len = pre_seq_len\n",
  177. " self.prefix_tokens = torch.arange(self.pre_seq_len).long()\n",
  178. " self.prefix_encoder = nn.Embedding(self.pre_seq_len, self.embeddings.embedding_dim)\n",
  179. " \n",
  180. " def get_prompt(self, batch_size):\n",
  181. " prefix_tokens = self.prefix_tokens.unsqueeze(0).expand(batch_size, -1).to(self.back_bone.device)\n",
  182. " prompts = self.prefix_encoder(prefix_tokens)\n",
  183. " return prompts\n",
  184. "\n",
  185. " def forward(self, input_ids, attention_mask, labels=None):\n",
  186. " \n",
  187. " batch_size = input_ids.shape[0]\n",
  188. " raw_embedding = self.embeddings(input_ids)\n",
  189. " \n",
  190. " prompts = self.get_prompt(batch_size=batch_size)\n",
  191. " inputs_embeds = torch.cat((prompts, raw_embedding), dim=1)\n",
  192. " prefix_attention_mask = torch.ones(batch_size, self.pre_seq_len).to(self.back_bone.device)\n",
  193. " attention_mask = torch.cat((prefix_attention_mask, attention_mask), dim=1)\n",
  194. "\n",
  195. " outputs = self.back_bone(inputs_embeds=inputs_embeds, \n",
  196. " attention_mask=attention_mask, labels=labels)\n",
  197. " return outputs\n",
  198. "\n",
  199. " def train_step(self, input_ids, attention_mask, labels):\n",
  200. " loss = self(input_ids, attention_mask, labels).loss\n",
  201. " return {'loss': loss}\n",
  202. "\n",
  203. " def evaluate_step(self, input_ids, attention_mask, labels):\n",
  204. " pred = self(input_ids, attention_mask, labels).logits\n",
  205. " pred = torch.max(pred, dim=-1)[1]\n",
  206. " return {'pred': pred, 'target': labels}"
  207. ]
  208. },
  209. {
  210. "cell_type": "markdown",
  211. "metadata": {},
  212. "source": [
  213. "接着,通过确定分类数量初始化模型实例,同时调用`torch.optim.AdamW`模块初始化优化器\n",
  214. "\n",
  215. "&emsp; 根据`P-Tuning v2`论文:*`Generally, simple classification tasks prefer shorter prompts (less than 20)`*\n",
  216. "\n",
  217. "&emsp; 此处`pre_seq_len`参数设定为`20`,学习率相应做出调整,其他内容和`tutorial-E1`中的内容一致"
  218. ]
  219. },
  220. {
  221. "cell_type": "code",
  222. "execution_count": 3,
  223. "metadata": {},
  224. "outputs": [
  225. {
  226. "name": "stderr",
  227. "output_type": "stream",
  228. "text": [
  229. "Some weights of the model checkpoint at distilbert-base-uncased were not used when initializing DistilBertForSequenceClassification: ['vocab_layer_norm.bias', 'vocab_layer_norm.weight', 'vocab_projector.weight', 'vocab_transform.bias', 'vocab_transform.weight', 'vocab_projector.bias']\n",
  230. "- This IS expected if you are initializing DistilBertForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
  231. "- This IS NOT expected if you are initializing DistilBertForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n",
  232. "Some weights of DistilBertForSequenceClassification were not initialized from the model checkpoint at distilbert-base-uncased and are newly initialized: ['pre_classifier.weight', 'classifier.weight', 'pre_classifier.bias', 'classifier.bias']\n",
  233. "You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
  234. ]
  235. }
  236. ],
  237. "source": [
  238. "model = SeqClsModel(model_checkpoint=model_checkpoint, num_labels=2, pre_seq_len=20)\n",
  239. "\n",
  240. "optimizers = AdamW(params=model.parameters(), lr=1e-2)"
  241. ]
  242. },
  243. {
  244. "cell_type": "markdown",
  245. "metadata": {},
  246. "source": [
  247. "### 3. 模型训练:加载 tokenizer、预处理 dataset、模型训练与分析\n",
  248. "\n",
  249. "&emsp; 本示例沿用`tutorial-E1`中的数据集,即使用`GLUE`评估基准中的`SST2`数据集\n",
  250. "\n",
  251. "&emsp; &emsp; 以`bert-base-uncased`模型作为基准,基于`P-Tuning v2`方式微调\n",
  252. "\n",
  253. "&emsp; &emsp; 数据集加载相关代码流程见下,内容和`tutorial-E1`中的内容基本一致\n",
  254. "\n",
  255. "首先,使用`datasets.load_dataset`加载数据集,使用`transformers.AutoTokenizer`\n",
  256. "\n",
  257. "&emsp; 构建`tokenizer`实例,通过`dataset.map`使用`tokenizer`将文本替换为词素序号序列"
  258. ]
  259. },
  260. {
  261. "cell_type": "code",
  262. "execution_count": 4,
  263. "metadata": {
  264. "scrolled": false
  265. },
  266. "outputs": [
  267. {
  268. "name": "stderr",
  269. "output_type": "stream",
  270. "text": [
  271. "Reusing dataset glue (/remote-home/xrliu/.cache/huggingface/datasets/glue/sst2/1.0.0/dacbe3125aa31d7f70367a07a8a9e72a5a0bfeb5fc42e75c9db75b96da6053ad)\n"
  272. ]
  273. },
  274. {
  275. "data": {
  276. "application/vnd.jupyter.widget-view+json": {
  277. "model_id": "21cbd92c3397497d84dc10f017ec96f4",
  278. "version_major": 2,
  279. "version_minor": 0
  280. },
  281. "text/plain": [
  282. " 0%| | 0/3 [00:00<?, ?it/s]"
  283. ]
  284. },
  285. "metadata": {},
  286. "output_type": "display_data"
  287. }
  288. ],
  289. "source": [
  290. "from datasets import load_dataset, load_metric\n",
  291. "\n",
  292. "dataset = load_dataset('glue', task)\n",
  293. "\n",
  294. "tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, use_fast=True)"
  295. ]
  296. },
  297. {
  298. "cell_type": "code",
  299. "execution_count": 5,
  300. "metadata": {},
  301. "outputs": [
  302. {
  303. "name": "stderr",
  304. "output_type": "stream",
  305. "text": [
  306. "Loading cached processed dataset at /remote-home/xrliu/.cache/huggingface/datasets/glue/sst2/1.0.0/dacbe3125aa31d7f70367a07a8a9e72a5a0bfeb5fc42e75c9db75b96da6053ad/cache-294e481a713c5754.arrow\n",
  307. "Loading cached processed dataset at /remote-home/xrliu/.cache/huggingface/datasets/glue/sst2/1.0.0/dacbe3125aa31d7f70367a07a8a9e72a5a0bfeb5fc42e75c9db75b96da6053ad/cache-ed9d9258aaf0fb54.arrow\n",
  308. "Loading cached processed dataset at /remote-home/xrliu/.cache/huggingface/datasets/glue/sst2/1.0.0/dacbe3125aa31d7f70367a07a8a9e72a5a0bfeb5fc42e75c9db75b96da6053ad/cache-f44c5576b89f9e6b.arrow\n"
  309. ]
  310. }
  311. ],
  312. "source": [
  313. "def preprocess_function(examples):\n",
  314. " return tokenizer(examples['sentence'], truncation=True)\n",
  315. "\n",
  316. "encoded_dataset = dataset.map(preprocess_function, batched=True)"
  317. ]
  318. },
  319. {
  320. "cell_type": "markdown",
  321. "metadata": {},
  322. "source": [
  323. "然后,定义`SeqClsDataset`类、定义校对函数`collate_fn`,这里沿用`tutorial-E1`中的内容\n",
  324. "\n",
  325. "&emsp; 同样需要注意/强调的是,**`__getitem__`函数的返回值必须和原始数据集中的属性对应**\n",
  326. "\n",
  327. "&emsp; **`collate_fn`函数的返回值必须和`train_step`和`evaluate_step`函数的参数匹配**"
  328. ]
  329. },
  330. {
  331. "cell_type": "code",
  332. "execution_count": 6,
  333. "metadata": {},
  334. "outputs": [],
  335. "source": [
  336. "class SeqClsDataset(Dataset):\n",
  337. " def __init__(self, dataset):\n",
  338. " Dataset.__init__(self)\n",
  339. " self.dataset = dataset\n",
  340. "\n",
  341. " def __len__(self):\n",
  342. " return len(self.dataset)\n",
  343. "\n",
  344. " def __getitem__(self, item):\n",
  345. " item = self.dataset[item]\n",
  346. " return item['input_ids'], item['attention_mask'], [item['label']] \n",
  347. "\n",
  348. "def collate_fn(batch):\n",
  349. " input_ids, atten_mask, labels = [], [], []\n",
  350. " max_length = [0] * 3\n",
  351. " for each_item in batch:\n",
  352. " input_ids.append(each_item[0])\n",
  353. " max_length[0] = max(max_length[0], len(each_item[0]))\n",
  354. " atten_mask.append(each_item[1])\n",
  355. " max_length[1] = max(max_length[1], len(each_item[1]))\n",
  356. " labels.append(each_item[2])\n",
  357. " max_length[2] = max(max_length[2], len(each_item[2]))\n",
  358. "\n",
  359. " for i in range(3):\n",
  360. " each = (input_ids, atten_mask, labels)[i]\n",
  361. " for item in each:\n",
  362. " item.extend([0] * (max_length[i] - len(item)))\n",
  363. " return {'input_ids': torch.cat([torch.tensor([item]) for item in input_ids], dim=0),\n",
  364. " 'attention_mask': torch.cat([torch.tensor([item]) for item in atten_mask], dim=0),\n",
  365. " 'labels': torch.cat([torch.tensor(item) for item in labels], dim=0)}"
  366. ]
  367. },
  368. {
  369. "cell_type": "markdown",
  370. "metadata": {},
  371. "source": [
  372. "再然后,分别对`tokenizer`处理过的训练集数据、验证集数据,进行预处理和批量划分"
  373. ]
  374. },
  375. {
  376. "cell_type": "code",
  377. "execution_count": 7,
  378. "metadata": {},
  379. "outputs": [],
  380. "source": [
  381. "dataset_train = SeqClsDataset(encoded_dataset['train'])\n",
  382. "dataloader_train = DataLoader(dataset=dataset_train, \n",
  383. " batch_size=32, shuffle=True, collate_fn=collate_fn)\n",
  384. "dataset_valid = SeqClsDataset(encoded_dataset['validation'])\n",
  385. "dataloader_valid = DataLoader(dataset=dataset_valid, \n",
  386. " batch_size=32, shuffle=False, collate_fn=collate_fn)"
  387. ]
  388. },
  389. {
  390. "cell_type": "markdown",
  391. "metadata": {},
  392. "source": [
  393. "最后,使用之前完成的`dataloader_train`和`dataloader_valid`,定义训练模块`trainer`"
  394. ]
  395. },
  396. {
  397. "cell_type": "code",
  398. "execution_count": 8,
  399. "metadata": {},
  400. "outputs": [],
  401. "source": [
  402. "trainer = Trainer(\n",
  403. " model=model,\n",
  404. " driver='torch',\n",
  405. " device=1, # [0, 1],\n",
  406. " n_epochs=10,\n",
  407. " optimizers=optimizers,\n",
  408. " train_dataloader=dataloader_train,\n",
  409. " evaluate_dataloaders=dataloader_valid,\n",
  410. " metrics={'acc': Accuracy()}\n",
  411. ")"
  412. ]
  413. },
  414. {
  415. "cell_type": "markdown",
  416. "metadata": {},
  417. "source": [
  418. "&emsp; 使用`trainer.run`方法训练模型,同样每次只对验证集中的`10`个`batch`进行评估"
  419. ]
  420. },
  421. {
  422. "cell_type": "code",
  423. "execution_count": 9,
  424. "metadata": {},
  425. "outputs": [
  426. {
  427. "data": {
  428. "text/html": [
  429. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[22:53:00] </span><span style=\"color: #000080; text-decoration-color: #000080\">INFO </span> Running evaluator sanity check for <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span> batches. <a href=\"file://../fastNLP/core/controllers/trainer.py\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">trainer.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file://../fastNLP/core/controllers/trainer.py#592\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">592</span></a>\n",
  430. "</pre>\n"
  431. ],
  432. "text/plain": [
  433. "\u001b[2;36m[22:53:00]\u001b[0m\u001b[2;36m \u001b[0m\u001b[34mINFO \u001b[0m Running evaluator sanity check for \u001b[1;36m2\u001b[0m batches. \u001b]8;id=406635;file://../fastNLP/core/controllers/trainer.py\u001b\\\u001b[2mtrainer.py\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=951504;file://../fastNLP/core/controllers/trainer.py#592\u001b\\\u001b[2m592\u001b[0m\u001b]8;;\u001b\\\n"
  434. ]
  435. },
  436. "metadata": {},
  437. "output_type": "display_data"
  438. },
  439. {
  440. "data": {
  441. "application/vnd.jupyter.widget-view+json": {
  442. "model_id": "",
  443. "version_major": 2,
  444. "version_minor": 0
  445. },
  446. "text/plain": [
  447. "Output()"
  448. ]
  449. },
  450. "metadata": {},
  451. "output_type": "display_data"
  452. },
  453. {
  454. "data": {
  455. "text/html": [
  456. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  457. ],
  458. "text/plain": []
  459. },
  460. "metadata": {},
  461. "output_type": "display_data"
  462. },
  463. {
  464. "data": {
  465. "application/vnd.jupyter.widget-view+json": {
  466. "model_id": "",
  467. "version_major": 2,
  468. "version_minor": 0
  469. },
  470. "text/plain": [
  471. "Output()"
  472. ]
  473. },
  474. "metadata": {},
  475. "output_type": "display_data"
  476. },
  477. {
  478. "data": {
  479. "text/html": [
  480. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  481. "</pre>\n"
  482. ],
  483. "text/plain": [
  484. "\n"
  485. ]
  486. },
  487. "metadata": {},
  488. "output_type": "display_data"
  489. },
  490. {
  491. "data": {
  492. "text/html": [
  493. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">----------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  494. "</pre>\n"
  495. ],
  496. "text/plain": [
  497. "----------------------------- Eval. results on Epoch:\u001b[1;36m1\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  498. ]
  499. },
  500. "metadata": {},
  501. "output_type": "display_data"
  502. },
  503. {
  504. "data": {
  505. "text/html": [
  506. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  507. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.540625</span>,\n",
  508. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  509. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">173.0</span>\n",
  510. "<span style=\"font-weight: bold\">}</span>\n",
  511. "</pre>\n"
  512. ],
  513. "text/plain": [
  514. "\u001b[1m{\u001b[0m\n",
  515. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.540625\u001b[0m,\n",
  516. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  517. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m173.0\u001b[0m\n",
  518. "\u001b[1m}\u001b[0m\n"
  519. ]
  520. },
  521. "metadata": {},
  522. "output_type": "display_data"
  523. },
  524. {
  525. "data": {
  526. "text/html": [
  527. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  528. "</pre>\n"
  529. ],
  530. "text/plain": [
  531. "\n"
  532. ]
  533. },
  534. "metadata": {},
  535. "output_type": "display_data"
  536. },
  537. {
  538. "data": {
  539. "text/html": [
  540. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">----------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  541. "</pre>\n"
  542. ],
  543. "text/plain": [
  544. "----------------------------- Eval. results on Epoch:\u001b[1;36m2\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  545. ]
  546. },
  547. "metadata": {},
  548. "output_type": "display_data"
  549. },
  550. {
  551. "data": {
  552. "text/html": [
  553. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  554. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.5</span>,\n",
  555. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  556. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">160.0</span>\n",
  557. "<span style=\"font-weight: bold\">}</span>\n",
  558. "</pre>\n"
  559. ],
  560. "text/plain": [
  561. "\u001b[1m{\u001b[0m\n",
  562. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.5\u001b[0m,\n",
  563. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  564. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m\n",
  565. "\u001b[1m}\u001b[0m\n"
  566. ]
  567. },
  568. "metadata": {},
  569. "output_type": "display_data"
  570. },
  571. {
  572. "data": {
  573. "text/html": [
  574. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  575. "</pre>\n"
  576. ],
  577. "text/plain": [
  578. "\n"
  579. ]
  580. },
  581. "metadata": {},
  582. "output_type": "display_data"
  583. },
  584. {
  585. "data": {
  586. "text/html": [
  587. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">----------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  588. "</pre>\n"
  589. ],
  590. "text/plain": [
  591. "----------------------------- Eval. results on Epoch:\u001b[1;36m3\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  592. ]
  593. },
  594. "metadata": {},
  595. "output_type": "display_data"
  596. },
  597. {
  598. "data": {
  599. "text/html": [
  600. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  601. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.509375</span>,\n",
  602. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  603. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">163.0</span>\n",
  604. "<span style=\"font-weight: bold\">}</span>\n",
  605. "</pre>\n"
  606. ],
  607. "text/plain": [
  608. "\u001b[1m{\u001b[0m\n",
  609. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.509375\u001b[0m,\n",
  610. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  611. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m163.0\u001b[0m\n",
  612. "\u001b[1m}\u001b[0m\n"
  613. ]
  614. },
  615. "metadata": {},
  616. "output_type": "display_data"
  617. },
  618. {
  619. "data": {
  620. "text/html": [
  621. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  622. "</pre>\n"
  623. ],
  624. "text/plain": [
  625. "\n"
  626. ]
  627. },
  628. "metadata": {},
  629. "output_type": "display_data"
  630. },
  631. {
  632. "data": {
  633. "text/html": [
  634. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">----------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  635. "</pre>\n"
  636. ],
  637. "text/plain": [
  638. "----------------------------- Eval. results on Epoch:\u001b[1;36m4\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  639. ]
  640. },
  641. "metadata": {},
  642. "output_type": "display_data"
  643. },
  644. {
  645. "data": {
  646. "text/html": [
  647. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  648. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.634375</span>,\n",
  649. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  650. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">203.0</span>\n",
  651. "<span style=\"font-weight: bold\">}</span>\n",
  652. "</pre>\n"
  653. ],
  654. "text/plain": [
  655. "\u001b[1m{\u001b[0m\n",
  656. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.634375\u001b[0m,\n",
  657. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  658. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m203.0\u001b[0m\n",
  659. "\u001b[1m}\u001b[0m\n"
  660. ]
  661. },
  662. "metadata": {},
  663. "output_type": "display_data"
  664. },
  665. {
  666. "data": {
  667. "text/html": [
  668. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  669. "</pre>\n"
  670. ],
  671. "text/plain": [
  672. "\n"
  673. ]
  674. },
  675. "metadata": {},
  676. "output_type": "display_data"
  677. },
  678. {
  679. "data": {
  680. "text/html": [
  681. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">----------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  682. "</pre>\n"
  683. ],
  684. "text/plain": [
  685. "----------------------------- Eval. results on Epoch:\u001b[1;36m5\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  686. ]
  687. },
  688. "metadata": {},
  689. "output_type": "display_data"
  690. },
  691. {
  692. "data": {
  693. "text/html": [
  694. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  695. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.6125</span>,\n",
  696. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  697. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">196.0</span>\n",
  698. "<span style=\"font-weight: bold\">}</span>\n",
  699. "</pre>\n"
  700. ],
  701. "text/plain": [
  702. "\u001b[1m{\u001b[0m\n",
  703. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.6125\u001b[0m,\n",
  704. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  705. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m196.0\u001b[0m\n",
  706. "\u001b[1m}\u001b[0m\n"
  707. ]
  708. },
  709. "metadata": {},
  710. "output_type": "display_data"
  711. },
  712. {
  713. "data": {
  714. "text/html": [
  715. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  716. "</pre>\n"
  717. ],
  718. "text/plain": [
  719. "\n"
  720. ]
  721. },
  722. "metadata": {},
  723. "output_type": "display_data"
  724. },
  725. {
  726. "data": {
  727. "text/html": [
  728. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">----------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  729. "</pre>\n"
  730. ],
  731. "text/plain": [
  732. "----------------------------- Eval. results on Epoch:\u001b[1;36m6\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  733. ]
  734. },
  735. "metadata": {},
  736. "output_type": "display_data"
  737. },
  738. {
  739. "data": {
  740. "text/html": [
  741. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  742. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.675</span>,\n",
  743. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  744. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">216.0</span>\n",
  745. "<span style=\"font-weight: bold\">}</span>\n",
  746. "</pre>\n"
  747. ],
  748. "text/plain": [
  749. "\u001b[1m{\u001b[0m\n",
  750. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.675\u001b[0m,\n",
  751. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  752. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m216.0\u001b[0m\n",
  753. "\u001b[1m}\u001b[0m\n"
  754. ]
  755. },
  756. "metadata": {},
  757. "output_type": "display_data"
  758. },
  759. {
  760. "data": {
  761. "text/html": [
  762. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  763. "</pre>\n"
  764. ],
  765. "text/plain": [
  766. "\n"
  767. ]
  768. },
  769. "metadata": {},
  770. "output_type": "display_data"
  771. },
  772. {
  773. "data": {
  774. "text/html": [
  775. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">----------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  776. "</pre>\n"
  777. ],
  778. "text/plain": [
  779. "----------------------------- Eval. results on Epoch:\u001b[1;36m7\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  780. ]
  781. },
  782. "metadata": {},
  783. "output_type": "display_data"
  784. },
  785. {
  786. "data": {
  787. "text/html": [
  788. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  789. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.64375</span>,\n",
  790. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  791. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">206.0</span>\n",
  792. "<span style=\"font-weight: bold\">}</span>\n",
  793. "</pre>\n"
  794. ],
  795. "text/plain": [
  796. "\u001b[1m{\u001b[0m\n",
  797. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.64375\u001b[0m,\n",
  798. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  799. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m206.0\u001b[0m\n",
  800. "\u001b[1m}\u001b[0m\n"
  801. ]
  802. },
  803. "metadata": {},
  804. "output_type": "display_data"
  805. },
  806. {
  807. "data": {
  808. "text/html": [
  809. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  810. "</pre>\n"
  811. ],
  812. "text/plain": [
  813. "\n"
  814. ]
  815. },
  816. "metadata": {},
  817. "output_type": "display_data"
  818. },
  819. {
  820. "data": {
  821. "text/html": [
  822. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">----------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">8</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  823. "</pre>\n"
  824. ],
  825. "text/plain": [
  826. "----------------------------- Eval. results on Epoch:\u001b[1;36m8\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  827. ]
  828. },
  829. "metadata": {},
  830. "output_type": "display_data"
  831. },
  832. {
  833. "data": {
  834. "text/html": [
  835. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  836. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.665625</span>,\n",
  837. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  838. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">213.0</span>\n",
  839. "<span style=\"font-weight: bold\">}</span>\n",
  840. "</pre>\n"
  841. ],
  842. "text/plain": [
  843. "\u001b[1m{\u001b[0m\n",
  844. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.665625\u001b[0m,\n",
  845. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  846. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m213.0\u001b[0m\n",
  847. "\u001b[1m}\u001b[0m\n"
  848. ]
  849. },
  850. "metadata": {},
  851. "output_type": "display_data"
  852. },
  853. {
  854. "data": {
  855. "text/html": [
  856. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  857. "</pre>\n"
  858. ],
  859. "text/plain": [
  860. "\n"
  861. ]
  862. },
  863. "metadata": {},
  864. "output_type": "display_data"
  865. },
  866. {
  867. "data": {
  868. "text/html": [
  869. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">----------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">9</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  870. "</pre>\n"
  871. ],
  872. "text/plain": [
  873. "----------------------------- Eval. results on Epoch:\u001b[1;36m9\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  874. ]
  875. },
  876. "metadata": {},
  877. "output_type": "display_data"
  878. },
  879. {
  880. "data": {
  881. "text/html": [
  882. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  883. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.659375</span>,\n",
  884. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  885. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">211.0</span>\n",
  886. "<span style=\"font-weight: bold\">}</span>\n",
  887. "</pre>\n"
  888. ],
  889. "text/plain": [
  890. "\u001b[1m{\u001b[0m\n",
  891. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.659375\u001b[0m,\n",
  892. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  893. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m211.0\u001b[0m\n",
  894. "\u001b[1m}\u001b[0m\n"
  895. ]
  896. },
  897. "metadata": {},
  898. "output_type": "display_data"
  899. },
  900. {
  901. "data": {
  902. "text/html": [
  903. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  904. "</pre>\n"
  905. ],
  906. "text/plain": [
  907. "\n"
  908. ]
  909. },
  910. "metadata": {},
  911. "output_type": "display_data"
  912. },
  913. {
  914. "data": {
  915. "text/html": [
  916. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">---------------------------- Eval. results on Epoch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">10</span>, Batch:<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span> -----------------------------\n",
  917. "</pre>\n"
  918. ],
  919. "text/plain": [
  920. "---------------------------- Eval. results on Epoch:\u001b[1;36m10\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  921. ]
  922. },
  923. "metadata": {},
  924. "output_type": "display_data"
  925. },
  926. {
  927. "data": {
  928. "text/html": [
  929. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
  930. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"acc#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.696875</span>,\n",
  931. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"total#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">320.0</span>,\n",
  932. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"correct#acc\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">223.0</span>\n",
  933. "<span style=\"font-weight: bold\">}</span>\n",
  934. "</pre>\n"
  935. ],
  936. "text/plain": [
  937. "\u001b[1m{\u001b[0m\n",
  938. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.696875\u001b[0m,\n",
  939. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m320.0\u001b[0m,\n",
  940. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m223.0\u001b[0m\n",
  941. "\u001b[1m}\u001b[0m\n"
  942. ]
  943. },
  944. "metadata": {},
  945. "output_type": "display_data"
  946. },
  947. {
  948. "data": {
  949. "text/html": [
  950. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  951. ],
  952. "text/plain": []
  953. },
  954. "metadata": {},
  955. "output_type": "display_data"
  956. },
  957. {
  958. "data": {
  959. "text/html": [
  960. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  961. "</pre>\n"
  962. ],
  963. "text/plain": [
  964. "\n"
  965. ]
  966. },
  967. "metadata": {},
  968. "output_type": "display_data"
  969. }
  970. ],
  971. "source": [
  972. "trainer.run(num_eval_batch_per_dl=10)"
  973. ]
  974. },
  975. {
  976. "cell_type": "markdown",
  977. "metadata": {},
  978. "source": [
  979. "可以发现,其效果远远逊色于`fine-tuning`,这是因为`P-Tuning v2`虽然能够适应参数量\n",
  980. "\n",
  981. "&emsp; 在`100M-1B`区间的模型,但是,**`distilbert-base`的参数量仅为`66M`**,无法触及其下限\n",
  982. "\n",
  983. "另一方面,**`fastNLP v0.8`不支持`jupyter`多卡**,所以无法在笔者的电脑/服务器上,完成\n",
  984. "\n",
  985. "&emsp; 合适规模模型的学习,例如`110M`的`bert-base`模型,以及`340M`的`bert-large`模型"
  986. ]
  987. },
  988. {
  989. "cell_type": "code",
  990. "execution_count": 10,
  991. "metadata": {},
  992. "outputs": [
  993. {
  994. "data": {
  995. "application/vnd.jupyter.widget-view+json": {
  996. "model_id": "",
  997. "version_major": 2,
  998. "version_minor": 0
  999. },
  1000. "text/plain": [
  1001. "Output()"
  1002. ]
  1003. },
  1004. "metadata": {},
  1005. "output_type": "display_data"
  1006. },
  1007. {
  1008. "data": {
  1009. "text/html": [
  1010. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  1011. ],
  1012. "text/plain": []
  1013. },
  1014. "metadata": {},
  1015. "output_type": "display_data"
  1016. },
  1017. {
  1018. "data": {
  1019. "text/plain": [
  1020. "{'acc#acc': 0.737385, 'total#acc': 872.0, 'correct#acc': 643.0}"
  1021. ]
  1022. },
  1023. "execution_count": 10,
  1024. "metadata": {},
  1025. "output_type": "execute_result"
  1026. }
  1027. ],
  1028. "source": [
  1029. "trainer.evaluator.run()"
  1030. ]
  1031. },
  1032. {
  1033. "cell_type": "code",
  1034. "execution_count": null,
  1035. "metadata": {},
  1036. "outputs": [],
  1037. "source": []
  1038. }
  1039. ],
  1040. "metadata": {
  1041. "kernelspec": {
  1042. "display_name": "Python 3 (ipykernel)",
  1043. "language": "python",
  1044. "name": "python3"
  1045. },
  1046. "language_info": {
  1047. "codemirror_mode": {
  1048. "name": "ipython",
  1049. "version": 3
  1050. },
  1051. "file_extension": ".py",
  1052. "mimetype": "text/x-python",
  1053. "name": "python",
  1054. "nbconvert_exporter": "python",
  1055. "pygments_lexer": "ipython3",
  1056. "version": "3.7.13"
  1057. },
  1058. "pycharm": {
  1059. "stem_cell": {
  1060. "cell_type": "raw",
  1061. "metadata": {
  1062. "collapsed": false
  1063. },
  1064. "source": []
  1065. }
  1066. }
  1067. },
  1068. "nbformat": 4,
  1069. "nbformat_minor": 1
  1070. }