question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need help in optimization

See original GitHub issue

Hi,

Thanks for this great library.

I have a use case related to multiple domains where I will have to do nlp.clone() multiple times in order not to overlap lexicon information related to one domain with another.

Currently, each nlp.clone() call is taking approx. 160ms. So, for 40 domains it is taking approximately 6 seconds. Any better way of doing this?

var nlp = require('compromise');
const performance = require('perf_hooks').performance;
var totalTime = 0;
var numOfDomains = 40;
for(var i = 0; i < numOfDomains; i++){
  var t0 = performance.now();
  var _nlp = nlp.clone();
  var t1 = performance.now();
  var diff = (t1 - t0); 
  totalTime += diff;
}
console.log("Time taken for " + numOfDomains + " apps is approx. " + Math.round(totalTime / 1000) + " Seconds");

Time taken for 40 apps is approx. 6 Seconds

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sheikirfanbashacommented, Jul 20, 2019

@spencermountain Yes. Replaced nlp.clone() with below code

function doClone(text, _nlp, lexicon){
	var nlp = _nlp.bind({});
	var doc = nlp(text);
	doc.world().plugin(lexicon);
	doc.tagger();
	return doc;
}
1reaction
sheikirfanbashacommented, Jul 19, 2019

hey @sheikirfanbasha thanks, that’s an interesting problem. I think you’re doing everything right.

The nlp.clone() is a bit of a mess - but the main task is to run a deep-clone on the World object. All of the linguistic data is on that thing, so it’s understandable to take a few-dozen milliseconds to do it each time.

The good part is that you probably don’t need to completely clone the whole dataset each time. If you’re making small changes to the lexicon, you may be able to get around it with some clever hacks.

this is rough, but maybe something like this?

let nlp2 = nlp.bind({});

let doc1 = nlp('it was slow');
let doc2 = nlp2('it was slow', { slow: 'NewTag' });

doc1.debug();
//default behaviour
doc2.debug();
//has #NewTag

to be honest, now that I think about it, that’s probably how nlp.clone() should work 😉

let me know how it comes along. You could also do nlp.tokenize() (which doesn’t touch the word-data), then set World values directly, then run .tagger().

cheers

@spencermountain Thanks for the prompt reply! I used your suggestion of setting the world values directly and then running .tagger(). Performance is much better now! Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimization - Calculus I - Pauls Online Math Notes
In this section we are going to look at optimization problems. In optimization problems we are looking for the largest value or the...
Read more >
10 Steps for Improving Business Optimization (With Benefits)
Optimization can help businesses with their internal and external operations, depending on their unique needs.
Read more >
Optimization Problems - Calculus - YouTube
This calculus video explains how to solve optimization problems. It explains how to solve the fence along the river problem, ...
Read more >
How to Solve ANY Optimization Problem [Calc 1] - YouTube
Optimization problems are like men. They're all the same amirite? … Show more. Show more. Key moments. View all. Solving for W.
Read more >
How to Solve Optimization Problems in Calculus - Matheno.com
Need to solve Optimization problems in Calculus? Let's break 'em down and develop a strategy that you can use to solve them routinely...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found