satya77 / Transformer_Temporal_Tagger

Code and data form the paper BERT Got a Date: Introducing Transformers to Temporal Tagging
MIT License
65 stars 5 forks source link

How to tag dates using the model temporal_tagger_DATEBERT_tokenclassifier #12

Open pratikchhapolika opened 2 years ago

pratikchhapolika commented 2 years ago

I am using this code to load the model and the tokenizer:

tokenizer = AutoTokenizer.from_pretrained("satyaalmasian/temporal_tagger_DATEBERT_tokenclassifier", use_fast=False)
model = tr.BertForTokenClassification.from_pretrained("satyaalmasian/temporal_tagger_DATEBERT_tokenclassifier")

I have a list of text:

examples=['Texas DRIVER LICENSE Class AM 04/10/2014', 'N. Joy Driving DOB 09/21/1990']

How do I now pass this into the model to get proper tagging of dates? Sorry little confused.

@dennlinger

pratikchhapolika commented 2 years ago

Hi @dennlinger , any help please?

dennlinger commented 2 years ago

Hi @pratikchhapolika, sorry for the late answer! For the DateBERT classifier, you need to take some additional steps to obtain predictions, namely, embedding the date itself.

An example is given in the Huggingface model card, or alternatively in our script for tagging inference.

Personally, we found that the fine-tuned "base" BERT model already achieves very comparable performance (i.e., the temporal_tagger_BERT_tokenclassifier model), which you can simply load with a TokenClassificationPipeline like this:

from transformers import pipeline

pipe = pipeline("token-classification", model="satyaalmasian/temporal_tagger_BERT_tokenclassifier")
# And then simply pass strings as inputs:
pipe("Tomorrow will be a beautiful day")