Getting start and end indices of entities with respect to the sentence within a spacy doc #10703
-
Hi!So I am trying to implement an entity linker for my custom trained NER. I am using the benepar parser to split the sentences in my document and get the indices of the sentences. Now I need the indices of the entities w.r.t the sentence. So I used the following line of code: current_span=d[index_start:index_end]
for entity in current_span.ents:
entity_start=entity.start_char-entity.sent.start_char
entity_end=entity.end_char-entity.sent.start_char
ent_info['ent_indices']=(entity_start, entity_end) where |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @shrinidhin , can you provide a more complete example so we can see what's going on? It's still difficult to pinpoint where the problem is from the sample code. Perhaps, one thing you can try is do |
Beta Was this translation helpful? Give feedback.
Hi @shrinidhin , can you provide a more complete example so we can see what's going on? It's still difficult to pinpoint where the problem is from the sample code. Perhaps, one thing you can try is do
span.as_doc()
for the sentence spans, then obtain the entities to get the offsets you want. That might give you the correct indices.