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

[WIP] Load or download the model. #55

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ dmypy.json
data/*
embeddings/*
results/*
models/*
15 changes: 10 additions & 5 deletions backend/my_executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from transformers import BertModel, BertTokenizer
from jina import Executor, requests, Document, DocumentArray

from backend_config import top_k, embeddings_path
from backend_config import top_k, embeddings_path
from utils import partition
from helpers import log

Expand All @@ -19,12 +19,17 @@ def __init__(self, **kwargs):
log("Initialising ProtBertExecutor.")
super().__init__()

model_path = "../models/prot_bert"
if not os.path.exists(model_path):
log(f"Downloading model {model_path}.")
model_path = "Rostlab/prot_bert"
else:
log(f"Using local model: {model_path}")

log("Setting tokenizer.")
tokenizer = BertTokenizer.from_pretrained(
"Rostlab/prot_bert", do_lower_case=False
)
tokenizer = BertTokenizer.from_pretrained(model_path, do_lower_case=False)
log("Setting model.")
model = BertModel.from_pretrained("Rostlab/prot_bert")
model = BertModel.from_pretrained(model_path)

self.tokenizer = tokenizer
self.model = model
Expand Down