-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add models to demo docker image (#1978)
* Add utility to cache models and nltk data & modify Dockerfiles to use it * Fix punkt data not being cached
- Loading branch information
Showing
3 changed files
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import logging | ||
|
||
def cache_models(): | ||
""" | ||
Small function that caches models and other data. | ||
Used only in the Dockerfile to include these caches in the images. | ||
""" | ||
# download punkt tokenizer | ||
logging.info("Caching punkt data") | ||
import nltk | ||
nltk.download('punkt', download_dir='/root/nltk_data') | ||
|
||
# Cache roberta-base-squad2 model | ||
logging.info("Caching deepset/roberta-base-squad2") | ||
import transformers | ||
model_to_cache='deepset/roberta-base-squad2' | ||
transformers.AutoTokenizer.from_pretrained(model_to_cache) | ||
transformers.AutoModel.from_pretrained(model_to_cache) |