Giter Club home page Giter Club logo

Comments (4)

jenojp avatar jenojp commented on May 22, 2024 1

Hi - there could be two issues here:

  1. you're limiting the entity types to PERSON or ORG that you're doing negation on.
  2. Even if you weren't limiting types, there are no entities in the example that show up using "en_core_web_sm".

You can create and entity ruler . See the example below where football is negated by cannot which is a preceding term in the "en" termset. If you want to change termsets, see this example.

import spacy
from negspacy.negation import Negex
from negspacy.termsets import termset

ts = termset("en")

nlp = spacy.load("en_core_web_sm")

ruler = nlp.add_pipe("entity_ruler")
patterns = [{"label": "SPORT", "pattern": "football"},
            {"label": "SPORT", "pattern": [{"LOWER": "ice"}, {"LOWER": "hockey"}]}]
ruler.add_patterns(patterns)

nlp.add_pipe(
    "negex",
    config={
        "neg_termset":ts.get_patterns()
    }
)

doc = nlp("Men cannot play football.")

for e in doc.ents:
    print(e.text, e._.negex)

from negspacy.

SallyBean avatar SallyBean commented on May 22, 2024

Thanks so much for your help! This makes sense. Apologies for the delay in getting back to you.

Although, if I replace 'football' with 'hockey' in the doc - nothing is returned - am I missing something else?

Huge apologies, I'm very new to this and learning.

from negspacy.

jenojp avatar jenojp commented on May 22, 2024

So for the example code I pasted above, it's looking specifically for 'ice hockey' not just 'hockey'. If you changed the patterns to remove 'ice' as shown below then it would work.

            {"label": "SPORT", "pattern": [{"LOWER": "hockey"}]}]

from negspacy.

SallyBean avatar SallyBean commented on May 22, 2024

Thanks @jenojp, this is really helpful!

from negspacy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.