naiveHobo / InvoiceNet

Deep neural network to extract intelligent information from invoice documents.
MIT License
2.46k stars 389 forks source link

n-grams for extraction #51

Open juvebogdan opened 3 years ago

juvebogdan commented 3 years ago

Hello,

I have this issue where if field of interest is longer. For example has 5, 6 or even more words it only extracts first part. Can you advise what can I do to fix this? Is n-gram setting here something I can try?

vitconhocboi2 commented 3 years ago

Can someone able to resolve this issue please.

juvebogdan commented 3 years ago

Seems like you can only use it for shorter n-grams. It was like that for me. When I increased n-grams training took forever, It's not really usable for bigger n-grams. That's not the way to approach this

vitconhocboi2 commented 3 years ago

how can i recognite field value on multiple line? can you suggest any solution?

naiveHobo commented 3 years ago

This is a limitation of the architecture I'm currently using. Increasing the n-gram size (which is currently 4) increases the model size exponentially and unless you have massive GPU resources available, that's not a viable option. The n-gram size decides the maximum number of words that you can extract for a particular field which is currently limited to 4. N-grams are currently extracted line-by-line which means multiple line entities cannot be extracted right now.

I'd suggest going through the paper for some insight into these limitations. I'm working on a new architecture to resolve some of these problems.

boehminho commented 3 years ago

Out of curiosity...what would I have to change to increase the number of extracted n-grams? I have quite a lot of GPU resources available and would like to give it a try.

naiveHobo commented 3 years ago

There are two places you'd have to change the n-gram length:

boehminho commented 3 years ago

Thanks for your quick response! I tried to set it to 6, but it gave me the following error message:

" ValueError: Tensor's shape (3, 3, 128, 4) is not compatible with supplied shape (3, 3, 128, 6) "

Do you have any idea how to modify the tensor shape? This might be due to the model I guess...

naiveHobo commented 3 years ago

Firstly, can you pull in the latest commit? It fixes a couple of bugs I missed when n-gram length is different. Secondly, you need to prepare your data again after you make the changes I mentioned above and then train your model. I tried it with different n-gram lengths, everything seems to work. Let me know if you face any more issues.

boehminho commented 3 years ago

I pulled the latest commit and also prepared the data again. Now it shows me a slightly different error message:

" ValueError: Tensor's shape (3, 3, 110, 32) is not compatible with supplied shape (3, 3, 118, 32) "

It seems to have a problem with the tensors width or am I wrong? Appreciate your support!

boehminho commented 3 years ago

I guess I found the source of the error message. I will most likely occur if you want to restart at a checkpoint with the previous size that obviously can't be matched. Seems to make sense. Appreciate your support tho!

FPEPOSHI commented 2 years ago

@naiveHobo I have set different n_grams (e.g 8) but when I run prediction is extracting still maximum 4 n_grams(words). Do we need to change anything else somewhere or it's part of paper limitations?