Update app.py
Browse files
app.py
CHANGED
@@ -50,12 +50,12 @@ def get_st(tgt):
|
|
50 |
st.error("Failed to obtain service ticket from UMLS API.")
|
51 |
st.stop()
|
52 |
|
53 |
-
# Text embedding
|
54 |
@st.cache_resource
|
55 |
-
def embed_text(text,
|
56 |
-
inputs =
|
57 |
with torch.no_grad():
|
58 |
-
outputs =
|
59 |
emb = outputs.last_hidden_state[:, 0, :].squeeze().cpu().numpy()
|
60 |
return emb / np.linalg.norm(emb)
|
61 |
|
|
|
50 |
st.error("Failed to obtain service ticket from UMLS API.")
|
51 |
st.stop()
|
52 |
|
53 |
+
# Text embedding (tokenizer and model are unhashable, prefix with underscore)
|
54 |
@st.cache_resource
|
55 |
+
def embed_text(text, _tokenizer, _model):
|
56 |
+
inputs = _tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
57 |
with torch.no_grad():
|
58 |
+
outputs = _model(**inputs)
|
59 |
emb = outputs.last_hidden_state[:, 0, :].squeeze().cpu().numpy()
|
60 |
return emb / np.linalg.norm(emb)
|
61 |
|