Spacy transformer model not able to extract relative dates like today,tomorrow.
I am trying to extract date entites like today, tomorrow, yesterday from query by simply loading the model. Below is the reference code: import spacy nlp = spacy.load("en_core_web_trf") query = "I will book an appointment tomorrow" doc = nlp(query)
Below are some of the queries I tried. Here I observed that "yesterday" gets extracted as date entity, but "today" and "tomorrow" are not getting extracted as date entity.
Example set 1: I went to office yesterday ----> yesterday extracted as date I have to go to office today ----> no entity extracted I will go to office tomorrow ----> no entity extracted
Example set 2: I booked an appointment yesterday ----> yesterday extracted as date I will book an appointment tomorrow ----> no entity extracted I have an appointment today ------> no entity extracted
Example set 3: I had visited park yesterday----> yesterday extracted as date I will visit the park tomorrow----> no entity extracted I have to visit the park today------> no entity extracted
Is it a expected behaviour of the model or am i missing something ?
Environment
- spaCy version: 3.2.4
- Platform: Windows-10-10.0.19041-SP0
- Python version: 3.7.9
- Pipelines: en_core_web_trf (3.2.0)
In my tests with the trf model (3.2.0 EN TRF, but with spaCy 3.3), yesterday/today/tomorrow all got detected as entities in simple sentences like "I saw him XXX". So I'm not sure if something is strange about your setup. Could you update to 3.3 and try again?
Besides that, dates are kind of different from other NER entities. In particular these three terms are not named entities in the traditional sense, and their detection or annotation is often a little irregular in NER models. Looking at our training data, occurrences of "today" are annotated as dates, but they're pretty uncommon - OntoNotes, the training corpus, is mostly newspaper-like text. First-person sentences like your examples are not common.
We'll check this some more, but if you need to detect these particular words, I would recommend you just use an EntityRuler to match and label them, on top of any NER you might be using. If you need sophisticated date handling, there are also a number of packages focused on that which will probably work better than the default DATE entity in our English pipelines.
Using the 3.3.0 TRF model I was able to get your results for the exact sentences you provided (or several of them anyway). In some cases it looks like adding a period at the end of the sentence changed the entity result, which is weird and might require another look (though see #3052).
Is this issue resolved @polm ? or else I can take it. I have gone though it to reproduce and yes it is reproducible, some bug is present
@Himanshuwagh There's probably not anything we want to do to address this specifically, and the problem here should be handled using methods I explained upthread. If there is something weird it's not in the model, it's in the data, which we can't make public for licensing reasons, so there's nothing for you to do.
This issue has been automatically closed because it was answered and there was no follow-up discussion.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.