Advice on using in web server #276
Comments
There are a few npm packages floating around out there -- |
in my experience, a node |
gensim has a pretty full featured wrapper with bindings for all the parameters |
@loretoparisi Just to note that your problem there can be memory. The model may typically comprise several hundreds of megabytes, possibly approaching one GB, replicated in each worker child process running the fasttext executable. A further scalable solution may involve using the original fasttext C api, from a good C/C++ web server (provided that queries are batched such that the http communication costs are amortized). Or making a PR to load a model from shared memory. |
@matanster thanks for point this out. In my experience I do not have memory leaks in the library, of course if you do pre-processing of the training/test set is better or use node.js streaming api. The response time of the model using a node var fastText = new FastText({
serializeTo: './band_model',
trainFile: './band_train.txt'
});
fastText.train()
.then(done=> {
console.log("train done.");
})
.catch(error => {
console.error(error);
}) the var sample="Our Twitter run by the band and crew to give you an inside look into our lives on the road. Get #FutureHearts now: http://smarturl.it/futurehearts";
fastText.load()
.then(done => {
return fastText.predict(sample);
})
.then(labels=> {
console.log("TEXT:", sample, "\nPREDICT:",labels );
sample="LBi Software provides precisely engineered, customer-focused #HRTECH solutions. Our flagship solution, LBi HR HelpDesk, is a SaaS #HR Case Management product.";
return fastText.predict(sample);
})
.then(labels=> {
console.log("TEXT:", sample, "\nPREDICT:",labels );
fastText.unload();
})
.catch(error => {
console.error(error);
}); in your running web service instance. See fasttext.js for more details. |
@loretoparisi in the shared memory suggestion, I meant OS shared memory, so that the model occupies a single copy for all spun up fasttext processes, to reduce memory consumption for concurrent implementations. Not because it is better than teasing apart fasttext into a proper library, but because it might be easier to get a PR merged with this small additional feature. But as to latency, I recall getting a response time of around 1.5 msec per single sentence in my clojure server implementation, so 200 msecs per response sounds a little odd. I mean it is closer to starting a fasttext process for every request, which I recall taking about 0.5 msecs. These measurements were taken on a 6th generation i7. (One or both of us surely have their numbers or implementation wrong). 200 msecs is really a lot for this, unless you're actually talking about predicting a large set of inputs in one request. |
@matanster thanks for your stats. The 200msec response time is at json api level i.e. express api response time let's say the call to |
@loretoparisi please can you tell me how |
@myoldusername that sounds like a php specific question. the php exec method doesnt seem to have a way to capture output of a running process and to stream new queries into it. maybe there is some hack you can do with by comparison node allows you to spawn a child process and then continuously listen for |
@dcsan thank you for your reply , well i can not use node since my the node fasttext needs centos >= 7. some one told me this :
But when i send string to the " |
you need to add the |
@dcsan it's seems very hard to me to do this .... OMG LOL Now the
Send a i want to send Please kindly may you help me with this ! |
@myoldusername maybe you want to send to background a process with input and feed contents from another window? This is possibile using that process (fasttext in background) pid from the secondo screen. |
@loretoparisi please kindly may show me a small demo how can i do it? Please, honestly i gave up... |
@myoldusername well a quick and dirty solution is using a
and in another shell you do:
so you will get
A better approach will be to get the output redirection in your client command line like this:
and then something like
but this could be a bit tricky to be handled. I strongly suggest a wrapper like my node client or a python btw. |
wow, nice tips @loretoparisi ! @myoldusername you could try getting a free node hosting, there are lots of options. It does seem php doesn't have good support for this type of streaming i/o to system level tasks which is what node really excels at. Python has generally better NLP libraries though, but the higher level support for fastText seems to be lagging a generation behind. |
@loretoparisi i love to use node but it seems the fastText thats compiled with it only works on CentOS 7, is thete a workaround for this. My centos is 6.9 and getting a free one is not a solution, traffic is involved. Otherwise wit service is available. But i love locally apps Regarding your example, thank you very much, but can i replace node fastText tool with the one i already compiled in my box? Regards |
@myoldusername yes just replace the executable file in bin folder here. I will update the library soon with a better implementation that handles system wide executable installation (so it will work if you have like |
I have updated fasttext.js with a better child process handing, bug fixes and a full working server prediction api example. |
Hello all, Thank you for working on this together. Can we consider this issue resolved or should we keep it open? Thanks, |
I suppose it would make sense to update the documentation to point to the unofficial but reasonably popular libs for various languages - wrappers, or anything else tightly integrated with fastText. At least that is the approach I see similar libs taking. Somebody ctrl+Fing https://github.com/facebookresearch/fastText or searching the whole site or whole repo for |
It's helpful IMHO, if the library turned into a library in the sense of providing a safe API, rather than having only a main function and wrappers in other languages. We do not all want to use node.js, and there'd be further benefit in a flexible API enabling a "proper" embedding. Sure, node.js is fast, but there's a limit to how much throughput you can get off a single fasttext process. Nor is fasttext necessarily known to be tested, as a long-running daemon-like process. Right now fasttext is not really a library just yet, apart from having some python API. It is a command line with a (python) API, and you cannot use it at ultra-high concurrency until an API has been designed to use one copy of the model in memory for prediction by many threads/processes. Unless you are willing to have the model duplicated in RAM by the number of disparate processes/threads making predictions over it (models start at 0.5GB typically), it's going to be highly wasteful or just restrictive. It is pretty fast in prediction, but the C++ code base should be relatively easy to refactor into a library with better concurrency support and testing. |
@matanster that makes sense, in my experience just consider that if you run inference from the compiled
Regarding I agree that it cannot be used as-it-is if you want to achieve the best performances as a web service and if you will to handle concurrency and multi-threading, there is need for a new C++ wrapper for that, but I beat that this is not the aim of this library as it is here, maybe some different repo. |
I find there is no need for this library to implement a web server/service. It suffice for it to expose a concurrency considerate C++ API, to let other do just that. Right now I doubt it is should be called a library, other than providing a python API it is a tool, and the distance for making the C++ code a library is so small. |
Is there any advice about how to use fasttext on a production web server?
The text was updated successfully, but these errors were encountered: