Nealcly / templateNER

Source code for template-based NER
208 stars 39 forks source link

Custom Label Problem #14

Open savasy opened 2 years ago

savasy commented 2 years ago

When I train the model with custom labels, the training code works well. However, Adapting Inference.py code to my custom trained model does not work.

I change the Inference.ipynb code to adapt my 11 labels as follows:

    LABELS=["Adjective","API","Core","GUI","Hardware","Language","Platform","Standard","User","Verb","O"]
    template_list=[" is a %s entity"%(e) for e in LABELS]
    entity_dict={i:e for i, e in enumerate(LABELS)}

Here is loading checkpoint

tokenizer = BartTokenizer.from_pretrained('facebook/bart-large')
model = BartForConditionalGeneration.from_pretrained('./outputs/best_model')

Here is the inference and the error

prediction("As a user I should be able to use the attribute type User in my queries.")

RuntimeError
----> 2 prediction("As a user I should be able to use the attribute type User in my queries.") /usr/local/lib/python3.7/dist-packages/transformers/models/bart/modeling_bart.py in _shape(self, tensor, seq_len, bsz) 157 def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int): --> 158 return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous() RuntimeError: shape '[88, -1, 16, 64]' is invalid for input of size 778240

HuangZhenyang commented 2 years ago

Hi, I met the same problem. And I solved it by replacing the number 5 with len(template_list) in inference.py.

savasy commented 2 years ago

Hi @HuangZhenyang You changed every 5s? , what about 4s, they need to be X-1 ?

HuangZhenyang commented 2 years ago

@savasy I changed every 5 to len(template_list) in function def template_entity(). I don't know if this change is right... Maybe we should wait for the author to reply.

savasy commented 2 years ago

@HuangZhenyang Aha awesome, it worked, thanks. Hi @Nealcly, Maybe you can change it accordingly or we can make a pull request