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.

Changes to nlp clone still affects original nlp

See original GitHub issue

Hi I’m trying to use multiple instances of nlp each with different plugins nlp.clone().extend(). However, since the world variable is global, any changes effect all nlp instances.

This can be seen by updating the following test and adding a copy of the first check to the end.

https://github.com/spencermountain/compromise/blob/51f1f158e6fcab14cdbf14f182b0c41f94e513e7/tests/plugin/addWords.test.js#L6-L8

test('persistent-lexicon-change', function(t) {
  let nlp2 = nlp.clone()
  let doc = nlp('he is marko')
  t.equal(doc.match('#Place+').length, 0, 'default-no-place')
  t.equal(doc.match('#Person+').length, 1, 'default-one-person')

  nlp2.extend((Doc, world) => {
    world.addWords({
      marko: 'Place',
    })
  })
  doc = nlp2('he is marko')
  t.equal(doc.match('#Place+').length, 1, 'now-one-place')
  t.equal(doc.match('#Person+').length, 0, 'now-no-person')

 // ....

  // Tests fail here - original nlp should not be affected?
  doc = nlp('he is marko')
  t.equal(doc.match('#Place+').length, 0, 'default-no-place')
  t.equal(doc.match('#Person+').length, 1, 'default-one-person')

  t.end()
})

Am I misunderstanding the intention behind the clone() function? Thanks in advance!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Drache93commented, Jan 14, 2020

True, but we’d only do it because a person specifically chose to make a fresh instance, so their choosing to using more memory 😄.

Maybe we just fix clone to create a fresh instance with cloned world? Breaking change if people are using it currently with the assumption changes go backwards. So no global world, and no new worlds. Just selective cloning. Again can always have a Boolean for empty clone.

1reaction
Drache93commented, Jan 14, 2020

Haha 😄 .new feels weird in JS. Also it’s not original or default considering it’s still uses the global world (could always add a Boolean for totally fresh)

Shame clone is used 😄 copy()?

Edit: Maybe the global world thing is confusing. Maybe with argument or extra function the choices are: new nlp with world cloned from old one, or nlp with fresh world. No global extend/world.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Unreasonable Progress of Deep Neural Networks in ...
Big Changes in Natural Language Processing (NLP Due to Deep Learning. Humans have a lot of senses, and yet our sensory experiences are ......
Read more >
Does not 'removing the stopwords' affect Natural Language ...
Removing such words from the text almost always changes the meaning drastically. The questions are: How reliable is removing stopwords? Does it ...
Read more >
Natural language processing to identify the creation and ...
NLP to develop new measures for novelty and impact based on patent text. Validate improvement over measures based on patent classification and citations....
Read more >
A Survey of Data Augmentation Approaches for NLP
Data augmentation has recently seen increased interest in NLP due to more work in low- resource domains, new tasks, and the popu-.
Read more >
Natural language processing: an introduction - PMC - NCBI
NLP began in the 1950s as the intersection of artificial intelligence and linguistics. NLP was originally distinct from text information retrieval (IR), which ......
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