Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a LRU cache for word embeddings for a decrease of 20% of inference time #1084

Merged
merged 9 commits into from Sep 11, 2019

Conversation

pommedeterresautee
Copy link
Contributor

@pommedeterresautee pommedeterresautee commented Sep 10, 2019

Set an embedding LRU cache of Tensor of word embeddings.
This approach avoid to convert most used Gensim embeddings to Pytorch Tensor and even more important to avoid to transfer from computer RAM to GPU Ram (this is a slow operation).
Because of zipf law, the effect of such caching approach are magnified.
LRU cache is set to 10000 because it s very small and still provide most of the performance boost compared to loading all embeddings in GPU Ram. A 1000 embedding LRU cache is slightly less performant on my own dataset.

A second little optimization is to replace a call of unsqueeze on each token followed by a cat by a single call of stack.

Time to process 100 French documents decreased from 33s to 26s with this PR.
For what it worths, Spacy takes exactly the same time (26s) on my dataset with much lower accuracy on some tricky entities (and same accuracy on easiest to recognize entities).
Another change is on Ner HTML viewer with the introduction of a HTML title parameter.

@alanakbik
Copy link
Collaborator

This is really great, including this PR the combined improvements of your recent PRs take inference time from ~95 seconds on CoNLL-03 down to ~33 seconds - Thanks for all your great work!

@alanakbik
Copy link
Collaborator

👍

1 similar comment
@kashif
Copy link
Contributor

kashif commented Sep 11, 2019

👍

@alanakbik alanakbik merged commit 67aeb04 into flairNLP:master Sep 11, 2019
@pommedeterresautee pommedeterresautee deleted the cache_results branch September 11, 2019 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants