My version changes

This commit is contained in:
Vladislav Khorev 2018-07-10 16:32:52 +05:00
parent 53cda0173c
commit 4448590ddc
18 changed files with 11906 additions and 40011 deletions

View File

@ -32,7 +32,7 @@ else
os.exit() os.exit()
end end
checkpoint = torch.load(opt.load_model) checkpoint = torch.load(opt.load_model, 'ascii')
checkpoint.protos.rnn:double() checkpoint.protos.rnn:double()
checkpoint.protos.criterion:double() checkpoint.protos.criterion:double()
torch.save(opt.save_file, checkpoint) torch.save(opt.save_file, checkpoint, 'ascii')

18
data/hongloumeng/data.t7 Executable file

File diff suppressed because one or more lines are too long

1562
data/hongloumeng/input.txt Executable file

File diff suppressed because one or more lines are too long

9854
data/hongloumeng/vocab.t7 Executable file

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -26,7 +26,7 @@ if opt.gpuid >= 0 then
cutorch.setDevice(opt.gpuid + 1) cutorch.setDevice(opt.gpuid + 1)
end end
local model = torch.load(opt.model) local model = torch.load(opt.model, 'ascii')
print('opt:') print('opt:')
print(model.opt) print(model.opt)

414
package-lock.json generated Executable file
View File

@ -0,0 +1,414 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"aphrodite": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/aphrodite/-/aphrodite-0.3.1.tgz",
"integrity": "sha1-1VqdH79WqKoM06kqdu9U1qn/04U=",
"requires": {
"asap": "2.0.6",
"inline-style-prefix-all": "1.0.5"
}
},
"asap": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY="
},
"bowser": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/bowser/-/bowser-1.9.4.tgz",
"integrity": "sha512-9IdMmj2KjigRq6oWhmwv1W36pDuA4STQZ8q6YO9um+x07xgYNCD3Oou+WP/3L1HNz7iqythGet3/p4wvc8AAwQ=="
},
"chain-function": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/chain-function/-/chain-function-1.0.0.tgz",
"integrity": "sha1-DUqzfn4Y6tC9xHuSB2QRjOWHM9w="
},
"chat-template": {
"version": "0.0.26",
"resolved": "https://registry.npmjs.org/chat-template/-/chat-template-0.0.26.tgz",
"integrity": "sha1-BtAYa0896aqN3IsAUPGptZcvI6M=",
"requires": {
"aphrodite": "0.3.1",
"material-ui": "0.15.0",
"object-assign-deep": "0.0.4",
"react-addons-css-transition-group": "15.1.0",
"react-dom": "15.1.0",
"react-scroll": "1.7.9",
"react-scrollbar": "0.5.4"
}
},
"computed-style": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/computed-style/-/computed-style-0.1.4.tgz",
"integrity": "sha1-fzRP2FhLLkJb7cpKGvwOMAuwXXQ="
},
"config": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/config/-/config-1.30.0.tgz",
"integrity": "sha1-HWCp81NIoTwXV5jThOgaWhbDum4=",
"requires": {
"json5": "0.4.0",
"os-homedir": "1.0.2"
}
},
"core-js": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz",
"integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY="
},
"dom-helpers": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.3.1.tgz",
"integrity": "sha512-2Sm+JaYn74OiTM2wHvxJOo3roiq/h25Yi69Fqk269cNUwIXsCvATB6CRSFC9Am/20G2b28hGv/+7NiWydIrPvg=="
},
"encoding": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
"integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
"requires": {
"iconv-lite": "0.4.23"
}
},
"fbjs": {
"version": "0.8.17",
"resolved": "https://registry.npmjs.org/fbjs/-/fbjs-0.8.17.tgz",
"integrity": "sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90=",
"requires": {
"core-js": "1.2.7",
"isomorphic-fetch": "2.2.1",
"loose-envify": "1.3.1",
"object-assign": "4.1.1",
"promise": "7.3.1",
"setimmediate": "1.0.5",
"ua-parser-js": "0.7.18"
}
},
"hoist-non-react-statics": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz",
"integrity": "sha1-qkSM8JhtVcxAdzsXF0t90GbLfPs="
},
"iconv-lite": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz",
"integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==",
"requires": {
"safer-buffer": "2.1.2"
}
},
"inline-style-prefix-all": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/inline-style-prefix-all/-/inline-style-prefix-all-1.0.5.tgz",
"integrity": "sha1-5uWMpErbcds2o0mdX17FWXoxM7Y="
},
"inline-style-prefixer": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/inline-style-prefixer/-/inline-style-prefixer-1.0.4.tgz",
"integrity": "sha1-hJ9lc3Olz72BQc/dsBPfb2jG3zk=",
"requires": {
"bowser": "1.9.4",
"inline-style-prefix-all": "2.0.2"
},
"dependencies": {
"inline-style-prefix-all": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/inline-style-prefix-all/-/inline-style-prefix-all-2.0.2.tgz",
"integrity": "sha1-ROI8ANNSGjYEHgfJsegb82dwsIw="
}
}
},
"is-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
},
"isomorphic-fetch": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz",
"integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=",
"requires": {
"node-fetch": "1.7.3",
"whatwg-fetch": "2.0.4"
}
},
"js-tokens": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
"integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls="
},
"json5": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-0.4.0.tgz",
"integrity": "sha1-BUNS5MTIDIbAkjh31EneF2pzLI0="
},
"keycode": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/keycode/-/keycode-2.2.0.tgz",
"integrity": "sha1-PQr1bce4uOXLqNCpfxByBO7CKwQ="
},
"line-height": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/line-height/-/line-height-0.1.1.tgz",
"integrity": "sha1-6GcF+/Cm9QYHrtZVANadstnbN+I=",
"requires": {
"computed-style": "0.1.4"
}
},
"lodash": {
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
},
"lodash.merge": {
"version": "4.6.1",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.1.tgz",
"integrity": "sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ=="
},
"lodash.throttle": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz",
"integrity": "sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ="
},
"loose-envify": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz",
"integrity": "sha1-0aitM/qc4OcT1l/dCsi3SNR4yEg=",
"requires": {
"js-tokens": "3.0.2"
}
},
"material-ui": {
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/material-ui/-/material-ui-0.15.0.tgz",
"integrity": "sha1-6AnYz3gdiSYYOCcEFvy+ElHUipU=",
"requires": {
"inline-style-prefixer": "1.0.4",
"keycode": "2.2.0",
"lodash.merge": "4.6.1",
"lodash.throttle": "4.1.1",
"react-addons-create-fragment": "15.6.2",
"react-addons-transition-group": "15.6.2",
"react-addons-update": "15.6.2",
"react-event-listener": "0.1.2",
"recompose": "0.17.0",
"simple-assign": "0.1.0",
"warning": "2.1.0"
}
},
"node-fetch": {
"version": "1.7.3",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
"requires": {
"encoding": "0.1.12",
"is-stream": "1.1.0"
}
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"object-assign-deep": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/object-assign-deep/-/object-assign-deep-0.0.4.tgz",
"integrity": "sha1-KzNshsqrOOusVe/zn/TfYJR++/M=",
"requires": {
"object-assign": "2.0.0",
"underscore": "1.7.0"
},
"dependencies": {
"object-assign": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-2.0.0.tgz",
"integrity": "sha1-+DCbCQg7ASYezj73Nz8rV7jdcEI="
}
}
},
"os-homedir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
"integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M="
},
"performance-now": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-0.2.0.tgz",
"integrity": "sha1-M+8wxcd9TqIcWlOGnZG1bY8lVeU="
},
"promise": {
"version": "7.3.1",
"resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",
"integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==",
"requires": {
"asap": "2.0.6"
}
},
"prop-types": {
"version": "15.6.2",
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz",
"integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==",
"requires": {
"loose-envify": "1.3.1",
"object-assign": "4.1.1"
}
},
"raf": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/raf/-/raf-3.4.0.tgz",
"integrity": "sha512-pDP/NMRAXoTfrhCfyfSEwJAKLaxBU9eApMeBPB1TkDouZmvPerIClV8lTAd+uF8ZiTaVl69e1FCxQrAd/VTjGw==",
"requires": {
"performance-now": "2.1.0"
},
"dependencies": {
"performance-now": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
}
}
},
"react-addons-create-fragment": {
"version": "15.6.2",
"resolved": "https://registry.npmjs.org/react-addons-create-fragment/-/react-addons-create-fragment-15.6.2.tgz",
"integrity": "sha1-o5TefCx77Na1R1uhuXrEcs58dPg=",
"requires": {
"fbjs": "0.8.17",
"loose-envify": "1.3.1",
"object-assign": "4.1.1"
}
},
"react-addons-css-transition-group": {
"version": "15.1.0",
"resolved": "https://registry.npmjs.org/react-addons-css-transition-group/-/react-addons-css-transition-group-15.1.0.tgz",
"integrity": "sha1-BXAkppk4akeh/35IshOKCtApHxQ="
},
"react-addons-transition-group": {
"version": "15.6.2",
"resolved": "https://registry.npmjs.org/react-addons-transition-group/-/react-addons-transition-group-15.6.2.tgz",
"integrity": "sha1-i668Kukczb8kX+Kcn9PTb4tHGSM=",
"requires": {
"react-transition-group": "1.2.1"
}
},
"react-addons-update": {
"version": "15.6.2",
"resolved": "https://registry.npmjs.org/react-addons-update/-/react-addons-update-15.6.2.tgz",
"integrity": "sha1-5TdTxbNIh5dFEMiC1/sHWFHV5QQ=",
"requires": {
"fbjs": "0.8.17",
"object-assign": "4.1.1"
}
},
"react-dom": {
"version": "15.1.0",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-15.1.0.tgz",
"integrity": "sha1-0MKyTItHpBornsdmZi1OaG81MVM="
},
"react-event-listener": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/react-event-listener/-/react-event-listener-0.1.2.tgz",
"integrity": "sha1-8f0vDFCEAT6VuLOsP7DR1M3kKBM="
},
"react-motion": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/react-motion/-/react-motion-0.5.2.tgz",
"integrity": "sha512-9q3YAvHoUiWlP3cK0v+w1N5Z23HXMj4IF4YuvjvWegWqNPfLXsOBE/V7UvQGpXxHFKRQQcNcVQE31g9SB/6qgQ==",
"requires": {
"performance-now": "0.2.0",
"prop-types": "15.6.2",
"raf": "3.4.0"
}
},
"react-scroll": {
"version": "1.7.9",
"resolved": "https://registry.npmjs.org/react-scroll/-/react-scroll-1.7.9.tgz",
"integrity": "sha512-baTwyz2FxaZWZ/4yEAWQEGE4CMZzGj/AjvLu/x4xmAisFgSAq3D0QED3deI6D4zeJTSEmeuy8Hm01IS+IDbKIg==",
"requires": {
"lodash.throttle": "4.1.1",
"prop-types": "15.6.2"
}
},
"react-scrollbar": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/react-scrollbar/-/react-scrollbar-0.5.4.tgz",
"integrity": "sha512-6t9ztrXipoJJcdS7qXOOXfdnuN16Y862Sy5m0vSDFG8hwmiaJ7JDSkRW4VGaYfgnIcYi7HGvCn/mimDz6uVgXQ==",
"requires": {
"config": "1.30.0",
"line-height": "0.1.1",
"react-motion": "0.5.2"
}
},
"react-transition-group": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-1.2.1.tgz",
"integrity": "sha512-CWaL3laCmgAFdxdKbhhps+c0HRGF4c+hdM4H23+FI1QBNUyx/AMeIJGWorehPNSaKnQNOAxL7PQmqMu78CDj3Q==",
"requires": {
"chain-function": "1.0.0",
"dom-helpers": "3.3.1",
"loose-envify": "1.3.1",
"prop-types": "15.6.2",
"warning": "3.0.0"
},
"dependencies": {
"warning": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/warning/-/warning-3.0.0.tgz",
"integrity": "sha1-MuU3fLVy3kqwR1O9+IIcAe1gW3w=",
"requires": {
"loose-envify": "1.3.1"
}
}
}
},
"recompose": {
"version": "0.17.0",
"resolved": "https://registry.npmjs.org/recompose/-/recompose-0.17.0.tgz",
"integrity": "sha1-uyGGF1djT1OzgpOoSYyP5uKEmx8=",
"requires": {
"hoist-non-react-statics": "1.2.0",
"lodash": "4.17.10"
}
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
},
"simple-assign": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/simple-assign/-/simple-assign-0.1.0.tgz",
"integrity": "sha1-F/0wZqXz13OPUDIbsPFMooHMS6o="
},
"ua-parser-js": {
"version": "0.7.18",
"resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.18.tgz",
"integrity": "sha512-LtzwHlVHwFGTptfNSgezHp7WUlwiqb0gA9AALRbKaERfxwJoiX0A73QbTToxteIAuIaFshhgIZfqK8s7clqgnA=="
},
"underscore": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz",
"integrity": "sha1-a7rwh3UA02vjTsqlhODbn+8DUgk="
},
"warning": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/warning/-/warning-2.1.0.tgz",
"integrity": "sha1-ISINnGOvx3qMkhEeARr3Bc4MaQE=",
"requires": {
"loose-envify": "1.3.1"
}
},
"whatwg-fetch": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz",
"integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng=="
}
}
}

