node-word2vec
node-word2vec copied to clipboard
Error loadModel
I download from 'Word2Vec' http://nilc.icmc.usp.br/embeddings
this http://143.107.183.175:22980/download.php?file=embeddings/word2vec/cbow_s50.zip
And try to load
var w2v2 = require( 'word2vec' );
w2v2.loadModel( 'C:\Users\Ranieri\Documents\Projetos\playground\datas.txt', function( error, model ) {
console.log(error)
console.log( model );
});
but nothing happens
Node 8.11
Add some logging to the node_modules/word2vec/lib/model.js file and you might find some answers. My issue was that I was trying to load a .json file. The init function has a switch statement with no default case. I added a default case to throw an error. Try this.
function init( file ) {
var mime_type = mime.getType( file );
switch ( mime_type ) {
case 'text/plain':
console.log('File type is text/plain')
readTxt( file );
break;
case 'application/octet-stream':
console.log('File type octet-stream')
readBinary( file );
break;
default: throw new Error( 'Invalid file type!' );
}
}
init( file );
@Mattperkinsee Please respect the callback and don't just throw your own errors, since the callback explicitly defines it:
https://github.com/Planeshifter/node-word2vec/pull/27/files
Thanks for the info. I installed from npm and my model.js file didn't have a default case which I assumed might occur with others. My package.json file shows version 1.1.5. What am I missing?
@Mattperkinsee loadModel
takes a callback and calls it with (error, model)
, which is not given with your code.
So you raise an error, but then have to catch it via try/catch and cannot rely on the given API just in that error case.
Just pointing out the existing API, good that you got it to work!