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.

tutorial_6_datasetiter.rst 23 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. ==============================================================================
  2. 动手实现一个文本分类器II-使用DataSetIter实现自定义训练过程
  3. ==============================================================================
  4. 我们使用和 :doc:`/user/quickstart` 中一样的任务来进行详细的介绍。给出一段评价性文字,预测其情感倾向是积极的(label=0)、
  5. 还是消极的(label=1),使用 :class:`~fastNLP.DataSetIter` 类来编写自己的训练过程。
  6. DataSetIter初探之前的内容与 :doc:`/tutorials/tutorial_5_loss_optimizer` 中的完全一样,如已经阅读过可以跳过。
  7. 数据读入和预处理
  8. --------------------
  9. 数据读入
  10. 我们可以使用 fastNLP :mod:`fastNLP.io` 模块中的 :class:`~fastNLP.io.SST2Pipe` 类,轻松地读取以及预处理SST2数据集。:class:`~fastNLP.io.SST2Pipe` 对象的
  11. :meth:`~fastNLP.io.SST2Pipe.process_from_file` 方法能够对读入的SST2数据集进行数据的预处理,方法的参数为paths, 指要处理的文件所在目录,如果paths为None,则会自动下载数 据集,函数默认paths值为None。
  12. 此函数返回一个 :class:`~fastNLP.io.DataBundle`,包含SST2数据集的训练集、测试集、验证集以及source端和target端的字典。其训练、测试、验证数据集含有四个 :mod:`~fastNLP.core.field` :
  13. * raw_words: 原source句子
  14. * target: 标签值
  15. * words: index之后的raw_words
  16. * seq_len: 句子长度
  17. 读入数据代码如下:
  18. .. code-block:: python
  19. from fastNLP.io import SST2Pipe
  20. pipe = SST2Pipe()
  21. databundle = pipe.process_from_file()
  22. vocab = databundle.vocabs['words']
  23. print(databundle)
  24. print(databundle.datasets['train'][0])
  25. print(databundle.vocabs['words'])
  26. 输出数据如下::
  27. In total 3 datasets:
  28. test has 1821 instances.
  29. train has 67349 instances.
  30. dev has 872 instances.
  31. In total 2 vocabs:
  32. words has 16293 entries.
  33. target has 2 entries.
  34. +-------------------------------------------+--------+--------------------------------------+---------+
  35. | raw_words | target | words | seq_len |
  36. +-------------------------------------------+--------+--------------------------------------+---------+
  37. | hide new secretions from the parental ... | 1 | [4111, 98, 12010, 38, 2, 6844, 9042] | 7 |
  38. +-------------------------------------------+--------+--------------------------------------+---------+
  39. Vocabulary(['hide', 'new', 'secretions', 'from', 'the']...)
  40. 除了可以对数据进行读入的Pipe类,fastNLP还提供了读入和下载数据的Loader类,不同数据集的Pipe和Loader及其用法详见 :doc:`/tutorials/tutorial_4_load_dataset` 。
  41. 数据集分割
  42. 由于SST2数据集的测试集并不带有标签数值,故我们分割出一部分训练集作为测试集。下面这段代码展示了 :meth:`~fastNLP.DataSet.split` 的使用方法
  43. .. code-block:: python
  44. train_data = databundle.get_dataset('train')
  45. train_data, test_data = train_data.split(0.015)
  46. dev_data = databundle.get_dataset('dev')
  47. print(len(train_data),len(dev_data),len(test_data))
  48. 输出结果为::
  49. 66339 872 1010
  50. 数据集 :meth:`~fastNLP.DataSet.set_input` 和 :meth:`~fastNLP.DataSet.set_target` 函数
  51. :class:`~fastNLP.io.SST2Pipe` 类的 :meth:`~fastNLP.io.SST2Pipe.process_from_file` 方法在预处理过程中还将训练、测试、验证集
  52. 的 `words` 、`seq_len` :mod:`~fastNLP.core.field` 设定为input,同时将`target` :mod:`~fastNLP.core.field` 设定为target。
  53. 我们可以通过 :class:`~fastNLP.core.Dataset` 类的 :meth:`~fastNLP.core.Dataset.print_field_meta` 方法查看各个
  54. :mod:`~fastNLP.core.field` 的设定情况,代码如下:
  55. .. code-block:: python
  56. train_data.print_field_meta()
  57. 输出结果为::
  58. +-------------+-----------+--------+-------+---------+
  59. | field_names | raw_words | target | words | seq_len |
  60. +-------------+-----------+--------+-------+---------+
  61. | is_input | False | False | True | True |
  62. | is_target | False | True | False | False |
  63. | ignore_type | | False | False | False |
  64. | pad_value | | 0 | 0 | 0 |
  65. +-------------+-----------+--------+-------+---------+
  66. 其中is_input和is_target分别表示是否为input和target。ignore_type为true时指使用 :class:`~fastNLP.DataSetIter` 取出batch数
  67. 据时fastNLP不会进行自动padding,pad_value指对应 :mod:`~fastNLP.core.field` padding所用的值,这两者只有当
  68. :mod:`~fastNLP.core.field` 设定为input或者target的时候才有存在的意义。
  69. is_input为true的 :mod:`~fastNLP.core.field` 在 :class:`~fastNLP.DataSetIter` 迭代取出的 batch_x 中,
  70. 而 is_target为true的 :mod:`~fastNLP.core.field` 在 :class:`~fastNLP.DataSetIter` 迭代取出的 batch_y 中。
  71. 具体分析见下面DataSetIter的介绍过程。
  72. 评价指标
  73. 训练模型需要提供一个评价指标。这里使用准确率做为评价指标。
  74. * ``pred`` 参数对应的是模型的 forward 方法返回的 dict 中的一个 key 的名字。
  75. * ``target`` 参数对应的是 :class:`~fastNLP.DataSet` 中作为标签的 :mod:`~fastNLP.core.field` 的名字。
  76. 这里我们用 :class:`~fastNLP.Const` 来辅助命名,如果你自己编写模型中 forward 方法的返回值或
  77. 数据集中 :mod:`~fastNLP.core.field` 的名字与本例不同, 你可以把 ``pred`` 参数和 ``target`` 参数设定符合自己代码的值。代码如下:
  78. .. code-block:: python
  79. from fastNLP import AccuracyMetric
  80. from fastNLP import Const
  81. # metrics=AccuracyMetric() 在本例中与下面这行代码等价
  82. metrics=AccuracyMetric(pred=Const.OUTPUT, target=Const.TARGET)
  83. DataSetIter初探
  84. --------------------------
  85. DataSetIter
  86. fastNLP定义的 :class:`~fastNLP.DataSetIter` 类,用于定义一个batch,并实现batch的多种功能,在初始化时传入的参数有:
  87. * dataset: :class:`~fastNLP.DataSet` 对象, 数据集
  88. * batch_size: 取出的batch大小
  89. * sampler: 规定使用的 :class:`~fastNLP.Sampler` 若为 None, 使用 :class:`~fastNLP.RandomSampler` (Default: None)
  90. * as_numpy: 若为 True, 输出batch为 `numpy.array`. 否则为 `torch.Tensor` (Default: False)
  91. * prefetch: 若为 True使用多进程预先取出下一batch. (Default: False)
  92. sampler
  93. fastNLP 实现的采样器有:
  94. * :class:`~fastNLP.BucketSampler` 可以随机地取出长度相似的元素 【初始化参数: num_buckets:bucket的数量; batch_size:batch大小; seq_len_field_name:dataset中对应序列长度的 :mod:`~fastNLP.core.field` 的名字】
  95. * SequentialSampler: 顺序取出元素的采样器【无初始化参数】
  96. * RandomSampler:随机化取元素的采样器【无初始化参数】
  97. Padder
  98. 在fastNLP里,pad是与一个 :mod:`~fastNLP.core.field` 绑定的。即不同的 :mod:`~fastNLP.core.field` 可以使用不同的pad方式,比如在英文任务中word需要的pad和
  99. character的pad方式往往是不同的。fastNLP是通过一个叫做 :class:`~fastNLP.Padder` 的子类来完成的。
  100. 默认情况下,所有field使用 :class:`~fastNLP.AutoPadder`
  101. 。大多数情况下直接使用 :class:`~fastNLP.AutoPadder` 就可以了。
  102. 如果 :class:`~fastNLP.AutoPadder` 或 :class:`~fastNLP.EngChar2DPadder` 无法满足需求,
  103. 也可以自己写一个 :class:`~fastNLP.Padder` 。
  104. DataSetIter自动padding
  105. 以下代码展示了DataSetIter的简单使用:
  106. .. code-block:: python
  107. from fastNLP import BucketSampler
  108. from fastNLP import DataSetIter
  109. tmp_data = dev_data[:10]
  110. # 定义一个Batch,传入DataSet,规定batch_size和去batch的规则。
  111. # 顺序(Sequential),随机(Random),相似长度组成一个batch(Bucket)
  112. sampler = BucketSampler(batch_size=2, seq_len_field_name='seq_len')
  113. batch = DataSetIter(batch_size=2, dataset=tmp_data, sampler=sampler)
  114. for batch_x, batch_y in batch:
  115. print("batch_x: ",batch_x)
  116. print("batch_y: ", batch_y)
  117. 输出结果如下::
  118. batch_x: {'words': tensor([[ 4, 278, 686, 18, 7],
  119. [15619, 3205, 5, 1676, 0]]), 'seq_len': tensor([5, 4])}
  120. batch_y: {'target': tensor([1, 1])}
  121. batch_x: {'words': tensor([[ 44, 753, 328, 181, 10, 15622, 16, 71, 8905, 9,
  122. 1218, 7, 0, 0, 0, 0, 0, 0, 0, 0],
  123. [ 880, 97, 8, 1027, 12, 8068, 11, 13624, 8, 15620,
  124. 4, 674, 663, 15, 4, 1155, 241, 640, 418, 7]]), 'seq_len': tensor([12, 20])}
  125. batch_y: {'target': tensor([1, 0])}
  126. batch_x: {'words': tensor([[ 1046, 11114, 16, 105, 5, 4, 177, 1825, 1705, 3,
  127. 2, 18, 11, 4, 1019, 433, 144, 32, 246, 309,
  128. 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  129. 0, 0, 0],
  130. [ 13, 831, 7747, 175, 3, 46, 6, 84, 5753, 15,
  131. 2178, 15, 62, 56, 407, 85, 1010, 4974, 26, 17,
  132. 13786, 3, 534, 3688, 15624, 38, 376, 8, 15625, 8,
  133. 1324, 4399, 7]]), 'seq_len': tensor([21, 33])}
  134. batch_y: {'target': tensor([0, 1])}
  135. batch_x: {'words': tensor([[ 14, 10, 438, 31, 78, 3, 78, 438, 7],
  136. [ 14, 10, 4, 312, 5, 155, 1419, 610, 7]]), 'seq_len': tensor([9, 9])}
  137. batch_y: {'target': tensor([1, 0])}
  138. batch_x: {'words': tensor([[ 24, 96, 27, 45, 8, 337, 37, 240, 8, 2134,
  139. 2, 18, 10, 15623, 1422, 6, 60, 5, 388, 7],
  140. [ 2, 156, 3, 4427, 3, 240, 3, 740, 5, 1137,
  141. 40, 42, 2428, 737, 2, 649, 10, 15621, 2286, 7]]), 'seq_len': tensor([20, 20])}
  142. batch_y: {'target': tensor([0, 0])}
  143. 可以看到那些设定为input的 :mod:`~fastNLP.core.field` 都出现在batch_x中,而设定为target的 :mod:`~fastNLP.core.field` 则出现在batch_y中。同时对于同一个batch_x中的两个数 据,长度偏短的那个会被自动padding到和长度偏长的句子长度一致,默认的padding值为0。
  144. Dataset改变padding值
  145. 可以通过 :meth:`~fastNLP.core.Dataset.set_pad_val` 方法修改默认的pad值,代码如下:
  146. .. code-block:: python
  147. tmp_data.set_pad_val('words',-1)
  148. batch = DataSetIter(batch_size=2, dataset=tmp_data, sampler=sampler)
  149. for batch_x, batch_y in batch:
  150. print("batch_x: ",batch_x)
  151. print("batch_y: ", batch_y)
  152. 输出结果如下::
  153. batch_x: {'words': tensor([[15619, 3205, 5, 1676, -1],
  154. [ 4, 278, 686, 18, 7]]), 'seq_len': tensor([4, 5])}
  155. batch_y: {'target': tensor([1, 1])}
  156. batch_x: {'words': tensor([[ 1046, 11114, 16, 105, 5, 4, 177, 1825, 1705, 3,
  157. 2, 18, 11, 4, 1019, 433, 144, 32, 246, 309,
  158. 7, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  159. -1, -1, -1],
  160. [ 13, 831, 7747, 175, 3, 46, 6, 84, 5753, 15,
  161. 2178, 15, 62, 56, 407, 85, 1010, 4974, 26, 17,
  162. 13786, 3, 534, 3688, 15624, 38, 376, 8, 15625, 8,
  163. 1324, 4399, 7]]), 'seq_len': tensor([21, 33])}
  164. batch_y: {'target': tensor([0, 1])}
  165. batch_x: {'words': tensor([[ 14, 10, 4, 312, 5, 155, 1419, 610, 7],
  166. [ 14, 10, 438, 31, 78, 3, 78, 438, 7]]), 'seq_len': tensor([9, 9])}
  167. batch_y: {'target': tensor([0, 1])}
  168. batch_x: {'words': tensor([[ 2, 156, 3, 4427, 3, 240, 3, 740, 5, 1137,
  169. 40, 42, 2428, 737, 2, 649, 10, 15621, 2286, 7],
  170. [ 24, 96, 27, 45, 8, 337, 37, 240, 8, 2134,
  171. 2, 18, 10, 15623, 1422, 6, 60, 5, 388, 7]]), 'seq_len': tensor([20, 20])}
  172. batch_y: {'target': tensor([0, 0])}
  173. batch_x: {'words': tensor([[ 44, 753, 328, 181, 10, 15622, 16, 71, 8905, 9,
  174. 1218, 7, -1, -1, -1, -1, -1, -1, -1, -1],
  175. [ 880, 97, 8, 1027, 12, 8068, 11, 13624, 8, 15620,
  176. 4, 674, 663, 15, 4, 1155, 241, 640, 418, 7]]), 'seq_len': tensor([12, 20])}
  177. batch_y: {'target': tensor([1, 0])}
  178. 可以看到使用了-1进行padding。
  179. Dataset个性化padding
  180. 如果我们希望对某一些 :mod:`~fastNLP.core.field` 进行个性化padding,可以自己构造Padder类,并使用 :meth:`~fastNLP.core.Dataset.set_padder` 函数修改padder来实现。下面通 过构造一个将数据padding到固定长度的padder进行展示:
  181. .. code-block:: python
  182. from fastNLP.core.field import Padder
  183. import numpy as np
  184. class FixLengthPadder(Padder):
  185. def __init__(self, pad_val=0, length=None):
  186. super().__init__(pad_val=pad_val)
  187. self.length = length
  188. assert self.length is not None, "Creating FixLengthPadder with no specific length!"
  189. def __call__(self, contents, field_name, field_ele_dtype, dim):
  190. #计算当前contents中的最大长度
  191. max_len = max(map(len, contents))
  192. #如果当前contents中的最大长度大于指定的padder length的话就报错
  193. assert max_len <= self.length, "Fixed padder length smaller than actual length! with length {}".format(max_len)
  194. array = np.full((len(contents), self.length), self.pad_val, dtype=field_ele_dtype)
  195. for i, content_i in enumerate(contents):
  196. array[i, :len(content_i)] = content_i
  197. return array
  198. #设定FixLengthPadder的固定长度为40
  199. tmp_padder = FixLengthPadder(pad_val=0,length=40)
  200. #利用dataset的set_padder函数设定words field的padder
  201. tmp_data.set_padder('words',tmp_padder)
  202. batch = DataSetIter(batch_size=2, dataset=tmp_data, sampler=sampler)
  203. for batch_x, batch_y in batch:
  204. print("batch_x: ",batch_x)
  205. print("batch_y: ", batch_y)
  206. 输出结果如下::
  207. batch_x: {'words': tensor([[ 4, 278, 686, 18, 7, 0, 0, 0, 0, 0,
  208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  211. [15619, 3205, 5, 1676, 0, 0, 0, 0, 0, 0,
  212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]), 'seq_len': tensor([5, 4])}
  215. batch_y: {'target': tensor([1, 1])}
  216. batch_x: {'words': tensor([[ 2, 156, 3, 4427, 3, 240, 3, 740, 5, 1137,
  217. 40, 42, 2428, 737, 2, 649, 10, 15621, 2286, 7,
  218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  220. [ 24, 96, 27, 45, 8, 337, 37, 240, 8, 2134,
  221. 2, 18, 10, 15623, 1422, 6, 60, 5, 388, 7,
  222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]), 'seq_len': tensor([20, 20])}
  224. batch_y: {'target': tensor([0, 0])}
  225. batch_x: {'words': tensor([[ 13, 831, 7747, 175, 3, 46, 6, 84, 5753, 15,
  226. 2178, 15, 62, 56, 407, 85, 1010, 4974, 26, 17,
  227. 13786, 3, 534, 3688, 15624, 38, 376, 8, 15625, 8,
  228. 1324, 4399, 7, 0, 0, 0, 0, 0, 0, 0],
  229. [ 1046, 11114, 16, 105, 5, 4, 177, 1825, 1705, 3,
  230. 2, 18, 11, 4, 1019, 433, 144, 32, 246, 309,
  231. 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]), 'seq_len': tensor([33, 21])}
  233. batch_y: {'target': tensor([1, 0])}
  234. batch_x: {'words': tensor([[ 14, 10, 4, 312, 5, 155, 1419, 610, 7, 0, 0, 0,
  235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  237. 0, 0, 0, 0],
  238. [ 14, 10, 438, 31, 78, 3, 78, 438, 7, 0, 0, 0,
  239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  241. 0, 0, 0, 0]]), 'seq_len': tensor([9, 9])}
  242. batch_y: {'target': tensor([0, 1])}
  243. batch_x: {'words': tensor([[ 44, 753, 328, 181, 10, 15622, 16, 71, 8905, 9,
  244. 1218, 7, 0, 0, 0, 0, 0, 0, 0, 0,
  245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  247. [ 880, 97, 8, 1027, 12, 8068, 11, 13624, 8, 15620,
  248. 4, 674, 663, 15, 4, 1155, 241, 640, 418, 7,
  249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]), 'seq_len': tensor([12, 20])}
  251. batch_y: {'target': tensor([1, 0])}
  252. 在这里所有的`words`都被pad成了长度为40的list。
  253. 使用DataSetIter自己编写训练过程
  254. ------------------------------------
  255. 如果你想用类似 PyTorch 的使用方法,自己编写训练过程,可以参考下面这段代码。
  256. 其中使用了 fastNLP 提供的 :class:`~fastNLP.DataSetIter` 来获得小批量训练的小批量数据,
  257. 使用 :class:`~fastNLP.BucketSampler` 做为 :class:`~fastNLP.DataSetIter` 的参数来选择采样的方式。
  258. 以下代码使用BucketSampler作为 :class:`~fastNLP.DataSetIter` 初始化的输入,运用 :class:`~fastNLP.DataSetIter` 自己写训练程序
  259. .. code-block:: python
  260. from fastNLP import BucketSampler
  261. from fastNLP import DataSetIter
  262. from fastNLP.models import CNNText
  263. from fastNLP import Tester
  264. import torch
  265. import time
  266. embed_dim = 100
  267. model = CNNText((len(vocab),embed_dim), num_classes=2, dropout=0.1)
  268. def train(epoch, data, devdata):
  269. optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
  270. lossfunc = torch.nn.CrossEntropyLoss()
  271. batch_size = 32
  272. # 定义一个Batch,传入DataSet,规定batch_size和去batch的规则。
  273. # 顺序(Sequential),随机(Random),相似长度组成一个batch(Bucket)
  274. train_sampler = BucketSampler(batch_size=batch_size, seq_len_field_name='seq_len')
  275. train_batch = DataSetIter(batch_size=batch_size, dataset=data, sampler=train_sampler)
  276. start_time = time.time()
  277. print("-"*5+"start training"+"-"*5)
  278. for i in range(epoch):
  279. loss_list = []
  280. for batch_x, batch_y in train_batch:
  281. optimizer.zero_grad()
  282. output = model(batch_x['words'])
  283. loss = lossfunc(output['pred'], batch_y['target'])
  284. loss.backward()
  285. optimizer.step()
  286. loss_list.append(loss.item())
  287. #这里verbose如果为0,在调用Tester对象的test()函数时不输出任何信息,返回评估信息; 如果为1,打印出验证结果,返回评估信息
  288. #在调用过Tester对象的test()函数后,调用其_format_eval_results(res)函数,结构化输出验证结果
  289. tester_tmp = Tester(devdata, model, metrics=AccuracyMetric(), verbose=0)
  290. res=tester_tmp.test()
  291. print('Epoch {:d} Avg Loss: {:.2f}'.format(i, sum(loss_list) / len(loss_list)),end=" ")
  292. print(tester_tmp._format_eval_results(res),end=" ")
  293. print('{:d}ms'.format(round((time.time()-start_time)*1000)))
  294. loss_list.clear()
  295. train(10, train_data, dev_data)
  296. #使用tester进行快速测试
  297. tester = Tester(test_data, model, metrics=AccuracyMetric())
  298. tester.test()
  299. 这段代码的输出如下::
  300. -----start training-----
  301. Evaluate data in 0.2 seconds!
  302. Epoch 0 Avg Loss: 0.33 AccuracyMetric: acc=0.825688 48895ms
  303. Evaluate data in 0.19 seconds!
  304. Epoch 1 Avg Loss: 0.16 AccuracyMetric: acc=0.829128 102081ms
  305. Evaluate data in 0.18 seconds!
  306. Epoch 2 Avg Loss: 0.10 AccuracyMetric: acc=0.822248 152853ms
  307. Evaluate data in 0.17 seconds!
  308. Epoch 3 Avg Loss: 0.08 AccuracyMetric: acc=0.821101 200184ms
  309. Evaluate data in 0.17 seconds!
  310. Epoch 4 Avg Loss: 0.06 AccuracyMetric: acc=0.827982 253097ms
  311. Evaluate data in 0.27 seconds!
  312. Epoch 5 Avg Loss: 0.05 AccuracyMetric: acc=0.806193 303883ms
  313. Evaluate data in 0.26 seconds!
  314. Epoch 6 Avg Loss: 0.04 AccuracyMetric: acc=0.803899 392315ms
  315. Evaluate data in 0.36 seconds!
  316. Epoch 7 Avg Loss: 0.04 AccuracyMetric: acc=0.802752 527211ms
  317. Evaluate data in 0.15 seconds!
  318. Epoch 8 Avg Loss: 0.03 AccuracyMetric: acc=0.809633 661533ms
  319. Evaluate data in 0.31 seconds!
  320. Epoch 9 Avg Loss: 0.03 AccuracyMetric: acc=0.797018 812232ms
  321. Evaluate data in 0.25 seconds!
  322. [tester]
  323. AccuracyMetric: acc=0.917822