View File

@ -35,9 +35,21 @@ cmd:option('-verbose',1,'set to 0 to ONLY print the sampled text, no diagnostics
cmd:option('-stop','\n\n\n\n\n','stop sampling when detected') cmd:option('-stop','\n\n\n\n\n','stop sampling when detected')
cmd:text() cmd:text()
-- parse input params -- parse input params
opt = cmd:parse(arg) opt = cmd:parse(arg)
fileInput = io.open("D:\\Work\\nodejsprojects\\rnn-chat-backend\\input.txt", 'r')
oneLine = fileInput:read()
opt.primetext = string.gsub(oneLine, "\n", "")
fileInput:close()
--opt.primetext = "恍恍惚惚"
-- gated print: simple utility function wrapping a print -- gated print: simple utility function wrapping a print
function gprint(str) function gprint(str)
if opt.verbose == 1 then print(str) end if opt.verbose == 1 then print(str) end
@ -64,7 +76,7 @@ torch.manualSeed(opt.seed)
if not lfs.attributes(opt.model, 'mode') then if not lfs.attributes(opt.model, 'mode') then
gprint('Error: File ' .. opt.model .. ' does not exist. Are you sure you didn\'t forget to prepend cv/ ?') gprint('Error: File ' .. opt.model .. ' does not exist. Are you sure you didn\'t forget to prepend cv/ ?')
end end
checkpoint = torch.load(opt.model) checkpoint = torch.load(opt.model, 'ascii')
protos = checkpoint.protos protos = checkpoint.protos
protos.rnn:evaluate() -- put in eval mode so that dropout works properly protos.rnn:evaluate() -- put in eval mode so that dropout works properly
@ -110,6 +122,9 @@ function get_char(str)
left = left + i left = left + i
unordered[#unordered+1] = tmpString unordered[#unordered+1] = tmpString
end end
print("get_char wordlen" .. wordLen)
return unordered return unordered
end end
@ -173,5 +188,11 @@ for i=1, opt.length do
if string.find(result, opt.stop) then break end if string.find(result, opt.stop) then break end
end end
io.write(result) io.write(result)
fd = io.open('C:\\Users\\MACHENIKE\\Downloads\\char-rnn-chinese-master\\temp.txt', 'w')
fd:write(result)
fd:close()
io.write('\n') io.flush() io.write('\n') io.flush()

1
temp.txt Executable file
View File

@ -0,0 +1 @@
,或者同你们病要,我也要递一个,我也想不到这里来,并不是这个名姓。”秋纹笑道:“原来这样,我们小姐和二家商议话叫我情儿. "凤姐笑话也还说:“宝兄弟。”湘莲道:“是外头有人做你.他就是有那么一到的,我一天的糊涂了,说了多穿鲜鹿丸去.这今分一半好,才好了,可见我这么个手心。”

View File

@ -70,10 +70,35 @@ cmd:option('-decay_ss', 0.005, 'ss amount decay rate of each epoch')
cmd:option('-min_ss', 0.9, 'minimum amount of truth data to be given to the model when using ss') cmd:option('-min_ss', 0.9, 'minimum amount of truth data to be given to the model when using ss')
cmd:text() cmd:text()
-- parse input params -- parse input params
opt = cmd:parse(arg) opt = cmd:parse(arg)
torch.manualSeed(opt.seed) torch.manualSeed(opt.seed)
math.randomseed(opt.seed) math.randomseed(opt.seed)
-- Xperimental -- Vladislav Khorev vladislav.khorev@fishrungames.com/oxford-cs-ml-2015/practical6
--[[
opt.rnn_size = 16
opt.gpuid = -1
opt.seq_length = 2
opt.batch_size = 2
opt.data_dir='data/hongloumeng'
opt.num_layers = 1
]]
opt.min_freq = 10
opt.rnn_size = 512
opt.gpuid = 0
opt.seq_length = 50
opt.batch_size = 50
opt.data_dir='data/hongloumeng'
opt.num_layers = 2
-- train / val / test split for data, in fractions -- train / val / test split for data, in fractions
local test_frac = math.max(0, 1 - (opt.train_frac + opt.val_frac)) local test_frac = math.max(0, 1 - (opt.train_frac + opt.val_frac))
local split_sizes = {opt.train_frac, opt.val_frac, test_frac} local split_sizes = {opt.train_frac, opt.val_frac, test_frac}
@ -126,7 +151,7 @@ if not path.exists(opt.checkpoint_dir) then lfs.mkdir(opt.checkpoint_dir) end
local do_random_init = true local do_random_init = true
if string.len(opt.init_from) > 0 then if string.len(opt.init_from) > 0 then
print('loading an LSTM from checkpoint ' .. opt.init_from) print('loading an LSTM from checkpoint ' .. opt.init_from)
local checkpoint = torch.load(opt.init_from) local checkpoint = torch.load(opt.init_from, 'ascii')
protos = checkpoint.protos protos = checkpoint.protos
-- make sure the vocabs are the same -- make sure the vocabs are the same
local vocab_compatible = true local vocab_compatible = true
@ -357,7 +382,7 @@ for i = 1, iterations do
checkpoint.i = i checkpoint.i = i
checkpoint.epoch = epoch checkpoint.epoch = epoch
checkpoint.vocab = loader.vocab_mapping checkpoint.vocab = loader.vocab_mapping
torch.save(savefile, checkpoint) torch.save(savefile, checkpoint, 'ascii')
end end
if i % opt.print_every == 0 then if i % opt.print_every == 0 then

8
util/CharSplitLMMinibatchLoader.lua Normal file → Executable file
View File

@ -39,8 +39,8 @@ function CharSplitLMMinibatchLoader.create(data_dir, batch_size, seq_length, spl
end end
print('loading data files...') print('loading data files...')
local data = torch.load(tensor_file) local data = torch.load(tensor_file, 'ascii')
self.vocab_mapping = torch.load(vocab_file) self.vocab_mapping = torch.load(vocab_file, 'ascii')
-- cut off the end so that it divides evenly -- cut off the end so that it divides evenly
local len = data:size(1) local len = data:size(1)
@ -226,9 +226,9 @@ function CharSplitLMMinibatchLoader.text_to_tensor(in_textfile, out_vocabfile, o
-- save output preprocessed files -- save output preprocessed files
print('saving ' .. out_vocabfile) print('saving ' .. out_vocabfile)
torch.save(out_vocabfile, vocab_mapping) torch.save(out_vocabfile, vocab_mapping, 'ascii')
print('saving ' .. out_tensorfile) print('saving ' .. out_tensorfile)
torch.save(out_tensorfile, data) torch.save(out_tensorfile, data, 'ascii')
end end
return CharSplitLMMinibatchLoader return CharSplitLMMinibatchLoader

0
util/JSON.lua Normal file → Executable file
View File

0
util/OneHot.lua Normal file → Executable file
View File

0
util/misc.lua Normal file → Executable file
View File

0
util/model_utils.lua Normal file → Executable file
View File

View File

@ -36,7 +36,7 @@ end
if not lfs.attributes(model_file, 'mode') then if not lfs.attributes(model_file, 'mode') then
print('Error: File ' .. model_file .. ' does not exist.') print('Error: File ' .. model_file .. ' does not exist.')
end end
checkpoint = torch.load(model_file) checkpoint = torch.load(model_file, 'ascii')
protos = checkpoint.protos protos = checkpoint.protos
protos.rnn:evaluate() -- put in eval mode so that dropout works properly protos.rnn:evaluate() -- put in eval mode so that dropout works properly