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_4.ipynb 113 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "id": "fdd7ff16",
  6. "metadata": {},
  7. "source": [
  8. "# T4. fastNLP 中的预定义模型\n",
  9. "\n",
  10. "  1   fastNLP 中 modules 的介绍\n",
  11. " \n",
  12. "    1.1   modules 模块、models 模块 简介\n",
  13. "\n",
  14. "    1.2   示例一:modules 实现 LSTM 分类\n",
  15. "\n",
  16. "  2   fastNLP 中 models 的介绍\n",
  17. " \n",
  18. "    2.1   示例一:models 实现 CNN 分类\n",
  19. "\n",
  20. "    2.3   示例二:models 实现 BiLSTM 标注"
  21. ]
  22. },
  23. {
  24. "cell_type": "markdown",
  25. "id": "d3d65d53",
  26. "metadata": {},
  27. "source": [
  28. "## 1. fastNLP 中 modules 模块的介绍\n",
  29. "\n",
  30. "### 1.1 modules 模块、models 模块 简介\n",
  31. "\n",
  32. "在`fastNLP 0.8`中,**`modules.torch`路径下定义了一些基于`pytorch`实现的基础模块**\n",
  33. "\n",
  34. "    包括长短期记忆网络`LSTM`、条件随机场`CRF`、`transformer`的编解码器模块等,详见下表\n",
  35. "\n",
  36. "| <div align=\"center\">代码名称</div> | <div align=\"center\">简要介绍</div> | <div align=\"center\">代码路径</div> |\n",
  37. "|:--|:--|:--|\n",
  38. "| `LSTM` | 轻量封装`pytorch`的`LSTM` | `/modules/torch/encoder/lstm.py` |\n",
  39. "| `Seq2SeqEncoder` | 序列变换编码器,基类 | `/modules/torch/encoder/seq2seq_encoder.py` |\n",
  40. "| `LSTMSeq2SeqEncoder` | 序列变换编码器,基于`LSTM` | `/modules/torch/encoder/seq2seq_encoder.py` |\n",
  41. "| `TransformerSeq2SeqEncoder` | 序列变换编码器,基于`transformer` | `/modules/torch/encoder/seq2seq_encoder.py` |\n",
  42. "| `StarTransformer` | `Star-Transformer`的编码器部分 | `/modules/torch/encoder/star_transformer.py` |\n",
  43. "| `VarRNN` | 实现`Variational Dropout RNN` | `/modules/torch/encoder/variational_rnn.py` |\n",
  44. "| `VarLSTM` | 实现`Variational Dropout LSTM` | `/modules/torch/encoder/variational_rnn.py` |\n",
  45. "| `VarGRU` | 实现`Variational Dropout GRU` | `/modules/torch/encoder/variational_rnn.py` |\n",
  46. "| `MLP` | 多层感知机模型 | `/modules/torch/decoder/mlp.py` |\n",
  47. "| `ConditionalRandomField` | 条件随机场模型 | `/modules/torch/decoder/crf.py` |\n",
  48. "| `Seq2SeqDecoder` | 序列变换解码器,基类 | `/modules/torch/decoder/seq2seq_decoder.py` |\n",
  49. "| `LSTMSeq2SeqDecoder` | 序列变换解码器,基于`LSTM` | `/modules/torch/decoder/seq2seq_decoder.py` |\n",
  50. "| `TransformerSeq2SeqDecoder` | 序列变换解码器,基于`transformer` | `/modules/torch/decoder/seq2seq_decoder.py` |\n",
  51. "| `SequenceGenerator` | 序列生成,封装`Seq2SeqDecoder` | `/models/torch/sequence_labeling.py` |\n",
  52. "| `TimestepDropout` | 在每个`timestamp`上`dropout` | `/modules/torch/dropout.py` |"
  53. ]
  54. },
  55. {
  56. "cell_type": "markdown",
  57. "id": "89ffcf07",
  58. "metadata": {},
  59. "source": [
  60. "&emsp; **`models.torch`路径下定义了一些基于`pytorch`、`modules`实现的预定义模型** \n",
  61. "\n",
  62. "&emsp; &emsp; 例如基于`CNN`的分类模型、基于`BiLSTM+CRF`的标注模型、基于[双仿射注意力机制](https://arxiv.org/pdf/1611.01734.pdf)的分析模型\n",
  63. "\n",
  64. "&emsp; &emsp; 基于`modules.torch`中的`LSTM`/`transformer`编/解码器模块的序列变换/生成模型,详见下表\n",
  65. "\n",
  66. "| <div align=\"center\">代码名称</div> | <div align=\"center\">简要介绍</div> | <div align=\"center\">代码路径</div> |\n",
  67. "|:--|:--|:--|\n",
  68. "| `BiaffineParser` | 句法分析模型,基于双仿射注意力 | `/models/torch/biaffine_parser.py` |\n",
  69. "| `CNNText` | 文本分类模型,基于`CNN` | `/models/torch/cnn_text_classification.py` |\n",
  70. "| `Seq2SeqModel` | 序列变换,基类`encoder+decoder` | `/models/torch/seq2seq_model.py` |\n",
  71. "| `LSTMSeq2SeqModel` | 序列变换,基于`LSTM` | `/models/torch/seq2seq_model.py` |\n",
  72. "| `TransformerSeq2SeqModel` | 序列变换,基于`transformer` | `/models/torch/seq2seq_model.py` |\n",
  73. "| `SequenceGeneratorModel` | 封装`Seq2SeqModel`,结合`SequenceGenerator` | `/models/torch/seq2seq_generator.py` |\n",
  74. "| `SeqLabeling` | 标注模型,基类`LSTM+FC+CRF` | `/models/torch/sequence_labeling.py` |\n",
  75. "| `BiLSTMCRF` | 标注模型,`BiLSTM+FC+CRF` | `/models/torch/sequence_labeling.py` |\n",
  76. "| `AdvSeqLabel` | 标注模型,`LN+BiLSTM*2+LN+FC+CRF` | `/models/torch/sequence_labeling.py` |"
  77. ]
  78. },
  79. {
  80. "cell_type": "markdown",
  81. "id": "61318354",
  82. "metadata": {},
  83. "source": [
  84. "上述`fastNLP`模块,不仅**为入门级用户提供了简单易用的工具**,以解决各种`NLP`任务,或复现相关论文\n",
  85. "\n",
  86. "&emsp; 同时**也为专业研究人员提供了便捷可操作的接口**,封装部分代码的同时,也能指定参数修改细节\n",
  87. "\n",
  88. "&emsp; 在接下来的`tutorial`中,我们将通过`SST-2`分类和`CoNLL-2003`标注,展示相关模型使用\n",
  89. "\n",
  90. "注一:**`SST`**,**单句情感分类**数据集,包含电影评论和对应情感极性,1 对应正面情感,0 对应负面情感\n",
  91. "\n",
  92. "&emsp; 数据集包括三部分:训练集 67350 条,验证集 873 条,测试集 1821 条,更多参考[下载链接](https://gluebenchmark.com/tasks)\n",
  93. "\n",
  94. "注二:**`CoNLL-2003`**,**文本语法标注**数据集,包含语句和对应的词性标签`pos_tags`(名动形数量代)\n",
  95. "\n",
  96. "&emsp; 语法结构标签`chunk_tags`(主谓宾定状补)、命名实体标签`ner_tags`(人名、组织名、地名、时间等)\n",
  97. "\n",
  98. "&emsp; 数据集包括三部分:训练集 14041 条,验证集 3250 条,测试集 3453 条,更多参考[原始论文](https://aclanthology.org/W03-0419.pdf)"
  99. ]
  100. },
  101. {
  102. "cell_type": "markdown",
  103. "id": "2a36bbe4",
  104. "metadata": {},
  105. "source": [
  106. "### 1.2 示例一:modules 实现 LSTM 分类\n",
  107. "\n",
  108. "\n",
  109. "&emsp; 本示例使用`fastNLP 0.8`中预定义模型`modules`模块,基于`LSTM`模型,实现`SST-2`文本二分类任务\n",
  110. "\n",
  111. "数据使用方面:首先,**使用`datasets`模块中的`load_dataset`函数**,以如下形式,指定`SST-2`数据集加载\n",
  112. "\n",
  113. "&emsp; &emsp; 首次下载保存至`~/.cache/huggingface/modules/datasets_modules/datasets/glue/`目录下"
  114. ]
  115. },
  116. {
  117. "cell_type": "code",
  118. "execution_count": 1,
  119. "id": "1aa5cf6d",
  120. "metadata": {},
  121. "outputs": [
  122. {
  123. "name": "stderr",
  124. "output_type": "stream",
  125. "text": [
  126. "Reusing dataset glue (/remote-home/xrliu/.cache/huggingface/datasets/glue/sst2/1.0.0/dacbe3125aa31d7f70367a07a8a9e72a5a0bfeb5fc42e75c9db75b96da6053ad)\n"
  127. ]
  128. },
  129. {
  130. "data": {
  131. "application/vnd.jupyter.widget-view+json": {
  132. "model_id": "b8bdfdc011d349e38a1aa2aff35b2482",
  133. "version_major": 2,
  134. "version_minor": 0
  135. },
  136. "text/plain": [
  137. " 0%| | 0/3 [00:00<?, ?it/s]"
  138. ]
  139. },
  140. "metadata": {},
  141. "output_type": "display_data"
  142. }
  143. ],
  144. "source": [
  145. "from datasets import load_dataset\n",
  146. "\n",
  147. "sst2data = load_dataset('glue', 'sst2')"
  148. ]
  149. },
  150. {
  151. "cell_type": "markdown",
  152. "id": "c476abe7",
  153. "metadata": {},
  154. "source": [
  155. "&emsp; 接着,使用`tutorial-1`和`tutorial-2`中的知识,将数据集转化为`fastNLP`中的`DataSet`格式\n",
  156. "\n",
  157. "&emsp; &emsp; **使用`apply_more`函数、`Vocabulary`模块的`from_/index_dataset`函数预处理数据**\n",
  158. "\n",
  159. "&emsp; &emsp; &emsp; 并结合`delete_field`函数删除字段调整格式,`split`函数划分测试集和验证集\n",
  160. "\n",
  161. "&emsp; &emsp; **仅保留`'words'`字段表示输入文本单词序号序列、`'target'`字段表示文本对应预测输出结果**\n",
  162. "\n",
  163. "&emsp; &emsp; &emsp; 两者**对应到`CNNText`中`train_step`函数和`evaluate_step`函数的签名/输入参数**"
  164. ]
  165. },
  166. {
  167. "cell_type": "code",
  168. "execution_count": 2,
  169. "id": "357ea748",
  170. "metadata": {},
  171. "outputs": [
  172. {
  173. "name": "stderr",
  174. "output_type": "stream",
  175. "text": [
  176. "\u001b[38;5;2m[i 0604 16:19:46.727257 48 log.cc:351] Load log_sync: 1\u001b[m\n"
  177. ]
  178. },
  179. {
  180. "data": {
  181. "text/html": [
  182. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  183. "</pre>\n"
  184. ],
  185. "text/plain": [
  186. "\n"
  187. ]
  188. },
  189. "metadata": {},
  190. "output_type": "display_data"
  191. },
  192. {
  193. "data": {
  194. "application/vnd.jupyter.widget-view+json": {
  195. "model_id": "",
  196. "version_major": 2,
  197. "version_minor": 0
  198. },
  199. "text/plain": [
  200. "Processing: 0%| | 0/6000 [00:00<?, ?it/s]"
  201. ]
  202. },
  203. "metadata": {},
  204. "output_type": "display_data"
  205. }
  206. ],
  207. "source": [
  208. "import sys\n",
  209. "sys.path.append('..')\n",
  210. "\n",
  211. "from fastNLP import DataSet\n",
  212. "\n",
  213. "dataset = DataSet.from_pandas(sst2data['train'].to_pandas())[:6000]\n",
  214. "\n",
  215. "dataset.apply_more(lambda ins:{'words': ins['sentence'].lower().split(), 'target': ins['label']}, \n",
  216. " progress_bar=\"tqdm\")\n",
  217. "dataset.delete_field('sentence')\n",
  218. "dataset.delete_field('label')\n",
  219. "dataset.delete_field('idx')\n",
  220. "\n",
  221. "from fastNLP import Vocabulary\n",
  222. "\n",
  223. "vocab = Vocabulary()\n",
  224. "vocab.from_dataset(dataset, field_name='words')\n",
  225. "vocab.index_dataset(dataset, field_name='words')\n",
  226. "\n",
  227. "train_dataset, evaluate_dataset = dataset.split(ratio=0.85)"
  228. ]
  229. },
  230. {
  231. "cell_type": "markdown",
  232. "id": "96380c67",
  233. "metadata": {},
  234. "source": [
  235. "&emsp; 然后,使用`tutorial-3`中的知识,**通过`prepare_torch_dataloader`处理数据集得到`dataloader`**"
  236. ]
  237. },
  238. {
  239. "cell_type": "code",
  240. "execution_count": 3,
  241. "id": "b9dd1273",
  242. "metadata": {},
  243. "outputs": [],
  244. "source": [
  245. "from fastNLP import prepare_torch_dataloader\n",
  246. "\n",
  247. "train_dataloader = prepare_torch_dataloader(train_dataset, batch_size=16, shuffle=True)\n",
  248. "evaluate_dataloader = prepare_torch_dataloader(evaluate_dataset, batch_size=16)"
  249. ]
  250. },
  251. {
  252. "cell_type": "markdown",
  253. "id": "eb75aaba",
  254. "metadata": {},
  255. "source": [
  256. "模型使用方面,这里使用`Embedding`、`LSTM`、`MLP`等模块搭建模型,方法类似`pytorch`,结构如下所示\n",
  257. "\n",
  258. "```\n",
  259. "ClsByModules(\n",
  260. " (embedding): Embedding(\n",
  261. " (embed): Embedding(8458, 100)\n",
  262. " (dropout): Dropout(p=0.0, inplace=False)\n",
  263. " )\n",
  264. " (lstm): LSTM(\n",
  265. " (lstm): LSTM(100, 64, num_layers=2, batch_first=True, bidirectional=True)\n",
  266. " )\n",
  267. " (mlp): MLP(\n",
  268. " (hiddens): ModuleList()\n",
  269. " (output): Linear(in_features=128, out_features=2, bias=True)\n",
  270. " (dropout): Dropout(p=0.5, inplace=False)\n",
  271. " )\n",
  272. " (loss_fn): CrossEntropyLoss()\n",
  273. ")\n",
  274. "```"
  275. ]
  276. },
  277. {
  278. "cell_type": "code",
  279. "execution_count": 4,
  280. "id": "0b25b25c",
  281. "metadata": {},
  282. "outputs": [],
  283. "source": [
  284. "import torch\n",
  285. "import torch.nn as nn\n",
  286. "\n",
  287. "from fastNLP.modules.torch import LSTM, MLP\n",
  288. "from fastNLP.embeddings.torch import Embedding\n",
  289. "\n",
  290. "\n",
  291. "class ClsByModules(nn.Module):\n",
  292. " def __init__(self, vocab_size, embedding_dim, output_dim, hidden_dim=64, num_layers=2, dropout=0.5):\n",
  293. " nn.Module.__init__(self)\n",
  294. "\n",
  295. " self.embedding = Embedding((vocab_size, embedding_dim))\n",
  296. " self.lstm = LSTM(embedding_dim, hidden_dim, num_layers=num_layers, bidirectional=True)\n",
  297. " self.mlp = MLP([hidden_dim * 2, output_dim], dropout=dropout)\n",
  298. " \n",
  299. " self.loss_fn = nn.CrossEntropyLoss()\n",
  300. "\n",
  301. " def forward(self, words):\n",
  302. " output = self.embedding(words)\n",
  303. " output, (hidden, cell) = self.lstm(output)\n",
  304. " output = self.mlp(torch.cat((hidden[-1], hidden[-2]), dim=1))\n",
  305. " return output\n",
  306. " \n",
  307. " def train_step(self, words, target):\n",
  308. " pred = self(words)\n",
  309. " return {\"loss\": self.loss_fn(pred, target)}\n",
  310. "\n",
  311. " def evaluate_step(self, words, target):\n",
  312. " pred = self(words)\n",
  313. " pred = torch.max(pred, dim=-1)[1]\n",
  314. " return {\"pred\": pred, \"target\": target}"
  315. ]
  316. },
  317. {
  318. "cell_type": "markdown",
  319. "id": "4890de5a",
  320. "metadata": {},
  321. "source": [
  322. "&emsp; 接着,初始化模型`model`实例,同时,使用`torch.optim.AdamW`初始化`optimizer`实例"
  323. ]
  324. },
  325. {
  326. "cell_type": "code",
  327. "execution_count": 5,
  328. "id": "9dbbf50d",
  329. "metadata": {},
  330. "outputs": [],
  331. "source": [
  332. "model = ClsByModules(vocab_size=len(vocab), embedding_dim=100, output_dim=2)\n",
  333. "\n",
  334. "from torch.optim import AdamW\n",
  335. "\n",
  336. "optimizers = AdamW(params=model.parameters(), lr=5e-5)"
  337. ]
  338. },
  339. {
  340. "cell_type": "markdown",
  341. "id": "054538f5",
  342. "metadata": {},
  343. "source": [
  344. "&emsp; 最后,使用`trainer`模块,集成`model`、`optimizer`、`dataloader`、`metric`训练"
  345. ]
  346. },
  347. {
  348. "cell_type": "code",
  349. "execution_count": 6,
  350. "id": "7a93432f",
  351. "metadata": {},
  352. "outputs": [],
  353. "source": [
  354. "from fastNLP import Trainer, Accuracy\n",
  355. "\n",
  356. "trainer = Trainer(\n",
  357. " model=model,\n",
  358. " driver='torch',\n",
  359. " device=0, # 'cuda'\n",
  360. " n_epochs=10,\n",
  361. " optimizers=optimizers,\n",
  362. " train_dataloader=train_dataloader,\n",
  363. " evaluate_dataloaders=evaluate_dataloader,\n",
  364. " metrics={'acc': Accuracy()}\n",
  365. ")"
  366. ]
  367. },
  368. {
  369. "cell_type": "code",
  370. "execution_count": 7,
  371. "id": "31102e0f",
  372. "metadata": {},
  373. "outputs": [
  374. {
  375. "data": {
  376. "text/html": [
  377. "<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\">[16:20:10] </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#596\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">596</span></a>\n",
  378. "</pre>\n"
  379. ],
  380. "text/plain": [
  381. "\u001b[2;36m[16:20:10]\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=908530;file://../fastNLP/core/controllers/trainer.py\u001b\\\u001b[2mtrainer.py\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=864197;file://../fastNLP/core/controllers/trainer.py#596\u001b\\\u001b[2m596\u001b[0m\u001b]8;;\u001b\\\n"
  382. ]
  383. },
  384. "metadata": {},
  385. "output_type": "display_data"
  386. },
  387. {
  388. "data": {
  389. "application/vnd.jupyter.widget-view+json": {
  390. "model_id": "",
  391. "version_major": 2,
  392. "version_minor": 0
  393. },
  394. "text/plain": [
  395. "Output()"
  396. ]
  397. },
  398. "metadata": {},
  399. "output_type": "display_data"
  400. },
  401. {
  402. "data": {
  403. "text/html": [
  404. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">/remote-home/xrliu/anaconda3/envs/demo/lib/python3.7/site-packages/ipywidgets/widgets/widget_\n",
  405. "output.py:111: DeprecationWarning: Kernel._parent_header is deprecated in ipykernel 6. Use \n",
  406. ".get_parent()\n",
  407. " if ip and hasattr(ip, 'kernel') and hasattr(ip.kernel, '_parent_header'):\n",
  408. "</pre>\n"
  409. ],
  410. "text/plain": [
  411. "/remote-home/xrliu/anaconda3/envs/demo/lib/python3.7/site-packages/ipywidgets/widgets/widget_\n",
  412. "output.py:111: DeprecationWarning: Kernel._parent_header is deprecated in ipykernel 6. Use \n",
  413. ".get_parent()\n",
  414. " if ip and hasattr(ip, 'kernel') and hasattr(ip.kernel, '_parent_header'):\n"
  415. ]
  416. },
  417. "metadata": {},
  418. "output_type": "display_data"
  419. },
  420. {
  421. "data": {
  422. "text/html": [
  423. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">/remote-home/xrliu/anaconda3/envs/demo/lib/python3.7/site-packages/ipywidgets/widgets/widget_\n",
  424. "output.py:112: DeprecationWarning: Kernel._parent_header is deprecated in ipykernel 6. Use \n",
  425. ".get_parent()\n",
  426. " self.msg_id = ip.kernel._parent_header['header']['msg_id']\n",
  427. "</pre>\n"
  428. ],
  429. "text/plain": [
  430. "/remote-home/xrliu/anaconda3/envs/demo/lib/python3.7/site-packages/ipywidgets/widgets/widget_\n",
  431. "output.py:112: DeprecationWarning: Kernel._parent_header is deprecated in ipykernel 6. Use \n",
  432. ".get_parent()\n",
  433. " self.msg_id = ip.kernel._parent_header['header']['msg_id']\n"
  434. ]
  435. },
  436. "metadata": {},
  437. "output_type": "display_data"
  438. },
  439. {
  440. "data": {
  441. "text/html": [
  442. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  443. ],
  444. "text/plain": []
  445. },
  446. "metadata": {},
  447. "output_type": "display_data"
  448. },
  449. {
  450. "data": {
  451. "application/vnd.jupyter.widget-view+json": {
  452. "model_id": "",
  453. "version_major": 2,
  454. "version_minor": 0
  455. },
  456. "text/plain": [
  457. "Output()"
  458. ]
  459. },
  460. "metadata": {},
  461. "output_type": "display_data"
  462. },
  463. {
  464. "data": {
  465. "text/html": [
  466. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  467. "</pre>\n"
  468. ],
  469. "text/plain": [
  470. "\n"
  471. ]
  472. },
  473. "metadata": {},
  474. "output_type": "display_data"
  475. },
  476. {
  477. "data": {
  478. "text/html": [
  479. "<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",
  480. "</pre>\n"
  481. ],
  482. "text/plain": [
  483. "----------------------------- Eval. results on Epoch:\u001b[1;36m1\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  484. ]
  485. },
  486. "metadata": {},
  487. "output_type": "display_data"
  488. },
  489. {
  490. "data": {
  491. "text/html": [
  492. "<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",
  493. " <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.525</span>,\n",
  494. " <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\">160.0</span>,\n",
  495. " <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\">84.0</span>\n",
  496. "<span style=\"font-weight: bold\">}</span>\n",
  497. "</pre>\n"
  498. ],
  499. "text/plain": [
  500. "\u001b[1m{\u001b[0m\n",
  501. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.525\u001b[0m,\n",
  502. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  503. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m84.0\u001b[0m\n",
  504. "\u001b[1m}\u001b[0m\n"
  505. ]
  506. },
  507. "metadata": {},
  508. "output_type": "display_data"
  509. },
  510. {
  511. "data": {
  512. "text/html": [
  513. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  514. "</pre>\n"
  515. ],
  516. "text/plain": [
  517. "\n"
  518. ]
  519. },
  520. "metadata": {},
  521. "output_type": "display_data"
  522. },
  523. {
  524. "data": {
  525. "text/html": [
  526. "<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",
  527. "</pre>\n"
  528. ],
  529. "text/plain": [
  530. "----------------------------- Eval. results on Epoch:\u001b[1;36m2\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  531. ]
  532. },
  533. "metadata": {},
  534. "output_type": "display_data"
  535. },
  536. {
  537. "data": {
  538. "text/html": [
  539. "<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",
  540. " <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.54375</span>,\n",
  541. " <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\">160.0</span>,\n",
  542. " <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\">87.0</span>\n",
  543. "<span style=\"font-weight: bold\">}</span>\n",
  544. "</pre>\n"
  545. ],
  546. "text/plain": [
  547. "\u001b[1m{\u001b[0m\n",
  548. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.54375\u001b[0m,\n",
  549. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  550. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m87.0\u001b[0m\n",
  551. "\u001b[1m}\u001b[0m\n"
  552. ]
  553. },
  554. "metadata": {},
  555. "output_type": "display_data"
  556. },
  557. {
  558. "data": {
  559. "text/html": [
  560. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  561. "</pre>\n"
  562. ],
  563. "text/plain": [
  564. "\n"
  565. ]
  566. },
  567. "metadata": {},
  568. "output_type": "display_data"
  569. },
  570. {
  571. "data": {
  572. "text/html": [
  573. "<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",
  574. "</pre>\n"
  575. ],
  576. "text/plain": [
  577. "----------------------------- Eval. results on Epoch:\u001b[1;36m3\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  578. ]
  579. },
  580. "metadata": {},
  581. "output_type": "display_data"
  582. },
  583. {
  584. "data": {
  585. "text/html": [
  586. "<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",
  587. " <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.55</span>,\n",
  588. " <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\">160.0</span>,\n",
  589. " <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\">88.0</span>\n",
  590. "<span style=\"font-weight: bold\">}</span>\n",
  591. "</pre>\n"
  592. ],
  593. "text/plain": [
  594. "\u001b[1m{\u001b[0m\n",
  595. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.55\u001b[0m,\n",
  596. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  597. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m88.0\u001b[0m\n",
  598. "\u001b[1m}\u001b[0m\n"
  599. ]
  600. },
  601. "metadata": {},
  602. "output_type": "display_data"
  603. },
  604. {
  605. "data": {
  606. "text/html": [
  607. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  608. "</pre>\n"
  609. ],
  610. "text/plain": [
  611. "\n"
  612. ]
  613. },
  614. "metadata": {},
  615. "output_type": "display_data"
  616. },
  617. {
  618. "data": {
  619. "text/html": [
  620. "<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",
  621. "</pre>\n"
  622. ],
  623. "text/plain": [
  624. "----------------------------- Eval. results on Epoch:\u001b[1;36m4\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  625. ]
  626. },
  627. "metadata": {},
  628. "output_type": "display_data"
  629. },
  630. {
  631. "data": {
  632. "text/html": [
  633. "<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",
  634. " <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.625</span>,\n",
  635. " <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\">160.0</span>,\n",
  636. " <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\">100.0</span>\n",
  637. "<span style=\"font-weight: bold\">}</span>\n",
  638. "</pre>\n"
  639. ],
  640. "text/plain": [
  641. "\u001b[1m{\u001b[0m\n",
  642. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.625\u001b[0m,\n",
  643. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  644. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m100.0\u001b[0m\n",
  645. "\u001b[1m}\u001b[0m\n"
  646. ]
  647. },
  648. "metadata": {},
  649. "output_type": "display_data"
  650. },
  651. {
  652. "data": {
  653. "text/html": [
  654. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  655. "</pre>\n"
  656. ],
  657. "text/plain": [
  658. "\n"
  659. ]
  660. },
  661. "metadata": {},
  662. "output_type": "display_data"
  663. },
  664. {
  665. "data": {
  666. "text/html": [
  667. "<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",
  668. "</pre>\n"
  669. ],
  670. "text/plain": [
  671. "----------------------------- Eval. results on Epoch:\u001b[1;36m5\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  672. ]
  673. },
  674. "metadata": {},
  675. "output_type": "display_data"
  676. },
  677. {
  678. "data": {
  679. "text/html": [
  680. "<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",
  681. " <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.65</span>,\n",
  682. " <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\">160.0</span>,\n",
  683. " <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\">104.0</span>\n",
  684. "<span style=\"font-weight: bold\">}</span>\n",
  685. "</pre>\n"
  686. ],
  687. "text/plain": [
  688. "\u001b[1m{\u001b[0m\n",
  689. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.65\u001b[0m,\n",
  690. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  691. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m104.0\u001b[0m\n",
  692. "\u001b[1m}\u001b[0m\n"
  693. ]
  694. },
  695. "metadata": {},
  696. "output_type": "display_data"
  697. },
  698. {
  699. "data": {
  700. "text/html": [
  701. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  702. "</pre>\n"
  703. ],
  704. "text/plain": [
  705. "\n"
  706. ]
  707. },
  708. "metadata": {},
  709. "output_type": "display_data"
  710. },
  711. {
  712. "data": {
  713. "text/html": [
  714. "<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",
  715. "</pre>\n"
  716. ],
  717. "text/plain": [
  718. "----------------------------- Eval. results on Epoch:\u001b[1;36m6\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  719. ]
  720. },
  721. "metadata": {},
  722. "output_type": "display_data"
  723. },
  724. {
  725. "data": {
  726. "text/html": [
  727. "<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",
  728. " <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.69375</span>,\n",
  729. " <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\">160.0</span>,\n",
  730. " <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\">111.0</span>\n",
  731. "<span style=\"font-weight: bold\">}</span>\n",
  732. "</pre>\n"
  733. ],
  734. "text/plain": [
  735. "\u001b[1m{\u001b[0m\n",
  736. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.69375\u001b[0m,\n",
  737. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  738. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m111.0\u001b[0m\n",
  739. "\u001b[1m}\u001b[0m\n"
  740. ]
  741. },
  742. "metadata": {},
  743. "output_type": "display_data"
  744. },
  745. {
  746. "data": {
  747. "text/html": [
  748. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  749. "</pre>\n"
  750. ],
  751. "text/plain": [
  752. "\n"
  753. ]
  754. },
  755. "metadata": {},
  756. "output_type": "display_data"
  757. },
  758. {
  759. "data": {
  760. "text/html": [
  761. "<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",
  762. "</pre>\n"
  763. ],
  764. "text/plain": [
  765. "----------------------------- Eval. results on Epoch:\u001b[1;36m7\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  766. ]
  767. },
  768. "metadata": {},
  769. "output_type": "display_data"
  770. },
  771. {
  772. "data": {
  773. "text/html": [
  774. "<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",
  775. " <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",
  776. " <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\">160.0</span>,\n",
  777. " <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\">108.0</span>\n",
  778. "<span style=\"font-weight: bold\">}</span>\n",
  779. "</pre>\n"
  780. ],
  781. "text/plain": [
  782. "\u001b[1m{\u001b[0m\n",
  783. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.675\u001b[0m,\n",
  784. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  785. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m108.0\u001b[0m\n",
  786. "\u001b[1m}\u001b[0m\n"
  787. ]
  788. },
  789. "metadata": {},
  790. "output_type": "display_data"
  791. },
  792. {
  793. "data": {
  794. "text/html": [
  795. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  796. "</pre>\n"
  797. ],
  798. "text/plain": [
  799. "\n"
  800. ]
  801. },
  802. "metadata": {},
  803. "output_type": "display_data"
  804. },
  805. {
  806. "data": {
  807. "text/html": [
  808. "<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",
  809. "</pre>\n"
  810. ],
  811. "text/plain": [
  812. "----------------------------- Eval. results on Epoch:\u001b[1;36m8\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  813. ]
  814. },
  815. "metadata": {},
  816. "output_type": "display_data"
  817. },
  818. {
  819. "data": {
  820. "text/html": [
  821. "<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",
  822. " <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.66875</span>,\n",
  823. " <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\">160.0</span>,\n",
  824. " <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\">107.0</span>\n",
  825. "<span style=\"font-weight: bold\">}</span>\n",
  826. "</pre>\n"
  827. ],
  828. "text/plain": [
  829. "\u001b[1m{\u001b[0m\n",
  830. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.66875\u001b[0m,\n",
  831. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  832. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m107.0\u001b[0m\n",
  833. "\u001b[1m}\u001b[0m\n"
  834. ]
  835. },
  836. "metadata": {},
  837. "output_type": "display_data"
  838. },
  839. {
  840. "data": {
  841. "text/html": [
  842. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  843. "</pre>\n"
  844. ],
  845. "text/plain": [
  846. "\n"
  847. ]
  848. },
  849. "metadata": {},
  850. "output_type": "display_data"
  851. },
  852. {
  853. "data": {
  854. "text/html": [
  855. "<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",
  856. "</pre>\n"
  857. ],
  858. "text/plain": [
  859. "----------------------------- Eval. results on Epoch:\u001b[1;36m9\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  860. ]
  861. },
  862. "metadata": {},
  863. "output_type": "display_data"
  864. },
  865. {
  866. "data": {
  867. "text/html": [
  868. "<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",
  869. " <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",
  870. " <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\">160.0</span>,\n",
  871. " <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\">108.0</span>\n",
  872. "<span style=\"font-weight: bold\">}</span>\n",
  873. "</pre>\n"
  874. ],
  875. "text/plain": [
  876. "\u001b[1m{\u001b[0m\n",
  877. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.675\u001b[0m,\n",
  878. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  879. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m108.0\u001b[0m\n",
  880. "\u001b[1m}\u001b[0m\n"
  881. ]
  882. },
  883. "metadata": {},
  884. "output_type": "display_data"
  885. },
  886. {
  887. "data": {
  888. "text/html": [
  889. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  890. "</pre>\n"
  891. ],
  892. "text/plain": [
  893. "\n"
  894. ]
  895. },
  896. "metadata": {},
  897. "output_type": "display_data"
  898. },
  899. {
  900. "data": {
  901. "text/html": [
  902. "<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",
  903. "</pre>\n"
  904. ],
  905. "text/plain": [
  906. "---------------------------- Eval. results on Epoch:\u001b[1;36m10\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  907. ]
  908. },
  909. "metadata": {},
  910. "output_type": "display_data"
  911. },
  912. {
  913. "data": {
  914. "text/html": [
  915. "<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",
  916. " <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.68125</span>,\n",
  917. " <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\">160.0</span>,\n",
  918. " <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\">109.0</span>\n",
  919. "<span style=\"font-weight: bold\">}</span>\n",
  920. "</pre>\n"
  921. ],
  922. "text/plain": [
  923. "\u001b[1m{\u001b[0m\n",
  924. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.68125\u001b[0m,\n",
  925. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m160.0\u001b[0m,\n",
  926. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m109.0\u001b[0m\n",
  927. "\u001b[1m}\u001b[0m\n"
  928. ]
  929. },
  930. "metadata": {},
  931. "output_type": "display_data"
  932. },
  933. {
  934. "data": {
  935. "text/html": [
  936. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  937. ],
  938. "text/plain": []
  939. },
  940. "metadata": {},
  941. "output_type": "display_data"
  942. },
  943. {
  944. "data": {
  945. "text/html": [
  946. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  947. "</pre>\n"
  948. ],
  949. "text/plain": [
  950. "\n"
  951. ]
  952. },
  953. "metadata": {},
  954. "output_type": "display_data"
  955. }
  956. ],
  957. "source": [
  958. "trainer.run(num_eval_batch_per_dl=10)"
  959. ]
  960. },
  961. {
  962. "cell_type": "code",
  963. "execution_count": 8,
  964. "id": "8bc4bfb2",
  965. "metadata": {},
  966. "outputs": [
  967. {
  968. "data": {
  969. "application/vnd.jupyter.widget-view+json": {
  970. "model_id": "",
  971. "version_major": 2,
  972. "version_minor": 0
  973. },
  974. "text/plain": [
  975. "Output()"
  976. ]
  977. },
  978. "metadata": {},
  979. "output_type": "display_data"
  980. },
  981. {
  982. "data": {
  983. "text/html": [
  984. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  985. ],
  986. "text/plain": []
  987. },
  988. "metadata": {},
  989. "output_type": "display_data"
  990. },
  991. {
  992. "data": {
  993. "text/plain": [
  994. "{'acc#acc': 0.712222, 'total#acc': 900.0, 'correct#acc': 641.0}"
  995. ]
  996. },
  997. "execution_count": 8,
  998. "metadata": {},
  999. "output_type": "execute_result"
  1000. }
  1001. ],
  1002. "source": [
  1003. "trainer.evaluator.run()"
  1004. ]
  1005. },
  1006. {
  1007. "cell_type": "markdown",
  1008. "id": "07538876",
  1009. "metadata": {},
  1010. "source": [
  1011. "&emsp; 注:此处使用`gc`模块删除相关变量,释放内存,为接下来新的模型训练预留存储空间,下同"
  1012. ]
  1013. },
  1014. {
  1015. "cell_type": "code",
  1016. "execution_count": 9,
  1017. "id": "1b52eafd",
  1018. "metadata": {},
  1019. "outputs": [
  1020. {
  1021. "data": {
  1022. "text/plain": [
  1023. "383"
  1024. ]
  1025. },
  1026. "execution_count": 9,
  1027. "metadata": {},
  1028. "output_type": "execute_result"
  1029. }
  1030. ],
  1031. "source": [
  1032. "import gc\n",
  1033. "\n",
  1034. "del model\n",
  1035. "del trainer\n",
  1036. "del dataset\n",
  1037. "del sst2data\n",
  1038. "\n",
  1039. "gc.collect()"
  1040. ]
  1041. },
  1042. {
  1043. "cell_type": "markdown",
  1044. "id": "d9443213",
  1045. "metadata": {},
  1046. "source": [
  1047. "## 2. fastNLP 中 models 模块的介绍\n",
  1048. "\n",
  1049. "### 2.1 示例一:models 实现 CNN 分类\n",
  1050. "\n",
  1051. "&emsp; 本示例使用`fastNLP 0.8`中预定义模型`models`中的`CNNText`模型,实现`SST-2`文本二分类任务\n",
  1052. "\n",
  1053. "数据使用方面,此处沿用在上个示例中展示的`SST-2`数据集,数据加载过程相同且已经执行过了,因此简略\n",
  1054. "\n",
  1055. "模型使用方面,如上所述,这里使用**基于卷积神经网络`CNN`的预定义文本分类模型`CNNText`**,结构如下所示\n",
  1056. "\n",
  1057. "&emsp; 首先是内置的`100`维嵌入层、`dropout`层、紧接着是三个一维卷积,将`100`维嵌入特征,分别通过\n",
  1058. "\n",
  1059. "&emsp; &emsp; **感受野为`1`、`3`、`5`的卷积算子变换至`30`维、`40`维、`50`维的卷积特征**,再将三者拼接\n",
  1060. "\n",
  1061. "&emsp; 最终再次通过`dropout`层、线性变换层,映射至二元的输出值,对应两个分类结果上的几率`logits`\n",
  1062. "\n",
  1063. "```\n",
  1064. "CNNText(\n",
  1065. " (embed): Embedding(\n",
  1066. " (embed): Embedding(5194, 100)\n",
  1067. " (dropout): Dropout(p=0.0, inplace=False)\n",
  1068. " )\n",
  1069. " (conv_pool): ConvMaxpool(\n",
  1070. " (convs): ModuleList(\n",
  1071. " (0): Conv1d(100, 30, kernel_size=(1,), stride=(1,), bias=False)\n",
  1072. " (1): Conv1d(100, 40, kernel_size=(3,), stride=(1,), padding=(1,), bias=False)\n",
  1073. " (2): Conv1d(100, 50, kernel_size=(5,), stride=(1,), padding=(2,), bias=False)\n",
  1074. " )\n",
  1075. " )\n",
  1076. " (dropout): Dropout(p=0.1, inplace=False)\n",
  1077. " (fc): Linear(in_features=120, out_features=2, bias=True)\n",
  1078. ")\n",
  1079. "```\n",
  1080. "\n",
  1081. "对应到代码上,**从`fastNLP.models.torch`路径下导入`CNNText`**,初始化`CNNText`和`optimizer`实例\n",
  1082. "\n",
  1083. "&emsp; 注意:初始化`CNNText`时,**二元组参数`embed`、分类数量`num_classes`是必须传入的**,其中\n",
  1084. "\n",
  1085. "&emsp; &emsp; **`embed`表示嵌入层的嵌入抽取矩阵大小**,因此第二个元素对应的是默认隐藏层维度 `100`维"
  1086. ]
  1087. },
  1088. {
  1089. "cell_type": "code",
  1090. "execution_count": 10,
  1091. "id": "f6e76e2e",
  1092. "metadata": {},
  1093. "outputs": [],
  1094. "source": [
  1095. "from fastNLP.models.torch import CNNText\n",
  1096. "\n",
  1097. "model = CNNText(embed=(len(vocab), 100), num_classes=2, dropout=0.1)\n",
  1098. "\n",
  1099. "from torch.optim import AdamW\n",
  1100. "\n",
  1101. "optimizers = AdamW(params=model.parameters(), lr=5e-4)"
  1102. ]
  1103. },
  1104. {
  1105. "cell_type": "markdown",
  1106. "id": "0cc5ca10",
  1107. "metadata": {},
  1108. "source": [
  1109. "&emsp; 最后,使用`trainer`模块,集成`model`、`optimizer`、`dataloader`、`metric`训练"
  1110. ]
  1111. },
  1112. {
  1113. "cell_type": "code",
  1114. "execution_count": 11,
  1115. "id": "50a13ee5",
  1116. "metadata": {},
  1117. "outputs": [],
  1118. "source": [
  1119. "from fastNLP import Trainer, Accuracy\n",
  1120. "\n",
  1121. "trainer = Trainer(\n",
  1122. " model=model,\n",
  1123. " driver='torch',\n",
  1124. " device=0, # 'cuda'\n",
  1125. " n_epochs=10,\n",
  1126. " optimizers=optimizers,\n",
  1127. " train_dataloader=train_dataloader,\n",
  1128. " evaluate_dataloaders=evaluate_dataloader,\n",
  1129. " metrics={'acc': Accuracy()}\n",
  1130. ")"
  1131. ]
  1132. },
  1133. {
  1134. "cell_type": "code",
  1135. "execution_count": 12,
  1136. "id": "28903a7d",
  1137. "metadata": {},
  1138. "outputs": [
  1139. {
  1140. "data": {
  1141. "text/html": [
  1142. "<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\">[16:21:57] </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#596\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">596</span></a>\n",
  1143. "</pre>\n"
  1144. ],
  1145. "text/plain": [
  1146. "\u001b[2;36m[16:21:57]\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=813103;file://../fastNLP/core/controllers/trainer.py\u001b\\\u001b[2mtrainer.py\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=271516;file://../fastNLP/core/controllers/trainer.py#596\u001b\\\u001b[2m596\u001b[0m\u001b]8;;\u001b\\\n"
  1147. ]
  1148. },
  1149. "metadata": {},
  1150. "output_type": "display_data"
  1151. },
  1152. {
  1153. "data": {
  1154. "application/vnd.jupyter.widget-view+json": {
  1155. "model_id": "",
  1156. "version_major": 2,
  1157. "version_minor": 0
  1158. },
  1159. "text/plain": [
  1160. "Output()"
  1161. ]
  1162. },
  1163. "metadata": {},
  1164. "output_type": "display_data"
  1165. },
  1166. {
  1167. "data": {
  1168. "text/html": [
  1169. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  1170. ],
  1171. "text/plain": []
  1172. },
  1173. "metadata": {},
  1174. "output_type": "display_data"
  1175. },
  1176. {
  1177. "data": {
  1178. "application/vnd.jupyter.widget-view+json": {
  1179. "model_id": "",
  1180. "version_major": 2,
  1181. "version_minor": 0
  1182. },
  1183. "text/plain": [
  1184. "Output()"
  1185. ]
  1186. },
  1187. "metadata": {},
  1188. "output_type": "display_data"
  1189. },
  1190. {
  1191. "data": {
  1192. "text/html": [
  1193. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1194. "</pre>\n"
  1195. ],
  1196. "text/plain": [
  1197. "\n"
  1198. ]
  1199. },
  1200. "metadata": {},
  1201. "output_type": "display_data"
  1202. },
  1203. {
  1204. "data": {
  1205. "text/html": [
  1206. "<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",
  1207. "</pre>\n"
  1208. ],
  1209. "text/plain": [
  1210. "----------------------------- Eval. results on Epoch:\u001b[1;36m1\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1211. ]
  1212. },
  1213. "metadata": {},
  1214. "output_type": "display_data"
  1215. },
  1216. {
  1217. "data": {
  1218. "text/html": [
  1219. "<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",
  1220. " <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.654444</span>,\n",
  1221. " <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\">900.0</span>,\n",
  1222. " <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\">589.0</span>\n",
  1223. "<span style=\"font-weight: bold\">}</span>\n",
  1224. "</pre>\n"
  1225. ],
  1226. "text/plain": [
  1227. "\u001b[1m{\u001b[0m\n",
  1228. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.654444\u001b[0m,\n",
  1229. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1230. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m589.0\u001b[0m\n",
  1231. "\u001b[1m}\u001b[0m\n"
  1232. ]
  1233. },
  1234. "metadata": {},
  1235. "output_type": "display_data"
  1236. },
  1237. {
  1238. "data": {
  1239. "text/html": [
  1240. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1241. "</pre>\n"
  1242. ],
  1243. "text/plain": [
  1244. "\n"
  1245. ]
  1246. },
  1247. "metadata": {},
  1248. "output_type": "display_data"
  1249. },
  1250. {
  1251. "data": {
  1252. "text/html": [
  1253. "<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",
  1254. "</pre>\n"
  1255. ],
  1256. "text/plain": [
  1257. "----------------------------- Eval. results on Epoch:\u001b[1;36m2\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1258. ]
  1259. },
  1260. "metadata": {},
  1261. "output_type": "display_data"
  1262. },
  1263. {
  1264. "data": {
  1265. "text/html": [
  1266. "<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",
  1267. " <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.767778</span>,\n",
  1268. " <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\">900.0</span>,\n",
  1269. " <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\">691.0</span>\n",
  1270. "<span style=\"font-weight: bold\">}</span>\n",
  1271. "</pre>\n"
  1272. ],
  1273. "text/plain": [
  1274. "\u001b[1m{\u001b[0m\n",
  1275. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.767778\u001b[0m,\n",
  1276. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1277. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m691.0\u001b[0m\n",
  1278. "\u001b[1m}\u001b[0m\n"
  1279. ]
  1280. },
  1281. "metadata": {},
  1282. "output_type": "display_data"
  1283. },
  1284. {
  1285. "data": {
  1286. "text/html": [
  1287. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1288. "</pre>\n"
  1289. ],
  1290. "text/plain": [
  1291. "\n"
  1292. ]
  1293. },
  1294. "metadata": {},
  1295. "output_type": "display_data"
  1296. },
  1297. {
  1298. "data": {
  1299. "text/html": [
  1300. "<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",
  1301. "</pre>\n"
  1302. ],
  1303. "text/plain": [
  1304. "----------------------------- Eval. results on Epoch:\u001b[1;36m3\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1305. ]
  1306. },
  1307. "metadata": {},
  1308. "output_type": "display_data"
  1309. },
  1310. {
  1311. "data": {
  1312. "text/html": [
  1313. "<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",
  1314. " <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.797778</span>,\n",
  1315. " <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\">900.0</span>,\n",
  1316. " <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\">718.0</span>\n",
  1317. "<span style=\"font-weight: bold\">}</span>\n",
  1318. "</pre>\n"
  1319. ],
  1320. "text/plain": [
  1321. "\u001b[1m{\u001b[0m\n",
  1322. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.797778\u001b[0m,\n",
  1323. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1324. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m718.0\u001b[0m\n",
  1325. "\u001b[1m}\u001b[0m\n"
  1326. ]
  1327. },
  1328. "metadata": {},
  1329. "output_type": "display_data"
  1330. },
  1331. {
  1332. "data": {
  1333. "text/html": [
  1334. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1335. "</pre>\n"
  1336. ],
  1337. "text/plain": [
  1338. "\n"
  1339. ]
  1340. },
  1341. "metadata": {},
  1342. "output_type": "display_data"
  1343. },
  1344. {
  1345. "data": {
  1346. "text/html": [
  1347. "<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",
  1348. "</pre>\n"
  1349. ],
  1350. "text/plain": [
  1351. "----------------------------- Eval. results on Epoch:\u001b[1;36m4\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1352. ]
  1353. },
  1354. "metadata": {},
  1355. "output_type": "display_data"
  1356. },
  1357. {
  1358. "data": {
  1359. "text/html": [
  1360. "<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",
  1361. " <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.803333</span>,\n",
  1362. " <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\">900.0</span>,\n",
  1363. " <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\">723.0</span>\n",
  1364. "<span style=\"font-weight: bold\">}</span>\n",
  1365. "</pre>\n"
  1366. ],
  1367. "text/plain": [
  1368. "\u001b[1m{\u001b[0m\n",
  1369. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.803333\u001b[0m,\n",
  1370. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1371. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m723.0\u001b[0m\n",
  1372. "\u001b[1m}\u001b[0m\n"
  1373. ]
  1374. },
  1375. "metadata": {},
  1376. "output_type": "display_data"
  1377. },
  1378. {
  1379. "data": {
  1380. "text/html": [
  1381. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1382. "</pre>\n"
  1383. ],
  1384. "text/plain": [
  1385. "\n"
  1386. ]
  1387. },
  1388. "metadata": {},
  1389. "output_type": "display_data"
  1390. },
  1391. {
  1392. "data": {
  1393. "text/html": [
  1394. "<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",
  1395. "</pre>\n"
  1396. ],
  1397. "text/plain": [
  1398. "----------------------------- Eval. results on Epoch:\u001b[1;36m5\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1399. ]
  1400. },
  1401. "metadata": {},
  1402. "output_type": "display_data"
  1403. },
  1404. {
  1405. "data": {
  1406. "text/html": [
  1407. "<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",
  1408. " <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.807778</span>,\n",
  1409. " <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\">900.0</span>,\n",
  1410. " <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\">727.0</span>\n",
  1411. "<span style=\"font-weight: bold\">}</span>\n",
  1412. "</pre>\n"
  1413. ],
  1414. "text/plain": [
  1415. "\u001b[1m{\u001b[0m\n",
  1416. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.807778\u001b[0m,\n",
  1417. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1418. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m727.0\u001b[0m\n",
  1419. "\u001b[1m}\u001b[0m\n"
  1420. ]
  1421. },
  1422. "metadata": {},
  1423. "output_type": "display_data"
  1424. },
  1425. {
  1426. "data": {
  1427. "text/html": [
  1428. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1429. "</pre>\n"
  1430. ],
  1431. "text/plain": [
  1432. "\n"
  1433. ]
  1434. },
  1435. "metadata": {},
  1436. "output_type": "display_data"
  1437. },
  1438. {
  1439. "data": {
  1440. "text/html": [
  1441. "<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",
  1442. "</pre>\n"
  1443. ],
  1444. "text/plain": [
  1445. "----------------------------- Eval. results on Epoch:\u001b[1;36m6\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1446. ]
  1447. },
  1448. "metadata": {},
  1449. "output_type": "display_data"
  1450. },
  1451. {
  1452. "data": {
  1453. "text/html": [
  1454. "<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",
  1455. " <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.812222</span>,\n",
  1456. " <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\">900.0</span>,\n",
  1457. " <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\">731.0</span>\n",
  1458. "<span style=\"font-weight: bold\">}</span>\n",
  1459. "</pre>\n"
  1460. ],
  1461. "text/plain": [
  1462. "\u001b[1m{\u001b[0m\n",
  1463. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.812222\u001b[0m,\n",
  1464. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1465. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m731.0\u001b[0m\n",
  1466. "\u001b[1m}\u001b[0m\n"
  1467. ]
  1468. },
  1469. "metadata": {},
  1470. "output_type": "display_data"
  1471. },
  1472. {
  1473. "data": {
  1474. "text/html": [
  1475. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1476. "</pre>\n"
  1477. ],
  1478. "text/plain": [
  1479. "\n"
  1480. ]
  1481. },
  1482. "metadata": {},
  1483. "output_type": "display_data"
  1484. },
  1485. {
  1486. "data": {
  1487. "text/html": [
  1488. "<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",
  1489. "</pre>\n"
  1490. ],
  1491. "text/plain": [
  1492. "----------------------------- Eval. results on Epoch:\u001b[1;36m7\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1493. ]
  1494. },
  1495. "metadata": {},
  1496. "output_type": "display_data"
  1497. },
  1498. {
  1499. "data": {
  1500. "text/html": [
  1501. "<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",
  1502. " <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.804444</span>,\n",
  1503. " <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\">900.0</span>,\n",
  1504. " <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\">724.0</span>\n",
  1505. "<span style=\"font-weight: bold\">}</span>\n",
  1506. "</pre>\n"
  1507. ],
  1508. "text/plain": [
  1509. "\u001b[1m{\u001b[0m\n",
  1510. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.804444\u001b[0m,\n",
  1511. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1512. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m724.0\u001b[0m\n",
  1513. "\u001b[1m}\u001b[0m\n"
  1514. ]
  1515. },
  1516. "metadata": {},
  1517. "output_type": "display_data"
  1518. },
  1519. {
  1520. "data": {
  1521. "text/html": [
  1522. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1523. "</pre>\n"
  1524. ],
  1525. "text/plain": [
  1526. "\n"
  1527. ]
  1528. },
  1529. "metadata": {},
  1530. "output_type": "display_data"
  1531. },
  1532. {
  1533. "data": {
  1534. "text/html": [
  1535. "<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",
  1536. "</pre>\n"
  1537. ],
  1538. "text/plain": [
  1539. "----------------------------- Eval. results on Epoch:\u001b[1;36m8\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1540. ]
  1541. },
  1542. "metadata": {},
  1543. "output_type": "display_data"
  1544. },
  1545. {
  1546. "data": {
  1547. "text/html": [
  1548. "<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",
  1549. " <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.811111</span>,\n",
  1550. " <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\">900.0</span>,\n",
  1551. " <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\">730.0</span>\n",
  1552. "<span style=\"font-weight: bold\">}</span>\n",
  1553. "</pre>\n"
  1554. ],
  1555. "text/plain": [
  1556. "\u001b[1m{\u001b[0m\n",
  1557. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.811111\u001b[0m,\n",
  1558. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1559. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m730.0\u001b[0m\n",
  1560. "\u001b[1m}\u001b[0m\n"
  1561. ]
  1562. },
  1563. "metadata": {},
  1564. "output_type": "display_data"
  1565. },
  1566. {
  1567. "data": {
  1568. "text/html": [
  1569. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1570. "</pre>\n"
  1571. ],
  1572. "text/plain": [
  1573. "\n"
  1574. ]
  1575. },
  1576. "metadata": {},
  1577. "output_type": "display_data"
  1578. },
  1579. {
  1580. "data": {
  1581. "text/html": [
  1582. "<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",
  1583. "</pre>\n"
  1584. ],
  1585. "text/plain": [
  1586. "----------------------------- Eval. results on Epoch:\u001b[1;36m9\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1587. ]
  1588. },
  1589. "metadata": {},
  1590. "output_type": "display_data"
  1591. },
  1592. {
  1593. "data": {
  1594. "text/html": [
  1595. "<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",
  1596. " <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.811111</span>,\n",
  1597. " <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\">900.0</span>,\n",
  1598. " <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\">730.0</span>\n",
  1599. "<span style=\"font-weight: bold\">}</span>\n",
  1600. "</pre>\n"
  1601. ],
  1602. "text/plain": [
  1603. "\u001b[1m{\u001b[0m\n",
  1604. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.811111\u001b[0m,\n",
  1605. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1606. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m730.0\u001b[0m\n",
  1607. "\u001b[1m}\u001b[0m\n"
  1608. ]
  1609. },
  1610. "metadata": {},
  1611. "output_type": "display_data"
  1612. },
  1613. {
  1614. "data": {
  1615. "text/html": [
  1616. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1617. "</pre>\n"
  1618. ],
  1619. "text/plain": [
  1620. "\n"
  1621. ]
  1622. },
  1623. "metadata": {},
  1624. "output_type": "display_data"
  1625. },
  1626. {
  1627. "data": {
  1628. "text/html": [
  1629. "<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",
  1630. "</pre>\n"
  1631. ],
  1632. "text/plain": [
  1633. "---------------------------- Eval. results on Epoch:\u001b[1;36m10\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  1634. ]
  1635. },
  1636. "metadata": {},
  1637. "output_type": "display_data"
  1638. },
  1639. {
  1640. "data": {
  1641. "text/html": [
  1642. "<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",
  1643. " <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.806667</span>,\n",
  1644. " <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\">900.0</span>,\n",
  1645. " <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\">726.0</span>\n",
  1646. "<span style=\"font-weight: bold\">}</span>\n",
  1647. "</pre>\n"
  1648. ],
  1649. "text/plain": [
  1650. "\u001b[1m{\u001b[0m\n",
  1651. " \u001b[1;34m\"acc#acc\"\u001b[0m: \u001b[1;36m0.806667\u001b[0m,\n",
  1652. " \u001b[1;34m\"total#acc\"\u001b[0m: \u001b[1;36m900.0\u001b[0m,\n",
  1653. " \u001b[1;34m\"correct#acc\"\u001b[0m: \u001b[1;36m726.0\u001b[0m\n",
  1654. "\u001b[1m}\u001b[0m\n"
  1655. ]
  1656. },
  1657. "metadata": {},
  1658. "output_type": "display_data"
  1659. },
  1660. {
  1661. "data": {
  1662. "text/html": [
  1663. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  1664. ],
  1665. "text/plain": []
  1666. },
  1667. "metadata": {},
  1668. "output_type": "display_data"
  1669. },
  1670. {
  1671. "data": {
  1672. "text/html": [
  1673. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  1674. "</pre>\n"
  1675. ],
  1676. "text/plain": [
  1677. "\n"
  1678. ]
  1679. },
  1680. "metadata": {},
  1681. "output_type": "display_data"
  1682. }
  1683. ],
  1684. "source": [
  1685. "trainer.run()"
  1686. ]
  1687. },
  1688. {
  1689. "cell_type": "code",
  1690. "execution_count": 13,
  1691. "id": "f47a6a35",
  1692. "metadata": {},
  1693. "outputs": [
  1694. {
  1695. "data": {
  1696. "application/vnd.jupyter.widget-view+json": {
  1697. "model_id": "",
  1698. "version_major": 2,
  1699. "version_minor": 0
  1700. },
  1701. "text/plain": [
  1702. "Output()"
  1703. ]
  1704. },
  1705. "metadata": {},
  1706. "output_type": "display_data"
  1707. },
  1708. {
  1709. "data": {
  1710. "text/html": [
  1711. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  1712. ],
  1713. "text/plain": []
  1714. },
  1715. "metadata": {},
  1716. "output_type": "display_data"
  1717. },
  1718. {
  1719. "data": {
  1720. "text/plain": [
  1721. "{'acc#acc': 0.806667, 'total#acc': 900.0, 'correct#acc': 726.0}"
  1722. ]
  1723. },
  1724. "execution_count": 13,
  1725. "metadata": {},
  1726. "output_type": "execute_result"
  1727. }
  1728. ],
  1729. "source": [
  1730. "trainer.evaluator.run()"
  1731. ]
  1732. },
  1733. {
  1734. "cell_type": "markdown",
  1735. "id": "5b5c0446",
  1736. "metadata": {},
  1737. "source": [
  1738. "&emsp; 注:此处使用`gc`模块删除相关变量,释放内存,为接下来新的模型训练预留存储空间,下同"
  1739. ]
  1740. },
  1741. {
  1742. "cell_type": "code",
  1743. "execution_count": 14,
  1744. "id": "e9e70f88",
  1745. "metadata": {},
  1746. "outputs": [
  1747. {
  1748. "data": {
  1749. "text/plain": [
  1750. "344"
  1751. ]
  1752. },
  1753. "execution_count": 14,
  1754. "metadata": {},
  1755. "output_type": "execute_result"
  1756. }
  1757. ],
  1758. "source": [
  1759. "import gc\n",
  1760. "\n",
  1761. "del model\n",
  1762. "del trainer\n",
  1763. "\n",
  1764. "gc.collect()"
  1765. ]
  1766. },
  1767. {
  1768. "cell_type": "markdown",
  1769. "id": "6aec2a19",
  1770. "metadata": {},
  1771. "source": [
  1772. "### 2.2 示例二:models 实现 BiLSTM 标注\n",
  1773. "\n",
  1774. "&emsp; 通过两个示例一的对比可以发现,得益于`models`对模型结构的封装,使用`models`明显更加便捷\n",
  1775. "\n",
  1776. "&emsp; &emsp; 针对更加复杂的模型时,编码更加轻松;本示例将使用`models`中的`BiLSTMCRF`模型\n",
  1777. "\n",
  1778. "&emsp; 避免`CRF`和`Viterbi`算法代码书写的困难,轻松实现`CoNLL-2003`中的命名实体识别`NER`任务\n",
  1779. "\n",
  1780. "模型使用方面,如上所述,这里使用**基于双向`LSTM`+条件随机场`CRF`的标注模型`BiLSTMCRF`**,结构如下所示\n",
  1781. "\n",
  1782. "&emsp; 其中,隐藏层维度默认`100`维,因此对应双向`LSTM`输出`200`维,`dropout`层退学概率、`LSTM`层数可调\n",
  1783. "\n",
  1784. "```\n",
  1785. "BiLSTMCRF(\n",
  1786. " (embed): Embedding(7590, 100)\n",
  1787. " (lstm): LSTM(\n",
  1788. " (lstm): LSTM(100, 100, batch_first=True, bidirectional=True)\n",
  1789. " )\n",
  1790. " (dropout): Dropout(p=0.1, inplace=False)\n",
  1791. " (fc): Linear(in_features=200, out_features=9, bias=True)\n",
  1792. " (crf): ConditionalRandomField()\n",
  1793. ")\n",
  1794. "```\n",
  1795. "\n",
  1796. "数据使用方面,此处仍然**使用`datasets`模块中的`load_dataset`函数**,以如下形式,加载`CoNLL-2003`数据集\n",
  1797. "\n",
  1798. "&emsp; 首次下载后会保存至`~.cache/huggingface/datasets/conll2003/conll2003/1.0.0/`目录下"
  1799. ]
  1800. },
  1801. {
  1802. "cell_type": "code",
  1803. "execution_count": 15,
  1804. "id": "03e66686",
  1805. "metadata": {},
  1806. "outputs": [
  1807. {
  1808. "name": "stderr",
  1809. "output_type": "stream",
  1810. "text": [
  1811. "Reusing dataset conll2003 (/remote-home/xrliu/.cache/huggingface/datasets/conll2003/conll2003/1.0.0/63f4ebd1bcb7148b1644497336fd74643d4ce70123334431a3c053b7ee4e96ee)\n"
  1812. ]
  1813. },
  1814. {
  1815. "data": {
  1816. "application/vnd.jupyter.widget-view+json": {
  1817. "model_id": "593bc03ed5914953ab94268ff2f01710",
  1818. "version_major": 2,
  1819. "version_minor": 0
  1820. },
  1821. "text/plain": [
  1822. " 0%| | 0/3 [00:00<?, ?it/s]"
  1823. ]
  1824. },
  1825. "metadata": {},
  1826. "output_type": "display_data"
  1827. }
  1828. ],
  1829. "source": [
  1830. "from datasets import load_dataset\n",
  1831. "\n",
  1832. "ner2data = load_dataset('conll2003', 'conll2003')"
  1833. ]
  1834. },
  1835. {
  1836. "cell_type": "markdown",
  1837. "id": "fc505631",
  1838. "metadata": {},
  1839. "source": [
  1840. "紧接着,使用`tutorial-1`和`tutorial-2`中的知识,将数据集转化为`fastNLP`中的`DataSet`格式\n",
  1841. "\n",
  1842. "&emsp; 完成数据集格式调整、文本序列化等操作;此处**需要`'words'`、`'seq_len'`、`'target'`三个字段**\n",
  1843. "\n",
  1844. "此外,**需要定义`NER`标签到标签序号的映射**(**词汇表`label_vocab`**),数据集中标签已经完成了序号映射\n",
  1845. "\n",
  1846. "&emsp; 所以需要人工定义**`9`个标签对应之前的`9`个分类目标**;数据集说明中规定,`'O'`表示其他标签\n",
  1847. "\n",
  1848. "&emsp; **后缀`'-PER'`、`'-ORG'`、`'-LOC'`、`'-MISC'`对应人名、组织名、地名、时间等其他命名**\n",
  1849. "\n",
  1850. "&emsp; **前缀`'B-'`表示起始标签、`'I-'`表示终止标签**;例如,`'B-PER'`表示人名实体的起始标签"
  1851. ]
  1852. },
  1853. {
  1854. "cell_type": "code",
  1855. "execution_count": 16,
  1856. "id": "1f88cad4",
  1857. "metadata": {},
  1858. "outputs": [
  1859. {
  1860. "data": {
  1861. "application/vnd.jupyter.widget-view+json": {
  1862. "model_id": "",
  1863. "version_major": 2,
  1864. "version_minor": 0
  1865. },
  1866. "text/plain": [
  1867. "Processing: 0%| | 0/4000 [00:00<?, ?it/s]"
  1868. ]
  1869. },
  1870. "metadata": {},
  1871. "output_type": "display_data"
  1872. }
  1873. ],
  1874. "source": [
  1875. "import sys\n",
  1876. "sys.path.append('..')\n",
  1877. "\n",
  1878. "from fastNLP import DataSet\n",
  1879. "\n",
  1880. "dataset = DataSet.from_pandas(ner2data['train'].to_pandas())[:4000]\n",
  1881. "\n",
  1882. "dataset.apply_more(lambda ins:{'words': ins['tokens'], 'seq_len': len(ins['tokens']), 'target': ins['ner_tags']}, \n",
  1883. " progress_bar=\"tqdm\")\n",
  1884. "dataset.delete_field('tokens')\n",
  1885. "dataset.delete_field('ner_tags')\n",
  1886. "dataset.delete_field('pos_tags')\n",
  1887. "dataset.delete_field('chunk_tags')\n",
  1888. "dataset.delete_field('id')\n",
  1889. "\n",
  1890. "from fastNLP import Vocabulary\n",
  1891. "\n",
  1892. "token_vocab = Vocabulary()\n",
  1893. "token_vocab.from_dataset(dataset, field_name='words')\n",
  1894. "token_vocab.index_dataset(dataset, field_name='words')\n",
  1895. "label_vocab = Vocabulary(padding=None, unknown=None)\n",
  1896. "label_vocab.add_word_lst(['O', 'B-PER', 'I-PER', 'B-ORG', 'I-ORG', 'B-LOC', 'I-LOC', 'B-MISC', 'I-MISC'])\n",
  1897. "\n",
  1898. "train_dataset, evaluate_dataset = dataset.split(ratio=0.85)"
  1899. ]
  1900. },
  1901. {
  1902. "cell_type": "markdown",
  1903. "id": "d9889427",
  1904. "metadata": {},
  1905. "source": [
  1906. "然后,同样使用`tutorial-3`中的知识,通过`prepare_torch_dataloader`处理数据集得到`dataloader`"
  1907. ]
  1908. },
  1909. {
  1910. "cell_type": "code",
  1911. "execution_count": 17,
  1912. "id": "7802a072",
  1913. "metadata": {},
  1914. "outputs": [],
  1915. "source": [
  1916. "from fastNLP import prepare_torch_dataloader\n",
  1917. "\n",
  1918. "train_dataloader = prepare_torch_dataloader(train_dataset, batch_size=16, shuffle=True)\n",
  1919. "evaluate_dataloader = prepare_torch_dataloader(evaluate_dataset, batch_size=16)"
  1920. ]
  1921. },
  1922. {
  1923. "cell_type": "markdown",
  1924. "id": "2bc7831b",
  1925. "metadata": {},
  1926. "source": [
  1927. "接着,**从`fastNLP.models.torch`路径下导入`BiLSTMCRF`**,初始化`BiLSTMCRF`实例和优化器\n",
  1928. "\n",
  1929. "&emsp; 注意:初始化`BiLSTMCRF`时,和`CNNText`相同,**参数`embed`、`num_classes`是必须传入的**\n",
  1930. "\n",
  1931. "&emsp; &emsp; 隐藏层维度`hidden_size`默认`100`维,调整`150`维;退学概率默认`0.1`,调整`0.2`"
  1932. ]
  1933. },
  1934. {
  1935. "cell_type": "code",
  1936. "execution_count": 18,
  1937. "id": "4e12c09f",
  1938. "metadata": {},
  1939. "outputs": [],
  1940. "source": [
  1941. "from fastNLP.models.torch import BiLSTMCRF\n",
  1942. "\n",
  1943. "model = BiLSTMCRF(embed=(len(token_vocab), 150), num_classes=len(label_vocab), \n",
  1944. " num_layers=1, hidden_size=150, dropout=0.2)\n",
  1945. "\n",
  1946. "from torch.optim import AdamW\n",
  1947. "\n",
  1948. "optimizers = AdamW(params=model.parameters(), lr=1e-3)"
  1949. ]
  1950. },
  1951. {
  1952. "cell_type": "markdown",
  1953. "id": "bf30608f",
  1954. "metadata": {},
  1955. "source": [
  1956. "最后,使用`trainer`模块,集成`model`、`optimizer`、`dataloader`、`metric`训练\n",
  1957. "\n",
  1958. "&emsp; **使用`SpanFPreRecMetric`作为`NER`的评价标准**,详细请参考接下来的`tutorial-5`\n",
  1959. "\n",
  1960. "&emsp; 同时,**初始化时需要添加`vocabulary`形式的标签与序号之间的映射`tag_vocab`**"
  1961. ]
  1962. },
  1963. {
  1964. "cell_type": "code",
  1965. "execution_count": 19,
  1966. "id": "cbd6c205",
  1967. "metadata": {},
  1968. "outputs": [],
  1969. "source": [
  1970. "from fastNLP import Trainer, SpanFPreRecMetric\n",
  1971. "\n",
  1972. "trainer = Trainer(\n",
  1973. " model=model,\n",
  1974. " driver='torch',\n",
  1975. " device=0, # 'cuda'\n",
  1976. " n_epochs=10,\n",
  1977. " optimizers=optimizers,\n",
  1978. " train_dataloader=train_dataloader,\n",
  1979. " evaluate_dataloaders=evaluate_dataloader,\n",
  1980. " metrics={'F1': SpanFPreRecMetric(tag_vocab=label_vocab)}\n",
  1981. ")"
  1982. ]
  1983. },
  1984. {
  1985. "cell_type": "code",
  1986. "execution_count": 20,
  1987. "id": "0f8eff34",
  1988. "metadata": {},
  1989. "outputs": [
  1990. {
  1991. "data": {
  1992. "text/html": [
  1993. "<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\">[16:23:41] </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#596\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">596</span></a>\n",
  1994. "</pre>\n"
  1995. ],
  1996. "text/plain": [
  1997. "\u001b[2;36m[16:23:41]\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=565652;file://../fastNLP/core/controllers/trainer.py\u001b\\\u001b[2mtrainer.py\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=224849;file://../fastNLP/core/controllers/trainer.py#596\u001b\\\u001b[2m596\u001b[0m\u001b]8;;\u001b\\\n"
  1998. ]
  1999. },
  2000. "metadata": {},
  2001. "output_type": "display_data"
  2002. },
  2003. {
  2004. "data": {
  2005. "application/vnd.jupyter.widget-view+json": {
  2006. "model_id": "",
  2007. "version_major": 2,
  2008. "version_minor": 0
  2009. },
  2010. "text/plain": [
  2011. "Output()"
  2012. ]
  2013. },
  2014. "metadata": {},
  2015. "output_type": "display_data"
  2016. },
  2017. {
  2018. "data": {
  2019. "text/html": [
  2020. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  2021. ],
  2022. "text/plain": []
  2023. },
  2024. "metadata": {},
  2025. "output_type": "display_data"
  2026. },
  2027. {
  2028. "data": {
  2029. "application/vnd.jupyter.widget-view+json": {
  2030. "model_id": "",
  2031. "version_major": 2,
  2032. "version_minor": 0
  2033. },
  2034. "text/plain": [
  2035. "Output()"
  2036. ]
  2037. },
  2038. "metadata": {},
  2039. "output_type": "display_data"
  2040. },
  2041. {
  2042. "data": {
  2043. "text/html": [
  2044. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2045. "</pre>\n"
  2046. ],
  2047. "text/plain": [
  2048. "\n"
  2049. ]
  2050. },
  2051. "metadata": {},
  2052. "output_type": "display_data"
  2053. },
  2054. {
  2055. "data": {
  2056. "text/html": [
  2057. "<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",
  2058. "</pre>\n"
  2059. ],
  2060. "text/plain": [
  2061. "----------------------------- Eval. results on Epoch:\u001b[1;36m1\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2062. ]
  2063. },
  2064. "metadata": {},
  2065. "output_type": "display_data"
  2066. },
  2067. {
  2068. "data": {
  2069. "text/html": [
  2070. "<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",
  2071. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.169014</span>,\n",
  2072. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.170732</span>,\n",
  2073. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.167331</span>\n",
  2074. "<span style=\"font-weight: bold\">}</span>\n",
  2075. "</pre>\n"
  2076. ],
  2077. "text/plain": [
  2078. "\u001b[1m{\u001b[0m\n",
  2079. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.169014\u001b[0m,\n",
  2080. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.170732\u001b[0m,\n",
  2081. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.167331\u001b[0m\n",
  2082. "\u001b[1m}\u001b[0m\n"
  2083. ]
  2084. },
  2085. "metadata": {},
  2086. "output_type": "display_data"
  2087. },
  2088. {
  2089. "data": {
  2090. "text/html": [
  2091. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2092. "</pre>\n"
  2093. ],
  2094. "text/plain": [
  2095. "\n"
  2096. ]
  2097. },
  2098. "metadata": {},
  2099. "output_type": "display_data"
  2100. },
  2101. {
  2102. "data": {
  2103. "text/html": [
  2104. "<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",
  2105. "</pre>\n"
  2106. ],
  2107. "text/plain": [
  2108. "----------------------------- Eval. results on Epoch:\u001b[1;36m2\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2109. ]
  2110. },
  2111. "metadata": {},
  2112. "output_type": "display_data"
  2113. },
  2114. {
  2115. "data": {
  2116. "text/html": [
  2117. "<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",
  2118. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.361809</span>,\n",
  2119. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.312139</span>,\n",
  2120. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.430279</span>\n",
  2121. "<span style=\"font-weight: bold\">}</span>\n",
  2122. "</pre>\n"
  2123. ],
  2124. "text/plain": [
  2125. "\u001b[1m{\u001b[0m\n",
  2126. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.361809\u001b[0m,\n",
  2127. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.312139\u001b[0m,\n",
  2128. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.430279\u001b[0m\n",
  2129. "\u001b[1m}\u001b[0m\n"
  2130. ]
  2131. },
  2132. "metadata": {},
  2133. "output_type": "display_data"
  2134. },
  2135. {
  2136. "data": {
  2137. "text/html": [
  2138. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2139. "</pre>\n"
  2140. ],
  2141. "text/plain": [
  2142. "\n"
  2143. ]
  2144. },
  2145. "metadata": {},
  2146. "output_type": "display_data"
  2147. },
  2148. {
  2149. "data": {
  2150. "text/html": [
  2151. "<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",
  2152. "</pre>\n"
  2153. ],
  2154. "text/plain": [
  2155. "----------------------------- Eval. results on Epoch:\u001b[1;36m3\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2156. ]
  2157. },
  2158. "metadata": {},
  2159. "output_type": "display_data"
  2160. },
  2161. {
  2162. "data": {
  2163. "text/html": [
  2164. "<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",
  2165. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.525</span>,\n",
  2166. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.475728</span>,\n",
  2167. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.585657</span>\n",
  2168. "<span style=\"font-weight: bold\">}</span>\n",
  2169. "</pre>\n"
  2170. ],
  2171. "text/plain": [
  2172. "\u001b[1m{\u001b[0m\n",
  2173. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.525\u001b[0m,\n",
  2174. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.475728\u001b[0m,\n",
  2175. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.585657\u001b[0m\n",
  2176. "\u001b[1m}\u001b[0m\n"
  2177. ]
  2178. },
  2179. "metadata": {},
  2180. "output_type": "display_data"
  2181. },
  2182. {
  2183. "data": {
  2184. "text/html": [
  2185. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2186. "</pre>\n"
  2187. ],
  2188. "text/plain": [
  2189. "\n"
  2190. ]
  2191. },
  2192. "metadata": {},
  2193. "output_type": "display_data"
  2194. },
  2195. {
  2196. "data": {
  2197. "text/html": [
  2198. "<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",
  2199. "</pre>\n"
  2200. ],
  2201. "text/plain": [
  2202. "----------------------------- Eval. results on Epoch:\u001b[1;36m4\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2203. ]
  2204. },
  2205. "metadata": {},
  2206. "output_type": "display_data"
  2207. },
  2208. {
  2209. "data": {
  2210. "text/html": [
  2211. "<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",
  2212. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.627306</span>,\n",
  2213. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.584192</span>,\n",
  2214. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.677291</span>\n",
  2215. "<span style=\"font-weight: bold\">}</span>\n",
  2216. "</pre>\n"
  2217. ],
  2218. "text/plain": [
  2219. "\u001b[1m{\u001b[0m\n",
  2220. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.627306\u001b[0m,\n",
  2221. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.584192\u001b[0m,\n",
  2222. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.677291\u001b[0m\n",
  2223. "\u001b[1m}\u001b[0m\n"
  2224. ]
  2225. },
  2226. "metadata": {},
  2227. "output_type": "display_data"
  2228. },
  2229. {
  2230. "data": {
  2231. "text/html": [
  2232. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2233. "</pre>\n"
  2234. ],
  2235. "text/plain": [
  2236. "\n"
  2237. ]
  2238. },
  2239. "metadata": {},
  2240. "output_type": "display_data"
  2241. },
  2242. {
  2243. "data": {
  2244. "text/html": [
  2245. "<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",
  2246. "</pre>\n"
  2247. ],
  2248. "text/plain": [
  2249. "----------------------------- Eval. results on Epoch:\u001b[1;36m5\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2250. ]
  2251. },
  2252. "metadata": {},
  2253. "output_type": "display_data"
  2254. },
  2255. {
  2256. "data": {
  2257. "text/html": [
  2258. "<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",
  2259. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.710937</span>,\n",
  2260. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.697318</span>,\n",
  2261. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.7251</span>\n",
  2262. "<span style=\"font-weight: bold\">}</span>\n",
  2263. "</pre>\n"
  2264. ],
  2265. "text/plain": [
  2266. "\u001b[1m{\u001b[0m\n",
  2267. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.710937\u001b[0m,\n",
  2268. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.697318\u001b[0m,\n",
  2269. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.7251\u001b[0m\n",
  2270. "\u001b[1m}\u001b[0m\n"
  2271. ]
  2272. },
  2273. "metadata": {},
  2274. "output_type": "display_data"
  2275. },
  2276. {
  2277. "data": {
  2278. "text/html": [
  2279. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2280. "</pre>\n"
  2281. ],
  2282. "text/plain": [
  2283. "\n"
  2284. ]
  2285. },
  2286. "metadata": {},
  2287. "output_type": "display_data"
  2288. },
  2289. {
  2290. "data": {
  2291. "text/html": [
  2292. "<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",
  2293. "</pre>\n"
  2294. ],
  2295. "text/plain": [
  2296. "----------------------------- Eval. results on Epoch:\u001b[1;36m6\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2297. ]
  2298. },
  2299. "metadata": {},
  2300. "output_type": "display_data"
  2301. },
  2302. {
  2303. "data": {
  2304. "text/html": [
  2305. "<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",
  2306. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.739563</span>,\n",
  2307. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.738095</span>,\n",
  2308. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.741036</span>\n",
  2309. "<span style=\"font-weight: bold\">}</span>\n",
  2310. "</pre>\n"
  2311. ],
  2312. "text/plain": [
  2313. "\u001b[1m{\u001b[0m\n",
  2314. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.739563\u001b[0m,\n",
  2315. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.738095\u001b[0m,\n",
  2316. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.741036\u001b[0m\n",
  2317. "\u001b[1m}\u001b[0m\n"
  2318. ]
  2319. },
  2320. "metadata": {},
  2321. "output_type": "display_data"
  2322. },
  2323. {
  2324. "data": {
  2325. "text/html": [
  2326. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2327. "</pre>\n"
  2328. ],
  2329. "text/plain": [
  2330. "\n"
  2331. ]
  2332. },
  2333. "metadata": {},
  2334. "output_type": "display_data"
  2335. },
  2336. {
  2337. "data": {
  2338. "text/html": [
  2339. "<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",
  2340. "</pre>\n"
  2341. ],
  2342. "text/plain": [
  2343. "----------------------------- Eval. results on Epoch:\u001b[1;36m7\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2344. ]
  2345. },
  2346. "metadata": {},
  2347. "output_type": "display_data"
  2348. },
  2349. {
  2350. "data": {
  2351. "text/html": [
  2352. "<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",
  2353. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.748491</span>,\n",
  2354. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.756098</span>,\n",
  2355. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.741036</span>\n",
  2356. "<span style=\"font-weight: bold\">}</span>\n",
  2357. "</pre>\n"
  2358. ],
  2359. "text/plain": [
  2360. "\u001b[1m{\u001b[0m\n",
  2361. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.748491\u001b[0m,\n",
  2362. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.756098\u001b[0m,\n",
  2363. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.741036\u001b[0m\n",
  2364. "\u001b[1m}\u001b[0m\n"
  2365. ]
  2366. },
  2367. "metadata": {},
  2368. "output_type": "display_data"
  2369. },
  2370. {
  2371. "data": {
  2372. "text/html": [
  2373. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2374. "</pre>\n"
  2375. ],
  2376. "text/plain": [
  2377. "\n"
  2378. ]
  2379. },
  2380. "metadata": {},
  2381. "output_type": "display_data"
  2382. },
  2383. {
  2384. "data": {
  2385. "text/html": [
  2386. "<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",
  2387. "</pre>\n"
  2388. ],
  2389. "text/plain": [
  2390. "----------------------------- Eval. results on Epoch:\u001b[1;36m8\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2391. ]
  2392. },
  2393. "metadata": {},
  2394. "output_type": "display_data"
  2395. },
  2396. {
  2397. "data": {
  2398. "text/html": [
  2399. "<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",
  2400. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.716763</span>,\n",
  2401. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.69403</span>,\n",
  2402. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.741036</span>\n",
  2403. "<span style=\"font-weight: bold\">}</span>\n",
  2404. "</pre>\n"
  2405. ],
  2406. "text/plain": [
  2407. "\u001b[1m{\u001b[0m\n",
  2408. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.716763\u001b[0m,\n",
  2409. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.69403\u001b[0m,\n",
  2410. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.741036\u001b[0m\n",
  2411. "\u001b[1m}\u001b[0m\n"
  2412. ]
  2413. },
  2414. "metadata": {},
  2415. "output_type": "display_data"
  2416. },
  2417. {
  2418. "data": {
  2419. "text/html": [
  2420. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2421. "</pre>\n"
  2422. ],
  2423. "text/plain": [
  2424. "\n"
  2425. ]
  2426. },
  2427. "metadata": {},
  2428. "output_type": "display_data"
  2429. },
  2430. {
  2431. "data": {
  2432. "text/html": [
  2433. "<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",
  2434. "</pre>\n"
  2435. ],
  2436. "text/plain": [
  2437. "----------------------------- Eval. results on Epoch:\u001b[1;36m9\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2438. ]
  2439. },
  2440. "metadata": {},
  2441. "output_type": "display_data"
  2442. },
  2443. {
  2444. "data": {
  2445. "text/html": [
  2446. "<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",
  2447. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.768293</span>,\n",
  2448. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.784232</span>,\n",
  2449. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.752988</span>\n",
  2450. "<span style=\"font-weight: bold\">}</span>\n",
  2451. "</pre>\n"
  2452. ],
  2453. "text/plain": [
  2454. "\u001b[1m{\u001b[0m\n",
  2455. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.768293\u001b[0m,\n",
  2456. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.784232\u001b[0m,\n",
  2457. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.752988\u001b[0m\n",
  2458. "\u001b[1m}\u001b[0m\n"
  2459. ]
  2460. },
  2461. "metadata": {},
  2462. "output_type": "display_data"
  2463. },
  2464. {
  2465. "data": {
  2466. "text/html": [
  2467. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2468. "</pre>\n"
  2469. ],
  2470. "text/plain": [
  2471. "\n"
  2472. ]
  2473. },
  2474. "metadata": {},
  2475. "output_type": "display_data"
  2476. },
  2477. {
  2478. "data": {
  2479. "text/html": [
  2480. "<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",
  2481. "</pre>\n"
  2482. ],
  2483. "text/plain": [
  2484. "---------------------------- Eval. results on Epoch:\u001b[1;36m10\u001b[0m, Batch:\u001b[1;36m0\u001b[0m -----------------------------\n"
  2485. ]
  2486. },
  2487. "metadata": {},
  2488. "output_type": "display_data"
  2489. },
  2490. {
  2491. "data": {
  2492. "text/html": [
  2493. "<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",
  2494. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"f#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.757692</span>,\n",
  2495. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"pre#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.732342</span>,\n",
  2496. " <span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">\"rec#F1\"</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.784861</span>\n",
  2497. "<span style=\"font-weight: bold\">}</span>\n",
  2498. "</pre>\n"
  2499. ],
  2500. "text/plain": [
  2501. "\u001b[1m{\u001b[0m\n",
  2502. " \u001b[1;34m\"f#F1\"\u001b[0m: \u001b[1;36m0.757692\u001b[0m,\n",
  2503. " \u001b[1;34m\"pre#F1\"\u001b[0m: \u001b[1;36m0.732342\u001b[0m,\n",
  2504. " \u001b[1;34m\"rec#F1\"\u001b[0m: \u001b[1;36m0.784861\u001b[0m\n",
  2505. "\u001b[1m}\u001b[0m\n"
  2506. ]
  2507. },
  2508. "metadata": {},
  2509. "output_type": "display_data"
  2510. },
  2511. {
  2512. "data": {
  2513. "text/html": [
  2514. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  2515. ],
  2516. "text/plain": []
  2517. },
  2518. "metadata": {},
  2519. "output_type": "display_data"
  2520. },
  2521. {
  2522. "data": {
  2523. "text/html": [
  2524. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
  2525. "</pre>\n"
  2526. ],
  2527. "text/plain": [
  2528. "\n"
  2529. ]
  2530. },
  2531. "metadata": {},
  2532. "output_type": "display_data"
  2533. }
  2534. ],
  2535. "source": [
  2536. "trainer.run(num_eval_batch_per_dl=10)"
  2537. ]
  2538. },
  2539. {
  2540. "cell_type": "code",
  2541. "execution_count": 21,
  2542. "id": "37871d6b",
  2543. "metadata": {},
  2544. "outputs": [
  2545. {
  2546. "data": {
  2547. "application/vnd.jupyter.widget-view+json": {
  2548. "model_id": "",
  2549. "version_major": 2,
  2550. "version_minor": 0
  2551. },
  2552. "text/plain": [
  2553. "Output()"
  2554. ]
  2555. },
  2556. "metadata": {},
  2557. "output_type": "display_data"
  2558. },
  2559. {
  2560. "data": {
  2561. "text/html": [
  2562. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
  2563. ],
  2564. "text/plain": []
  2565. },
  2566. "metadata": {},
  2567. "output_type": "display_data"
  2568. },
  2569. {
  2570. "data": {
  2571. "text/plain": [
  2572. "{'f#F1': 0.766798, 'pre#F1': 0.741874, 'rec#F1': 0.793456}"
  2573. ]
  2574. },
  2575. "execution_count": 21,
  2576. "metadata": {},
  2577. "output_type": "execute_result"
  2578. }
  2579. ],
  2580. "source": [
  2581. "trainer.evaluator.run()"
  2582. ]
  2583. },
  2584. {
  2585. "cell_type": "code",
  2586. "execution_count": null,
  2587. "id": "96bae094",
  2588. "metadata": {},
  2589. "outputs": [],
  2590. "source": []
  2591. }
  2592. ],
  2593. "metadata": {
  2594. "kernelspec": {
  2595. "display_name": "Python 3 (ipykernel)",
  2596. "language": "python",
  2597. "name": "python3"
  2598. },
  2599. "language_info": {
  2600. "codemirror_mode": {
  2601. "name": "ipython",
  2602. "version": 3
  2603. },
  2604. "file_extension": ".py",
  2605. "mimetype": "text/x-python",
  2606. "name": "python",
  2607. "nbconvert_exporter": "python",
  2608. "pygments_lexer": "ipython3",
  2609. "version": "3.7.13"
  2610. }
  2611. },
  2612. "nbformat": 4,
  2613. "nbformat_minor": 5
  2614. }