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_1min_tutorial.ipynb 53 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {
  6. "collapsed": true
  7. },
  8. "source": [
  9. "# fastNLP 1分钟上手教程"
  10. ]
  11. },
  12. {
  13. "cell_type": "markdown",
  14. "metadata": {},
  15. "source": [
  16. "## step 1\n",
  17. "读取数据集"
  18. ]
  19. },
  20. {
  21. "cell_type": "code",
  22. "execution_count": 1,
  23. "metadata": {},
  24. "outputs": [],
  25. "source": [
  26. "from fastNLP import DataSet\n",
  27. " \n",
  28. "data_path = \"./sample_data/tutorial_sample_dataset.csv\"\n",
  29. "ds = DataSet.read_csv(data_path, headers=('raw_sentence', 'label'), sep='\\t')"
  30. ]
  31. },
  32. {
  33. "cell_type": "code",
  34. "execution_count": 2,
  35. "metadata": {},
  36. "outputs": [
  37. {
  38. "data": {
  39. "text/plain": [
  40. "{'raw_sentence': This quiet , introspective and entertaining independent is worth seeking . type=str,\n",
  41. "'label': 4 type=str}"
  42. ]
  43. },
  44. "execution_count": 2,
  45. "metadata": {},
  46. "output_type": "execute_result"
  47. }
  48. ],
  49. "source": [
  50. "ds[1]"
  51. ]
  52. },
  53. {
  54. "cell_type": "markdown",
  55. "metadata": {},
  56. "source": [
  57. "## step 2\n",
  58. "数据预处理\n",
  59. "1. 类型转换\n",
  60. "2. 切分验证集\n",
  61. "3. 构建词典"
  62. ]
  63. },
  64. {
  65. "cell_type": "code",
  66. "execution_count": 3,
  67. "metadata": {},
  68. "outputs": [
  69. {
  70. "data": {
  71. "text/plain": [
  72. "[['a',\n",
  73. " 'series',\n",
  74. " 'of',\n",
  75. " 'escapades',\n",
  76. " 'demonstrating',\n",
  77. " 'the',\n",
  78. " 'adage',\n",
  79. " 'that',\n",
  80. " 'what',\n",
  81. " 'is',\n",
  82. " 'good',\n",
  83. " 'for',\n",
  84. " 'the',\n",
  85. " 'goose',\n",
  86. " 'is',\n",
  87. " 'also',\n",
  88. " 'good',\n",
  89. " 'for',\n",
  90. " 'the',\n",
  91. " 'gander',\n",
  92. " ',',\n",
  93. " 'some',\n",
  94. " 'of',\n",
  95. " 'which',\n",
  96. " 'occasionally',\n",
  97. " 'amuses',\n",
  98. " 'but',\n",
  99. " 'none',\n",
  100. " 'of',\n",
  101. " 'which',\n",
  102. " 'amounts',\n",
  103. " 'to',\n",
  104. " 'much',\n",
  105. " 'of',\n",
  106. " 'a',\n",
  107. " 'story',\n",
  108. " '.'],\n",
  109. " ['this',\n",
  110. " 'quiet',\n",
  111. " ',',\n",
  112. " 'introspective',\n",
  113. " 'and',\n",
  114. " 'entertaining',\n",
  115. " 'independent',\n",
  116. " 'is',\n",
  117. " 'worth',\n",
  118. " 'seeking',\n",
  119. " '.'],\n",
  120. " ['even',\n",
  121. " 'fans',\n",
  122. " 'of',\n",
  123. " 'ismail',\n",
  124. " 'merchant',\n",
  125. " \"'s\",\n",
  126. " 'work',\n",
  127. " ',',\n",
  128. " 'i',\n",
  129. " 'suspect',\n",
  130. " ',',\n",
  131. " 'would',\n",
  132. " 'have',\n",
  133. " 'a',\n",
  134. " 'hard',\n",
  135. " 'time',\n",
  136. " 'sitting',\n",
  137. " 'through',\n",
  138. " 'this',\n",
  139. " 'one',\n",
  140. " '.'],\n",
  141. " ['a',\n",
  142. " 'positively',\n",
  143. " 'thrilling',\n",
  144. " 'combination',\n",
  145. " 'of',\n",
  146. " 'ethnography',\n",
  147. " 'and',\n",
  148. " 'all',\n",
  149. " 'the',\n",
  150. " 'intrigue',\n",
  151. " ',',\n",
  152. " 'betrayal',\n",
  153. " ',',\n",
  154. " 'deceit',\n",
  155. " 'and',\n",
  156. " 'murder',\n",
  157. " 'of',\n",
  158. " 'a',\n",
  159. " 'shakespearean',\n",
  160. " 'tragedy',\n",
  161. " 'or',\n",
  162. " 'a',\n",
  163. " 'juicy',\n",
  164. " 'soap',\n",
  165. " 'opera',\n",
  166. " '.'],\n",
  167. " ['aggressive',\n",
  168. " 'self-glorification',\n",
  169. " 'and',\n",
  170. " 'a',\n",
  171. " 'manipulative',\n",
  172. " 'whitewash',\n",
  173. " '.'],\n",
  174. " ['a',\n",
  175. " 'comedy-drama',\n",
  176. " 'of',\n",
  177. " 'nearly',\n",
  178. " 'epic',\n",
  179. " 'proportions',\n",
  180. " 'rooted',\n",
  181. " 'in',\n",
  182. " 'a',\n",
  183. " 'sincere',\n",
  184. " 'performance',\n",
  185. " 'by',\n",
  186. " 'the',\n",
  187. " 'title',\n",
  188. " 'character',\n",
  189. " 'undergoing',\n",
  190. " 'midlife',\n",
  191. " 'crisis',\n",
  192. " '.'],\n",
  193. " ['narratively',\n",
  194. " ',',\n",
  195. " 'trouble',\n",
  196. " 'every',\n",
  197. " 'day',\n",
  198. " 'is',\n",
  199. " 'a',\n",
  200. " 'plodding',\n",
  201. " 'mess',\n",
  202. " '.'],\n",
  203. " ['the',\n",
  204. " 'importance',\n",
  205. " 'of',\n",
  206. " 'being',\n",
  207. " 'earnest',\n",
  208. " ',',\n",
  209. " 'so',\n",
  210. " 'thick',\n",
  211. " 'with',\n",
  212. " 'wit',\n",
  213. " 'it',\n",
  214. " 'plays',\n",
  215. " 'like',\n",
  216. " 'a',\n",
  217. " 'reading',\n",
  218. " 'from',\n",
  219. " 'bartlett',\n",
  220. " \"'s\",\n",
  221. " 'familiar',\n",
  222. " 'quotations'],\n",
  223. " ['but', 'it', 'does', \"n't\", 'leave', 'you', 'with', 'much', '.'],\n",
  224. " ['you', 'could', 'hate', 'it', 'for', 'the', 'same', 'reason', '.'],\n",
  225. " ['there',\n",
  226. " \"'s\",\n",
  227. " 'little',\n",
  228. " 'to',\n",
  229. " 'recommend',\n",
  230. " 'snow',\n",
  231. " 'dogs',\n",
  232. " ',',\n",
  233. " 'unless',\n",
  234. " 'one',\n",
  235. " 'considers',\n",
  236. " 'cliched',\n",
  237. " 'dialogue',\n",
  238. " 'and',\n",
  239. " 'perverse',\n",
  240. " 'escapism',\n",
  241. " 'a',\n",
  242. " 'source',\n",
  243. " 'of',\n",
  244. " 'high',\n",
  245. " 'hilarity',\n",
  246. " '.'],\n",
  247. " ['kung',\n",
  248. " 'pow',\n",
  249. " 'is',\n",
  250. " 'oedekerk',\n",
  251. " \"'s\",\n",
  252. " 'realization',\n",
  253. " 'of',\n",
  254. " 'his',\n",
  255. " 'childhood',\n",
  256. " 'dream',\n",
  257. " 'to',\n",
  258. " 'be',\n",
  259. " 'in',\n",
  260. " 'a',\n",
  261. " 'martial-arts',\n",
  262. " 'flick',\n",
  263. " ',',\n",
  264. " 'and',\n",
  265. " 'proves',\n",
  266. " 'that',\n",
  267. " 'sometimes',\n",
  268. " 'the',\n",
  269. " 'dreams',\n",
  270. " 'of',\n",
  271. " 'youth',\n",
  272. " 'should',\n",
  273. " 'remain',\n",
  274. " 'just',\n",
  275. " 'that',\n",
  276. " '.'],\n",
  277. " ['the', 'performances', 'are', 'an', 'absolute', 'joy', '.'],\n",
  278. " ['fresnadillo',\n",
  279. " 'has',\n",
  280. " 'something',\n",
  281. " 'serious',\n",
  282. " 'to',\n",
  283. " 'say',\n",
  284. " 'about',\n",
  285. " 'the',\n",
  286. " 'ways',\n",
  287. " 'in',\n",
  288. " 'which',\n",
  289. " 'extravagant',\n",
  290. " 'chance',\n",
  291. " 'can',\n",
  292. " 'distort',\n",
  293. " 'our',\n",
  294. " 'perspective',\n",
  295. " 'and',\n",
  296. " 'throw',\n",
  297. " 'us',\n",
  298. " 'off',\n",
  299. " 'the',\n",
  300. " 'path',\n",
  301. " 'of',\n",
  302. " 'good',\n",
  303. " 'sense',\n",
  304. " '.'],\n",
  305. " ['i',\n",
  306. " 'still',\n",
  307. " 'like',\n",
  308. " 'moonlight',\n",
  309. " 'mile',\n",
  310. " ',',\n",
  311. " 'better',\n",
  312. " 'judgment',\n",
  313. " 'be',\n",
  314. " 'damned',\n",
  315. " '.'],\n",
  316. " ['a',\n",
  317. " 'welcome',\n",
  318. " 'relief',\n",
  319. " 'from',\n",
  320. " 'baseball',\n",
  321. " 'movies',\n",
  322. " 'that',\n",
  323. " 'try',\n",
  324. " 'too',\n",
  325. " 'hard',\n",
  326. " 'to',\n",
  327. " 'be',\n",
  328. " 'mythic',\n",
  329. " ',',\n",
  330. " 'this',\n",
  331. " 'one',\n",
  332. " 'is',\n",
  333. " 'a',\n",
  334. " 'sweet',\n",
  335. " 'and',\n",
  336. " 'modest',\n",
  337. " 'and',\n",
  338. " 'ultimately',\n",
  339. " 'winning',\n",
  340. " 'story',\n",
  341. " '.'],\n",
  342. " ['a',\n",
  343. " 'bilingual',\n",
  344. " 'charmer',\n",
  345. " ',',\n",
  346. " 'just',\n",
  347. " 'like',\n",
  348. " 'the',\n",
  349. " 'woman',\n",
  350. " 'who',\n",
  351. " 'inspired',\n",
  352. " 'it'],\n",
  353. " ['like',\n",
  354. " 'a',\n",
  355. " 'less',\n",
  356. " 'dizzily',\n",
  357. " 'gorgeous',\n",
  358. " 'companion',\n",
  359. " 'to',\n",
  360. " 'mr.',\n",
  361. " 'wong',\n",
  362. " \"'s\",\n",
  363. " 'in',\n",
  364. " 'the',\n",
  365. " 'mood',\n",
  366. " 'for',\n",
  367. " 'love',\n",
  368. " '--',\n",
  369. " 'very',\n",
  370. " 'much',\n",
  371. " 'a',\n",
  372. " 'hong',\n",
  373. " 'kong',\n",
  374. " 'movie',\n",
  375. " 'despite',\n",
  376. " 'its',\n",
  377. " 'mainland',\n",
  378. " 'setting',\n",
  379. " '.'],\n",
  380. " ['as',\n",
  381. " 'inept',\n",
  382. " 'as',\n",
  383. " 'big-screen',\n",
  384. " 'remakes',\n",
  385. " 'of',\n",
  386. " 'the',\n",
  387. " 'avengers',\n",
  388. " 'and',\n",
  389. " 'the',\n",
  390. " 'wild',\n",
  391. " 'wild',\n",
  392. " 'west',\n",
  393. " '.'],\n",
  394. " ['it',\n",
  395. " \"'s\",\n",
  396. " 'everything',\n",
  397. " 'you',\n",
  398. " \"'d\",\n",
  399. " 'expect',\n",
  400. " '--',\n",
  401. " 'but',\n",
  402. " 'nothing',\n",
  403. " 'more',\n",
  404. " '.'],\n",
  405. " ['best', 'indie', 'of', 'the', 'year', ',', 'so', 'far', '.'],\n",
  406. " ['hatfield',\n",
  407. " 'and',\n",
  408. " 'hicks',\n",
  409. " 'make',\n",
  410. " 'the',\n",
  411. " 'oddest',\n",
  412. " 'of',\n",
  413. " 'couples',\n",
  414. " ',',\n",
  415. " 'and',\n",
  416. " 'in',\n",
  417. " 'this',\n",
  418. " 'sense',\n",
  419. " 'the',\n",
  420. " 'movie',\n",
  421. " 'becomes',\n",
  422. " 'a',\n",
  423. " 'study',\n",
  424. " 'of',\n",
  425. " 'the',\n",
  426. " 'gambles',\n",
  427. " 'of',\n",
  428. " 'the',\n",
  429. " 'publishing',\n",
  430. " 'world',\n",
  431. " ',',\n",
  432. " 'offering',\n",
  433. " 'a',\n",
  434. " 'case',\n",
  435. " 'study',\n",
  436. " 'that',\n",
  437. " 'exists',\n",
  438. " 'apart',\n",
  439. " 'from',\n",
  440. " 'all',\n",
  441. " 'the',\n",
  442. " 'movie',\n",
  443. " \"'s\",\n",
  444. " 'political',\n",
  445. " 'ramifications',\n",
  446. " '.'],\n",
  447. " ['it',\n",
  448. " \"'s\",\n",
  449. " 'like',\n",
  450. " 'going',\n",
  451. " 'to',\n",
  452. " 'a',\n",
  453. " 'house',\n",
  454. " 'party',\n",
  455. " 'and',\n",
  456. " 'watching',\n",
  457. " 'the',\n",
  458. " 'host',\n",
  459. " 'defend',\n",
  460. " 'himself',\n",
  461. " 'against',\n",
  462. " 'a',\n",
  463. " 'frothing',\n",
  464. " 'ex-girlfriend',\n",
  465. " '.'],\n",
  466. " ['that',\n",
  467. " 'the',\n",
  468. " 'chuck',\n",
  469. " 'norris',\n",
  470. " '``',\n",
  471. " 'grenade',\n",
  472. " 'gag',\n",
  473. " \"''\",\n",
  474. " 'occurs',\n",
  475. " 'about',\n",
  476. " '7',\n",
  477. " 'times',\n",
  478. " 'during',\n",
  479. " 'windtalkers',\n",
  480. " 'is',\n",
  481. " 'a',\n",
  482. " 'good',\n",
  483. " 'indication',\n",
  484. " 'of',\n",
  485. " 'how',\n",
  486. " 'serious-minded',\n",
  487. " 'the',\n",
  488. " 'film',\n",
  489. " 'is',\n",
  490. " '.'],\n",
  491. " ['the',\n",
  492. " 'plot',\n",
  493. " 'is',\n",
  494. " 'romantic',\n",
  495. " 'comedy',\n",
  496. " 'boilerplate',\n",
  497. " 'from',\n",
  498. " 'start',\n",
  499. " 'to',\n",
  500. " 'finish',\n",
  501. " '.'],\n",
  502. " ['it',\n",
  503. " 'arrives',\n",
  504. " 'with',\n",
  505. " 'an',\n",
  506. " 'impeccable',\n",
  507. " 'pedigree',\n",
  508. " ',',\n",
  509. " 'mongrel',\n",
  510. " 'pep',\n",
  511. " ',',\n",
  512. " 'and',\n",
  513. " 'almost',\n",
  514. " 'indecipherable',\n",
  515. " 'plot',\n",
  516. " 'complications',\n",
  517. " '.'],\n",
  518. " ['a',\n",
  519. " 'film',\n",
  520. " 'that',\n",
  521. " 'clearly',\n",
  522. " 'means',\n",
  523. " 'to',\n",
  524. " 'preach',\n",
  525. " 'exclusively',\n",
  526. " 'to',\n",
  527. " 'the',\n",
  528. " 'converted',\n",
  529. " '.'],\n",
  530. " ['while',\n",
  531. " 'the',\n",
  532. " 'importance',\n",
  533. " 'of',\n",
  534. " 'being',\n",
  535. " 'earnest',\n",
  536. " 'offers',\n",
  537. " 'opportunities',\n",
  538. " 'for',\n",
  539. " 'occasional',\n",
  540. " 'smiles',\n",
  541. " 'and',\n",
  542. " 'chuckles',\n",
  543. " ',',\n",
  544. " 'it',\n",
  545. " 'does',\n",
  546. " \"n't\",\n",
  547. " 'give',\n",
  548. " 'us',\n",
  549. " 'a',\n",
  550. " 'reason',\n",
  551. " 'to',\n",
  552. " 'be',\n",
  553. " 'in',\n",
  554. " 'the',\n",
  555. " 'theater',\n",
  556. " 'beyond',\n",
  557. " 'wilde',\n",
  558. " \"'s\",\n",
  559. " 'wit',\n",
  560. " 'and',\n",
  561. " 'the',\n",
  562. " 'actors',\n",
  563. " \"'\",\n",
  564. " 'performances',\n",
  565. " '.'],\n",
  566. " ['the',\n",
  567. " 'latest',\n",
  568. " 'vapid',\n",
  569. " 'actor',\n",
  570. " \"'s\",\n",
  571. " 'exercise',\n",
  572. " 'to',\n",
  573. " 'appropriate',\n",
  574. " 'the',\n",
  575. " 'structure',\n",
  576. " 'of',\n",
  577. " 'arthur',\n",
  578. " 'schnitzler',\n",
  579. " \"'s\",\n",
  580. " 'reigen',\n",
  581. " '.'],\n",
  582. " ['more',\n",
  583. " 'vaudeville',\n",
  584. " 'show',\n",
  585. " 'than',\n",
  586. " 'well-constructed',\n",
  587. " 'narrative',\n",
  588. " ',',\n",
  589. " 'but',\n",
  590. " 'on',\n",
  591. " 'those',\n",
  592. " 'terms',\n",
  593. " 'it',\n",
  594. " \"'s\",\n",
  595. " 'inoffensive',\n",
  596. " 'and',\n",
  597. " 'actually',\n",
  598. " 'rather',\n",
  599. " 'sweet',\n",
  600. " '.'],\n",
  601. " ['nothing', 'more', 'than', 'a', 'run-of-the-mill', 'action', 'flick', '.'],\n",
  602. " ['hampered',\n",
  603. " '--',\n",
  604. " 'no',\n",
  605. " ',',\n",
  606. " 'paralyzed',\n",
  607. " '--',\n",
  608. " 'by',\n",
  609. " 'a',\n",
  610. " 'self-indulgent',\n",
  611. " 'script',\n",
  612. " '...',\n",
  613. " 'that',\n",
  614. " 'aims',\n",
  615. " 'for',\n",
  616. " 'poetry',\n",
  617. " 'and',\n",
  618. " 'ends',\n",
  619. " 'up',\n",
  620. " 'sounding',\n",
  621. " 'like',\n",
  622. " 'satire',\n",
  623. " '.'],\n",
  624. " ['ice',\n",
  625. " 'age',\n",
  626. " 'is',\n",
  627. " 'the',\n",
  628. " 'first',\n",
  629. " 'computer-generated',\n",
  630. " 'feature',\n",
  631. " 'cartoon',\n",
  632. " 'to',\n",
  633. " 'feel',\n",
  634. " 'like',\n",
  635. " 'other',\n",
  636. " 'movies',\n",
  637. " ',',\n",
  638. " 'and',\n",
  639. " 'that',\n",
  640. " 'makes',\n",
  641. " 'for',\n",
  642. " 'some',\n",
  643. " 'glacial',\n",
  644. " 'pacing',\n",
  645. " 'early',\n",
  646. " 'on',\n",
  647. " '.'],\n",
  648. " ['there',\n",
  649. " \"'s\",\n",
  650. " 'very',\n",
  651. " 'little',\n",
  652. " 'sense',\n",
  653. " 'to',\n",
  654. " 'what',\n",
  655. " \"'s\",\n",
  656. " 'going',\n",
  657. " 'on',\n",
  658. " 'here',\n",
  659. " ',',\n",
  660. " 'but',\n",
  661. " 'the',\n",
  662. " 'makers',\n",
  663. " 'serve',\n",
  664. " 'up',\n",
  665. " 'the',\n",
  666. " 'cliches',\n",
  667. " 'with',\n",
  668. " 'considerable',\n",
  669. " 'dash',\n",
  670. " '.'],\n",
  671. " ['cattaneo',\n",
  672. " 'should',\n",
  673. " 'have',\n",
  674. " 'followed',\n",
  675. " 'the',\n",
  676. " 'runaway',\n",
  677. " 'success',\n",
  678. " 'of',\n",
  679. " 'his',\n",
  680. " 'first',\n",
  681. " 'film',\n",
  682. " ',',\n",
  683. " 'the',\n",
  684. " 'full',\n",
  685. " 'monty',\n",
  686. " ',',\n",
  687. " 'with',\n",
  688. " 'something',\n",
  689. " 'different',\n",
  690. " '.'],\n",
  691. " ['they',\n",
  692. " \"'re\",\n",
  693. " 'the',\n",
  694. " 'unnamed',\n",
  695. " ',',\n",
  696. " 'easily',\n",
  697. " 'substitutable',\n",
  698. " 'forces',\n",
  699. " 'that',\n",
  700. " 'serve',\n",
  701. " 'as',\n",
  702. " 'whatever',\n",
  703. " 'terror',\n",
  704. " 'the',\n",
  705. " 'heroes',\n",
  706. " 'of',\n",
  707. " 'horror',\n",
  708. " 'movies',\n",
  709. " 'try',\n",
  710. " 'to',\n",
  711. " 'avoid',\n",
  712. " '.'],\n",
  713. " ['it',\n",
  714. " 'almost',\n",
  715. " 'feels',\n",
  716. " 'as',\n",
  717. " 'if',\n",
  718. " 'the',\n",
  719. " 'movie',\n",
  720. " 'is',\n",
  721. " 'more',\n",
  722. " 'interested',\n",
  723. " 'in',\n",
  724. " 'entertaining',\n",
  725. " 'itself',\n",
  726. " 'than',\n",
  727. " 'in',\n",
  728. " 'amusing',\n",
  729. " 'us',\n",
  730. " '.'],\n",
  731. " ['the',\n",
  732. " 'movie',\n",
  733. " \"'s\",\n",
  734. " 'progression',\n",
  735. " 'into',\n",
  736. " 'rambling',\n",
  737. " 'incoherence',\n",
  738. " 'gives',\n",
  739. " 'new',\n",
  740. " 'meaning',\n",
  741. " 'to',\n",
  742. " 'the',\n",
  743. " 'phrase',\n",
  744. " '`',\n",
  745. " 'fatal',\n",
  746. " 'script',\n",
  747. " 'error',\n",
  748. " '.',\n",
  749. " \"'\"],\n",
  750. " ['i',\n",
  751. " 'still',\n",
  752. " 'like',\n",
  753. " 'moonlight',\n",
  754. " 'mile',\n",
  755. " ',',\n",
  756. " 'better',\n",
  757. " 'judgment',\n",
  758. " 'be',\n",
  759. " 'damned',\n",
  760. " '.'],\n",
  761. " ['a',\n",
  762. " 'welcome',\n",
  763. " 'relief',\n",
  764. " 'from',\n",
  765. " 'baseball',\n",
  766. " 'movies',\n",
  767. " 'that',\n",
  768. " 'try',\n",
  769. " 'too',\n",
  770. " 'hard',\n",
  771. " 'to',\n",
  772. " 'be',\n",
  773. " 'mythic',\n",
  774. " ',',\n",
  775. " 'this',\n",
  776. " 'one',\n",
  777. " 'is',\n",
  778. " 'a',\n",
  779. " 'sweet',\n",
  780. " 'and',\n",
  781. " 'modest',\n",
  782. " 'and',\n",
  783. " 'ultimately',\n",
  784. " 'winning',\n",
  785. " 'story',\n",
  786. " '.'],\n",
  787. " ['a',\n",
  788. " 'bilingual',\n",
  789. " 'charmer',\n",
  790. " ',',\n",
  791. " 'just',\n",
  792. " 'like',\n",
  793. " 'the',\n",
  794. " 'woman',\n",
  795. " 'who',\n",
  796. " 'inspired',\n",
  797. " 'it'],\n",
  798. " ['like',\n",
  799. " 'a',\n",
  800. " 'less',\n",
  801. " 'dizzily',\n",
  802. " 'gorgeous',\n",
  803. " 'companion',\n",
  804. " 'to',\n",
  805. " 'mr.',\n",
  806. " 'wong',\n",
  807. " \"'s\",\n",
  808. " 'in',\n",
  809. " 'the',\n",
  810. " 'mood',\n",
  811. " 'for',\n",
  812. " 'love',\n",
  813. " '--',\n",
  814. " 'very',\n",
  815. " 'much',\n",
  816. " 'a',\n",
  817. " 'hong',\n",
  818. " 'kong',\n",
  819. " 'movie',\n",
  820. " 'despite',\n",
  821. " 'its',\n",
  822. " 'mainland',\n",
  823. " 'setting',\n",
  824. " '.'],\n",
  825. " ['as',\n",
  826. " 'inept',\n",
  827. " 'as',\n",
  828. " 'big-screen',\n",
  829. " 'remakes',\n",
  830. " 'of',\n",
  831. " 'the',\n",
  832. " 'avengers',\n",
  833. " 'and',\n",
  834. " 'the',\n",
  835. " 'wild',\n",
  836. " 'wild',\n",
  837. " 'west',\n",
  838. " '.'],\n",
  839. " ['it',\n",
  840. " \"'s\",\n",
  841. " 'everything',\n",
  842. " 'you',\n",
  843. " \"'d\",\n",
  844. " 'expect',\n",
  845. " '--',\n",
  846. " 'but',\n",
  847. " 'nothing',\n",
  848. " 'more',\n",
  849. " '.'],\n",
  850. " ['best', 'indie', 'of', 'the', 'year', ',', 'so', 'far', '.'],\n",
  851. " ['hatfield',\n",
  852. " 'and',\n",
  853. " 'hicks',\n",
  854. " 'make',\n",
  855. " 'the',\n",
  856. " 'oddest',\n",
  857. " 'of',\n",
  858. " 'couples',\n",
  859. " ',',\n",
  860. " 'and',\n",
  861. " 'in',\n",
  862. " 'this',\n",
  863. " 'sense',\n",
  864. " 'the',\n",
  865. " 'movie',\n",
  866. " 'becomes',\n",
  867. " 'a',\n",
  868. " 'study',\n",
  869. " 'of',\n",
  870. " 'the',\n",
  871. " 'gambles',\n",
  872. " 'of',\n",
  873. " 'the',\n",
  874. " 'publishing',\n",
  875. " 'world',\n",
  876. " ',',\n",
  877. " 'offering',\n",
  878. " 'a',\n",
  879. " 'case',\n",
  880. " 'study',\n",
  881. " 'that',\n",
  882. " 'exists',\n",
  883. " 'apart',\n",
  884. " 'from',\n",
  885. " 'all',\n",
  886. " 'the',\n",
  887. " 'movie',\n",
  888. " \"'s\",\n",
  889. " 'political',\n",
  890. " 'ramifications',\n",
  891. " '.'],\n",
  892. " ['it',\n",
  893. " \"'s\",\n",
  894. " 'like',\n",
  895. " 'going',\n",
  896. " 'to',\n",
  897. " 'a',\n",
  898. " 'house',\n",
  899. " 'party',\n",
  900. " 'and',\n",
  901. " 'watching',\n",
  902. " 'the',\n",
  903. " 'host',\n",
  904. " 'defend',\n",
  905. " 'himself',\n",
  906. " 'against',\n",
  907. " 'a',\n",
  908. " 'frothing',\n",
  909. " 'ex-girlfriend',\n",
  910. " '.'],\n",
  911. " ['that',\n",
  912. " 'the',\n",
  913. " 'chuck',\n",
  914. " 'norris',\n",
  915. " '``',\n",
  916. " 'grenade',\n",
  917. " 'gag',\n",
  918. " \"''\",\n",
  919. " 'occurs',\n",
  920. " 'about',\n",
  921. " '7',\n",
  922. " 'times',\n",
  923. " 'during',\n",
  924. " 'windtalkers',\n",
  925. " 'is',\n",
  926. " 'a',\n",
  927. " 'good',\n",
  928. " 'indication',\n",
  929. " 'of',\n",
  930. " 'how',\n",
  931. " 'serious-minded',\n",
  932. " 'the',\n",
  933. " 'film',\n",
  934. " 'is',\n",
  935. " '.'],\n",
  936. " ['the',\n",
  937. " 'plot',\n",
  938. " 'is',\n",
  939. " 'romantic',\n",
  940. " 'comedy',\n",
  941. " 'boilerplate',\n",
  942. " 'from',\n",
  943. " 'start',\n",
  944. " 'to',\n",
  945. " 'finish',\n",
  946. " '.'],\n",
  947. " ['it',\n",
  948. " 'arrives',\n",
  949. " 'with',\n",
  950. " 'an',\n",
  951. " 'impeccable',\n",
  952. " 'pedigree',\n",
  953. " ',',\n",
  954. " 'mongrel',\n",
  955. " 'pep',\n",
  956. " ',',\n",
  957. " 'and',\n",
  958. " 'almost',\n",
  959. " 'indecipherable',\n",
  960. " 'plot',\n",
  961. " 'complications',\n",
  962. " '.'],\n",
  963. " ['a',\n",
  964. " 'film',\n",
  965. " 'that',\n",
  966. " 'clearly',\n",
  967. " 'means',\n",
  968. " 'to',\n",
  969. " 'preach',\n",
  970. " 'exclusively',\n",
  971. " 'to',\n",
  972. " 'the',\n",
  973. " 'converted',\n",
  974. " '.'],\n",
  975. " ['i',\n",
  976. " 'still',\n",
  977. " 'like',\n",
  978. " 'moonlight',\n",
  979. " 'mile',\n",
  980. " ',',\n",
  981. " 'better',\n",
  982. " 'judgment',\n",
  983. " 'be',\n",
  984. " 'damned',\n",
  985. " '.'],\n",
  986. " ['a',\n",
  987. " 'welcome',\n",
  988. " 'relief',\n",
  989. " 'from',\n",
  990. " 'baseball',\n",
  991. " 'movies',\n",
  992. " 'that',\n",
  993. " 'try',\n",
  994. " 'too',\n",
  995. " 'hard',\n",
  996. " 'to',\n",
  997. " 'be',\n",
  998. " 'mythic',\n",
  999. " ',',\n",
  1000. " 'this',\n",
  1001. " 'one',\n",
  1002. " 'is',\n",
  1003. " 'a',\n",
  1004. " 'sweet',\n",
  1005. " 'and',\n",
  1006. " 'modest',\n",
  1007. " 'and',\n",
  1008. " 'ultimately',\n",
  1009. " 'winning',\n",
  1010. " 'story',\n",
  1011. " '.'],\n",
  1012. " ['a',\n",
  1013. " 'bilingual',\n",
  1014. " 'charmer',\n",
  1015. " ',',\n",
  1016. " 'just',\n",
  1017. " 'like',\n",
  1018. " 'the',\n",
  1019. " 'woman',\n",
  1020. " 'who',\n",
  1021. " 'inspired',\n",
  1022. " 'it'],\n",
  1023. " ['like',\n",
  1024. " 'a',\n",
  1025. " 'less',\n",
  1026. " 'dizzily',\n",
  1027. " 'gorgeous',\n",
  1028. " 'companion',\n",
  1029. " 'to',\n",
  1030. " 'mr.',\n",
  1031. " 'wong',\n",
  1032. " \"'s\",\n",
  1033. " 'in',\n",
  1034. " 'the',\n",
  1035. " 'mood',\n",
  1036. " 'for',\n",
  1037. " 'love',\n",
  1038. " '--',\n",
  1039. " 'very',\n",
  1040. " 'much',\n",
  1041. " 'a',\n",
  1042. " 'hong',\n",
  1043. " 'kong',\n",
  1044. " 'movie',\n",
  1045. " 'despite',\n",
  1046. " 'its',\n",
  1047. " 'mainland',\n",
  1048. " 'setting',\n",
  1049. " '.'],\n",
  1050. " ['as',\n",
  1051. " 'inept',\n",
  1052. " 'as',\n",
  1053. " 'big-screen',\n",
  1054. " 'remakes',\n",
  1055. " 'of',\n",
  1056. " 'the',\n",
  1057. " 'avengers',\n",
  1058. " 'and',\n",
  1059. " 'the',\n",
  1060. " 'wild',\n",
  1061. " 'wild',\n",
  1062. " 'west',\n",
  1063. " '.'],\n",
  1064. " ['it',\n",
  1065. " \"'s\",\n",
  1066. " 'everything',\n",
  1067. " 'you',\n",
  1068. " \"'d\",\n",
  1069. " 'expect',\n",
  1070. " '--',\n",
  1071. " 'but',\n",
  1072. " 'nothing',\n",
  1073. " 'more',\n",
  1074. " '.'],\n",
  1075. " ['best', 'indie', 'of', 'the', 'year', ',', 'so', 'far', '.'],\n",
  1076. " ['hatfield',\n",
  1077. " 'and',\n",
  1078. " 'hicks',\n",
  1079. " 'make',\n",
  1080. " 'the',\n",
  1081. " 'oddest',\n",
  1082. " 'of',\n",
  1083. " 'couples',\n",
  1084. " ',',\n",
  1085. " 'and',\n",
  1086. " 'in',\n",
  1087. " 'this',\n",
  1088. " 'sense',\n",
  1089. " 'the',\n",
  1090. " 'movie',\n",
  1091. " 'becomes',\n",
  1092. " 'a',\n",
  1093. " 'study',\n",
  1094. " 'of',\n",
  1095. " 'the',\n",
  1096. " 'gambles',\n",
  1097. " 'of',\n",
  1098. " 'the',\n",
  1099. " 'publishing',\n",
  1100. " 'world',\n",
  1101. " ',',\n",
  1102. " 'offering',\n",
  1103. " 'a',\n",
  1104. " 'case',\n",
  1105. " 'study',\n",
  1106. " 'that',\n",
  1107. " 'exists',\n",
  1108. " 'apart',\n",
  1109. " 'from',\n",
  1110. " 'all',\n",
  1111. " 'the',\n",
  1112. " 'movie',\n",
  1113. " \"'s\",\n",
  1114. " 'political',\n",
  1115. " 'ramifications',\n",
  1116. " '.'],\n",
  1117. " ['it',\n",
  1118. " \"'s\",\n",
  1119. " 'like',\n",
  1120. " 'going',\n",
  1121. " 'to',\n",
  1122. " 'a',\n",
  1123. " 'house',\n",
  1124. " 'party',\n",
  1125. " 'and',\n",
  1126. " 'watching',\n",
  1127. " 'the',\n",
  1128. " 'host',\n",
  1129. " 'defend',\n",
  1130. " 'himself',\n",
  1131. " 'against',\n",
  1132. " 'a',\n",
  1133. " 'frothing',\n",
  1134. " 'ex-girlfriend',\n",
  1135. " '.'],\n",
  1136. " ['that',\n",
  1137. " 'the',\n",
  1138. " 'chuck',\n",
  1139. " 'norris',\n",
  1140. " '``',\n",
  1141. " 'grenade',\n",
  1142. " 'gag',\n",
  1143. " \"''\",\n",
  1144. " 'occurs',\n",
  1145. " 'about',\n",
  1146. " '7',\n",
  1147. " 'times',\n",
  1148. " 'during',\n",
  1149. " 'windtalkers',\n",
  1150. " 'is',\n",
  1151. " 'a',\n",
  1152. " 'good',\n",
  1153. " 'indication',\n",
  1154. " 'of',\n",
  1155. " 'how',\n",
  1156. " 'serious-minded',\n",
  1157. " 'the',\n",
  1158. " 'film',\n",
  1159. " 'is',\n",
  1160. " '.'],\n",
  1161. " ['the',\n",
  1162. " 'plot',\n",
  1163. " 'is',\n",
  1164. " 'romantic',\n",
  1165. " 'comedy',\n",
  1166. " 'boilerplate',\n",
  1167. " 'from',\n",
  1168. " 'start',\n",
  1169. " 'to',\n",
  1170. " 'finish',\n",
  1171. " '.'],\n",
  1172. " ['it',\n",
  1173. " 'arrives',\n",
  1174. " 'with',\n",
  1175. " 'an',\n",
  1176. " 'impeccable',\n",
  1177. " 'pedigree',\n",
  1178. " ',',\n",
  1179. " 'mongrel',\n",
  1180. " 'pep',\n",
  1181. " ',',\n",
  1182. " 'and',\n",
  1183. " 'almost',\n",
  1184. " 'indecipherable',\n",
  1185. " 'plot',\n",
  1186. " 'complications',\n",
  1187. " '.'],\n",
  1188. " ['a',\n",
  1189. " 'film',\n",
  1190. " 'that',\n",
  1191. " 'clearly',\n",
  1192. " 'means',\n",
  1193. " 'to',\n",
  1194. " 'preach',\n",
  1195. " 'exclusively',\n",
  1196. " 'to',\n",
  1197. " 'the',\n",
  1198. " 'converted',\n",
  1199. " '.'],\n",
  1200. " ['i',\n",
  1201. " 'still',\n",
  1202. " 'like',\n",
  1203. " 'moonlight',\n",
  1204. " 'mile',\n",
  1205. " ',',\n",
  1206. " 'better',\n",
  1207. " 'judgment',\n",
  1208. " 'be',\n",
  1209. " 'damned',\n",
  1210. " '.'],\n",
  1211. " ['a',\n",
  1212. " 'welcome',\n",
  1213. " 'relief',\n",
  1214. " 'from',\n",
  1215. " 'baseball',\n",
  1216. " 'movies',\n",
  1217. " 'that',\n",
  1218. " 'try',\n",
  1219. " 'too',\n",
  1220. " 'hard',\n",
  1221. " 'to',\n",
  1222. " 'be',\n",
  1223. " 'mythic',\n",
  1224. " ',',\n",
  1225. " 'this',\n",
  1226. " 'one',\n",
  1227. " 'is',\n",
  1228. " 'a',\n",
  1229. " 'sweet',\n",
  1230. " 'and',\n",
  1231. " 'modest',\n",
  1232. " 'and',\n",
  1233. " 'ultimately',\n",
  1234. " 'winning',\n",
  1235. " 'story',\n",
  1236. " '.'],\n",
  1237. " ['a',\n",
  1238. " 'bilingual',\n",
  1239. " 'charmer',\n",
  1240. " ',',\n",
  1241. " 'just',\n",
  1242. " 'like',\n",
  1243. " 'the',\n",
  1244. " 'woman',\n",
  1245. " 'who',\n",
  1246. " 'inspired',\n",
  1247. " 'it'],\n",
  1248. " ['like',\n",
  1249. " 'a',\n",
  1250. " 'less',\n",
  1251. " 'dizzily',\n",
  1252. " 'gorgeous',\n",
  1253. " 'companion',\n",
  1254. " 'to',\n",
  1255. " 'mr.',\n",
  1256. " 'wong',\n",
  1257. " \"'s\",\n",
  1258. " 'in',\n",
  1259. " 'the',\n",
  1260. " 'mood',\n",
  1261. " 'for',\n",
  1262. " 'love',\n",
  1263. " '--',\n",
  1264. " 'very',\n",
  1265. " 'much',\n",
  1266. " 'a',\n",
  1267. " 'hong',\n",
  1268. " 'kong',\n",
  1269. " 'movie',\n",
  1270. " 'despite',\n",
  1271. " 'its',\n",
  1272. " 'mainland',\n",
  1273. " 'setting',\n",
  1274. " '.'],\n",
  1275. " ['as',\n",
  1276. " 'inept',\n",
  1277. " 'as',\n",
  1278. " 'big-screen',\n",
  1279. " 'remakes',\n",
  1280. " 'of',\n",
  1281. " 'the',\n",
  1282. " 'avengers',\n",
  1283. " 'and',\n",
  1284. " 'the',\n",
  1285. " 'wild',\n",
  1286. " 'wild',\n",
  1287. " 'west',\n",
  1288. " '.'],\n",
  1289. " ['it',\n",
  1290. " \"'s\",\n",
  1291. " 'everything',\n",
  1292. " 'you',\n",
  1293. " \"'d\",\n",
  1294. " 'expect',\n",
  1295. " '--',\n",
  1296. " 'but',\n",
  1297. " 'nothing',\n",
  1298. " 'more',\n",
  1299. " '.'],\n",
  1300. " ['best', 'indie', 'of', 'the', 'year', ',', 'so', 'far', '.'],\n",
  1301. " ['hatfield',\n",
  1302. " 'and',\n",
  1303. " 'hicks',\n",
  1304. " 'make',\n",
  1305. " 'the',\n",
  1306. " 'oddest',\n",
  1307. " 'of',\n",
  1308. " 'couples',\n",
  1309. " ',',\n",
  1310. " 'and',\n",
  1311. " 'in',\n",
  1312. " 'this',\n",
  1313. " 'sense',\n",
  1314. " 'the',\n",
  1315. " 'movie',\n",
  1316. " 'becomes',\n",
  1317. " 'a',\n",
  1318. " 'study',\n",
  1319. " 'of',\n",
  1320. " 'the',\n",
  1321. " 'gambles',\n",
  1322. " 'of',\n",
  1323. " 'the',\n",
  1324. " 'publishing',\n",
  1325. " 'world',\n",
  1326. " ',',\n",
  1327. " 'offering',\n",
  1328. " 'a',\n",
  1329. " 'case',\n",
  1330. " 'study',\n",
  1331. " 'that',\n",
  1332. " 'exists',\n",
  1333. " 'apart',\n",
  1334. " 'from',\n",
  1335. " 'all',\n",
  1336. " 'the',\n",
  1337. " 'movie',\n",
  1338. " \"'s\",\n",
  1339. " 'political',\n",
  1340. " 'ramifications',\n",
  1341. " '.'],\n",
  1342. " ['it',\n",
  1343. " \"'s\",\n",
  1344. " 'like',\n",
  1345. " 'going',\n",
  1346. " 'to',\n",
  1347. " 'a',\n",
  1348. " 'house',\n",
  1349. " 'party',\n",
  1350. " 'and',\n",
  1351. " 'watching',\n",
  1352. " 'the',\n",
  1353. " 'host',\n",
  1354. " 'defend',\n",
  1355. " 'himself',\n",
  1356. " 'against',\n",
  1357. " 'a',\n",
  1358. " 'frothing',\n",
  1359. " 'ex-girlfriend',\n",
  1360. " '.'],\n",
  1361. " ['that',\n",
  1362. " 'the',\n",
  1363. " 'chuck',\n",
  1364. " 'norris',\n",
  1365. " '``',\n",
  1366. " 'grenade',\n",
  1367. " 'gag',\n",
  1368. " \"''\",\n",
  1369. " 'occurs',\n",
  1370. " 'about',\n",
  1371. " '7',\n",
  1372. " 'times',\n",
  1373. " 'during',\n",
  1374. " 'windtalkers',\n",
  1375. " 'is',\n",
  1376. " 'a',\n",
  1377. " 'good',\n",
  1378. " 'indication',\n",
  1379. " 'of',\n",
  1380. " 'how',\n",
  1381. " 'serious-minded',\n",
  1382. " 'the',\n",
  1383. " 'film',\n",
  1384. " 'is',\n",
  1385. " '.'],\n",
  1386. " ['the',\n",
  1387. " 'plot',\n",
  1388. " 'is',\n",
  1389. " 'romantic',\n",
  1390. " 'comedy',\n",
  1391. " 'boilerplate',\n",
  1392. " 'from',\n",
  1393. " 'start',\n",
  1394. " 'to',\n",
  1395. " 'finish',\n",
  1396. " '.'],\n",
  1397. " ['it',\n",
  1398. " 'arrives',\n",
  1399. " 'with',\n",
  1400. " 'an',\n",
  1401. " 'impeccable',\n",
  1402. " 'pedigree',\n",
  1403. " ',',\n",
  1404. " 'mongrel',\n",
  1405. " 'pep',\n",
  1406. " ',',\n",
  1407. " 'and',\n",
  1408. " 'almost',\n",
  1409. " 'indecipherable',\n",
  1410. " 'plot',\n",
  1411. " 'complications',\n",
  1412. " '.'],\n",
  1413. " ['a',\n",
  1414. " 'film',\n",
  1415. " 'that',\n",
  1416. " 'clearly',\n",
  1417. " 'means',\n",
  1418. " 'to',\n",
  1419. " 'preach',\n",
  1420. " 'exclusively',\n",
  1421. " 'to',\n",
  1422. " 'the',\n",
  1423. " 'converted',\n",
  1424. " '.']]"
  1425. ]
  1426. },
  1427. "execution_count": 3,
  1428. "metadata": {},
  1429. "output_type": "execute_result"
  1430. }
  1431. ],
  1432. "source": [
  1433. "# 将所有数字转为小写\n",
  1434. "ds.apply(lambda x: x['raw_sentence'].lower(), new_field_name='raw_sentence')\n",
  1435. "# label转int\n",
  1436. "ds.apply(lambda x: int(x['label']), new_field_name='label_seq', is_target=True)\n",
  1437. "\n",
  1438. "def split_sent(ins):\n",
  1439. " return ins['raw_sentence'].split()\n",
  1440. "ds.apply(split_sent, new_field_name='words', is_input=True)\n"
  1441. ]
  1442. },
  1443. {
  1444. "cell_type": "code",
  1445. "execution_count": 4,
  1446. "metadata": {},
  1447. "outputs": [
  1448. {
  1449. "name": "stdout",
  1450. "output_type": "stream",
  1451. "text": [
  1452. "Train size: 54\n",
  1453. "Test size: 23\n"
  1454. ]
  1455. }
  1456. ],
  1457. "source": [
  1458. "# 分割训练集/验证集\n",
  1459. "train_data, dev_data = ds.split(0.3)\n",
  1460. "print(\"Train size: \", len(train_data))\n",
  1461. "print(\"Test size: \", len(dev_data))"
  1462. ]
  1463. },
  1464. {
  1465. "cell_type": "code",
  1466. "execution_count": 5,
  1467. "metadata": {},
  1468. "outputs": [
  1469. {
  1470. "data": {
  1471. "text/plain": [
  1472. "[[120, 121, 6, 2, 122, 5, 72, 123, 3],\n",
  1473. " [14,\n",
  1474. " 4,\n",
  1475. " 152,\n",
  1476. " 153,\n",
  1477. " 154,\n",
  1478. " 155,\n",
  1479. " 8,\n",
  1480. " 156,\n",
  1481. " 157,\n",
  1482. " 9,\n",
  1483. " 16,\n",
  1484. " 2,\n",
  1485. " 158,\n",
  1486. " 21,\n",
  1487. " 159,\n",
  1488. " 30,\n",
  1489. " 98,\n",
  1490. " 57,\n",
  1491. " 4,\n",
  1492. " 160,\n",
  1493. " 161,\n",
  1494. " 13,\n",
  1495. " 162,\n",
  1496. " 163,\n",
  1497. " 164,\n",
  1498. " 165,\n",
  1499. " 3],\n",
  1500. " [4,\n",
  1501. " 112,\n",
  1502. " 113,\n",
  1503. " 15,\n",
  1504. " 114,\n",
  1505. " 35,\n",
  1506. " 10,\n",
  1507. " 68,\n",
  1508. " 115,\n",
  1509. " 69,\n",
  1510. " 8,\n",
  1511. " 23,\n",
  1512. " 116,\n",
  1513. " 5,\n",
  1514. " 18,\n",
  1515. " 36,\n",
  1516. " 11,\n",
  1517. " 4,\n",
  1518. " 70,\n",
  1519. " 7,\n",
  1520. " 117,\n",
  1521. " 7,\n",
  1522. " 118,\n",
  1523. " 119,\n",
  1524. " 71,\n",
  1525. " 3],\n",
  1526. " [4, 1, 1, 5, 138, 14, 2, 1, 1, 1, 12],\n",
  1527. " [2, 27, 11, 139, 140, 141, 15, 142, 8, 143, 3],\n",
  1528. " [12, 9, 14, 32, 8, 4, 59, 60, 7, 61, 2, 62, 63, 64, 65, 4, 66, 67, 3],\n",
  1529. " [97, 145, 14, 146, 147, 5, 148, 149, 23, 150, 3],\n",
  1530. " [4, 1, 1, 5, 138, 14, 2, 1, 1, 1, 12],\n",
  1531. " [4, 1, 1, 5, 138, 14, 2, 1, 1, 1, 12],\n",
  1532. " [14,\n",
  1533. " 4,\n",
  1534. " 152,\n",
  1535. " 153,\n",
  1536. " 154,\n",
  1537. " 155,\n",
  1538. " 8,\n",
  1539. " 156,\n",
  1540. " 157,\n",
  1541. " 9,\n",
  1542. " 16,\n",
  1543. " 2,\n",
  1544. " 158,\n",
  1545. " 21,\n",
  1546. " 159,\n",
  1547. " 30,\n",
  1548. " 98,\n",
  1549. " 57,\n",
  1550. " 4,\n",
  1551. " 160,\n",
  1552. " 161,\n",
  1553. " 13,\n",
  1554. " 162,\n",
  1555. " 163,\n",
  1556. " 164,\n",
  1557. " 165,\n",
  1558. " 3],\n",
  1559. " [10,\n",
  1560. " 2,\n",
  1561. " 82,\n",
  1562. " 83,\n",
  1563. " 84,\n",
  1564. " 85,\n",
  1565. " 86,\n",
  1566. " 87,\n",
  1567. " 88,\n",
  1568. " 89,\n",
  1569. " 90,\n",
  1570. " 91,\n",
  1571. " 92,\n",
  1572. " 93,\n",
  1573. " 11,\n",
  1574. " 4,\n",
  1575. " 28,\n",
  1576. " 94,\n",
  1577. " 6,\n",
  1578. " 95,\n",
  1579. " 96,\n",
  1580. " 2,\n",
  1581. " 17,\n",
  1582. " 11,\n",
  1583. " 3],\n",
  1584. " [12, 73, 20, 33, 74, 75, 5, 76, 77, 5, 7, 78, 79, 27, 80, 3],\n",
  1585. " [12, 78, 1, 24, 1, 2, 13, 11, 31, 1, 16, 1, 1, 133, 16, 1, 1, 3],\n",
  1586. " [24, 107, 24, 108, 109, 6, 2, 110, 7, 2, 34, 34, 111, 3],\n",
  1587. " [2, 27, 11, 139, 140, 141, 15, 142, 8, 143, 3],\n",
  1588. " [24, 107, 24, 108, 109, 6, 2, 110, 7, 2, 34, 34, 111, 3],\n",
  1589. " [97, 145, 14, 146, 147, 5, 148, 149, 23, 150, 3],\n",
  1590. " [4,\n",
  1591. " 112,\n",
  1592. " 113,\n",
  1593. " 15,\n",
  1594. " 114,\n",
  1595. " 35,\n",
  1596. " 10,\n",
  1597. " 68,\n",
  1598. " 115,\n",
  1599. " 69,\n",
  1600. " 8,\n",
  1601. " 23,\n",
  1602. " 116,\n",
  1603. " 5,\n",
  1604. " 18,\n",
  1605. " 36,\n",
  1606. " 11,\n",
  1607. " 4,\n",
  1608. " 70,\n",
  1609. " 7,\n",
  1610. " 117,\n",
  1611. " 7,\n",
  1612. " 118,\n",
  1613. " 119,\n",
  1614. " 71,\n",
  1615. " 3],\n",
  1616. " [12, 9, 99, 29, 100, 101, 30, 22, 58, 31, 3],\n",
  1617. " [12, 9, 99, 29, 100, 101, 30, 22, 58, 31, 3],\n",
  1618. " [120, 121, 6, 2, 122, 5, 72, 123, 3],\n",
  1619. " [1, 30, 1, 5, 1, 30, 1, 4, 1, 1, 1, 10, 1, 21, 1, 7, 1, 1, 1, 14, 1, 3],\n",
  1620. " [1,\n",
  1621. " 1,\n",
  1622. " 1,\n",
  1623. " 1,\n",
  1624. " 8,\n",
  1625. " 1,\n",
  1626. " 89,\n",
  1627. " 2,\n",
  1628. " 1,\n",
  1629. " 16,\n",
  1630. " 151,\n",
  1631. " 1,\n",
  1632. " 1,\n",
  1633. " 1,\n",
  1634. " 1,\n",
  1635. " 1,\n",
  1636. " 1,\n",
  1637. " 7,\n",
  1638. " 1,\n",
  1639. " 1,\n",
  1640. " 1,\n",
  1641. " 2,\n",
  1642. " 1,\n",
  1643. " 6,\n",
  1644. " 28,\n",
  1645. " 25,\n",
  1646. " 3]]"
  1647. ]
  1648. },
  1649. "execution_count": 5,
  1650. "metadata": {},
  1651. "output_type": "execute_result"
  1652. }
  1653. ],
  1654. "source": [
  1655. "from fastNLP import Vocabulary\n",
  1656. "vocab = Vocabulary(min_freq=2)\n",
  1657. "train_data.apply(lambda x: [vocab.add(word) for word in x['words']])\n",
  1658. "\n",
  1659. "# index句子, Vocabulary.to_index(word)\n",
  1660. "train_data.apply(lambda x: [vocab.to_index(word) for word in x['words']], new_field_name='word_seq', is_input=True)\n",
  1661. "dev_data.apply(lambda x: [vocab.to_index(word) for word in x['words']], new_field_name='word_seq', is_input=True)\n"
  1662. ]
  1663. },
  1664. {
  1665. "cell_type": "markdown",
  1666. "metadata": {},
  1667. "source": [
  1668. "## step 3\n",
  1669. " 定义模型"
  1670. ]
  1671. },
  1672. {
  1673. "cell_type": "code",
  1674. "execution_count": 6,
  1675. "metadata": {},
  1676. "outputs": [],
  1677. "source": [
  1678. "from fastNLP.models import CNNText\n",
  1679. "model = CNNText((len(vocab),50), num_classes=5, padding=2, dropout=0.1)\n"
  1680. ]
  1681. },
  1682. {
  1683. "cell_type": "markdown",
  1684. "metadata": {},
  1685. "source": [
  1686. "## step 4\n",
  1687. "开始训练"
  1688. ]
  1689. },
  1690. {
  1691. "cell_type": "code",
  1692. "execution_count": 7,
  1693. "metadata": {},
  1694. "outputs": [
  1695. {
  1696. "name": "stdout",
  1697. "output_type": "stream",
  1698. "text": [
  1699. "input fields after batch(if batch size is 2):\n",
  1700. "\twords: (1)type:numpy.ndarray (2)dtype:object, (3)shape:(2,) \n",
  1701. "\tword_seq: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 11]) \n",
  1702. "target fields after batch(if batch size is 2):\n",
  1703. "\tlabel_seq: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) \n",
  1704. "\n"
  1705. ]
  1706. },
  1707. {
  1708. "ename": "AttributeError",
  1709. "evalue": "'numpy.ndarray' object has no attribute 'contiguous'",
  1710. "output_type": "error",
  1711. "traceback": [
  1712. "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
  1713. "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
  1714. "\u001b[0;32m<ipython-input-7-4b34d005949c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mdev_data\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdev_data\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mCrossEntropyLoss\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mmetrics\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mAccuracyMetric\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m )\n\u001b[1;32m 8\u001b[0m \u001b[0mtrainer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1715. "\u001b[0;32m/Users/fdujyn/anaconda3/lib/python3.6/site-packages/fastNLP/core/trainer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, train_data, model, optimizer, loss, batch_size, sampler, update_every, n_epochs, print_every, dev_data, metrics, metric_key, validate_every, save_path, prefetch, use_tqdm, device, callbacks, check_code_level)\u001b[0m\n\u001b[1;32m 447\u001b[0m _check_code(dataset=train_data, model=model, losser=losser, metrics=metrics, dev_data=dev_data,\n\u001b[1;32m 448\u001b[0m \u001b[0mmetric_key\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmetric_key\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcheck_level\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcheck_code_level\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 449\u001b[0;31m batch_size=min(batch_size, DEFAULT_CHECK_BATCH_SIZE))\n\u001b[0m\u001b[1;32m 450\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 451\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtrain_data\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1716. "\u001b[0;32m/Users/fdujyn/anaconda3/lib/python3.6/site-packages/fastNLP/core/trainer.py\u001b[0m in \u001b[0;36m_check_code\u001b[0;34m(dataset, model, losser, metrics, batch_size, dev_data, metric_key, check_level)\u001b[0m\n\u001b[1;32m 811\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 812\u001b[0m \u001b[0mrefined_batch_x\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_build_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mbatch_x\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 813\u001b[0;31m \u001b[0mpred_dict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mrefined_batch_x\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 814\u001b[0m \u001b[0mfunc_signature\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_get_func_signature\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 815\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpred_dict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1717. "\u001b[0;32m/Users/fdujyn/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 489\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_slow_forward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 490\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 491\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 492\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mhook\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_forward_hooks\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 493\u001b[0m \u001b[0mhook_result\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mhook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1718. "\u001b[0;32m/Users/fdujyn/anaconda3/lib/python3.6/site-packages/fastNLP/models/cnn_text_classification.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, words, seq_len)\u001b[0m\n\u001b[1;32m 58\u001b[0m \u001b[0;34m:\u001b[0m\u001b[0;32mreturn\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m \u001b[0mof\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mLongTensor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mbatch_size\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnum_classes\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 59\u001b[0m \"\"\"\n\u001b[0;32m---> 60\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0membed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwords\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# [N,L] -> [N,L,C]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 61\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconv_pool\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# [N,L,C] -> [N,C]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdropout\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1719. "\u001b[0;32m/Users/fdujyn/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 489\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_slow_forward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 490\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 491\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 492\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mhook\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_forward_hooks\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 493\u001b[0m \u001b[0mhook_result\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mhook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1720. "\u001b[0;32m/Users/fdujyn/anaconda3/lib/python3.6/site-packages/fastNLP/modules/encoder/embedding.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, x)\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;34m:\u001b[0m\u001b[0;32mreturn\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTensor\u001b[0m \u001b[0;34m:\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mseq_len\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0membed_dim\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 34\u001b[0m \"\"\"\n\u001b[0;32m---> 35\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 36\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdropout\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1721. "\u001b[0;32m/Users/fdujyn/anaconda3/lib/python3.6/site-packages/torch/nn/modules/sparse.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, input)\u001b[0m\n\u001b[1;32m 106\u001b[0m return F.embedding(\n\u001b[1;32m 107\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mweight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpadding_idx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax_norm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 108\u001b[0;31m self.norm_type, self.scale_grad_by_freq, self.sparse)\n\u001b[0m\u001b[1;32m 109\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 110\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mextra_repr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1722. "\u001b[0;32m/Users/fdujyn/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py\u001b[0m in \u001b[0;36membedding\u001b[0;34m(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse)\u001b[0m\n\u001b[1;32m 1062\u001b[0m [ 0.6262, 0.2438, 0.7471]]])\n\u001b[1;32m 1063\u001b[0m \"\"\"\n\u001b[0;32m-> 1064\u001b[0;31m \u001b[0minput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcontiguous\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1065\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpadding_idx\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1066\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpadding_idx\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1723. "\u001b[0;31mAttributeError\u001b[0m: 'numpy.ndarray' object has no attribute 'contiguous'"
  1724. ]
  1725. }
  1726. ],
  1727. "source": [
  1728. "from fastNLP import Trainer, CrossEntropyLoss, AccuracyMetric\n",
  1729. "trainer = Trainer(model=model, \n",
  1730. " train_data=train_data, \n",
  1731. " dev_data=dev_data,\n",
  1732. " loss=CrossEntropyLoss(),\n",
  1733. " metrics=AccuracyMetric()\n",
  1734. " )\n",
  1735. "trainer.train()\n",
  1736. "print('Train finished!')\n"
  1737. ]
  1738. },
  1739. {
  1740. "cell_type": "markdown",
  1741. "metadata": {},
  1742. "source": [
  1743. "### 本教程结束。更多操作请参考进阶教程。"
  1744. ]
  1745. },
  1746. {
  1747. "cell_type": "code",
  1748. "execution_count": null,
  1749. "metadata": {},
  1750. "outputs": [],
  1751. "source": []
  1752. }
  1753. ],
  1754. "metadata": {
  1755. "kernelspec": {
  1756. "display_name": "Python 3",
  1757. "language": "python",
  1758. "name": "python3"
  1759. },
  1760. "language_info": {
  1761. "codemirror_mode": {
  1762. "name": "ipython",
  1763. "version": 3
  1764. },
  1765. "file_extension": ".py",
  1766. "mimetype": "text/x-python",
  1767. "name": "python",
  1768. "nbconvert_exporter": "python",
  1769. "pygments_lexer": "ipython3",
  1770. "version": "3.6.7"
  1771. }
  1772. },
  1773. "nbformat": 4,
  1774. "nbformat_minor": 1
  1775. }