Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can we display multiple records in displacy in spacy

Tags:

spacy

I have been using space for quite some-time and I really liked the displacy

Is there a way where we can serve multiple texts from my data-set in the web-page as-in a small arrow to redirect to next record and mark the entities. The code I'm using is as follows.

def validate(VAL_DATA):
nlp = spacy.load(args.model + '/nn')
for text, _ in VAL_DATA:
    doc = nlp(text)
    displacy.serve(doc, style='ent')
    for ent in doc.ents:
        print("entity: " + ent.label_ +"\t" + "text: " + ent.text)

VAL_DATA is my validation set and it has multiple records in it.

Thanks in advance.

like image 622
user3398900 Avatar asked Nov 07 '22 16:11

user3398900


1 Answers

Not sure if I got your question right, but if you want to mark entities found for mulitple docs you can just do the following:

def validate(VAL_DATA):
    nlp = spacy.load(args.model + '/nn')
    docs = list(nlp.pipe(VAL_DATA))
    entities = [doc.ents for doc in docs]
    displacy.serve(docs, style="ent")

At least for me it worked just fine. Might work fo you too?

like image 150
ChrisDelClea Avatar answered Nov 12 '22 23:11

ChrisDelClea