Uan Sholanbayev
commited on
Commit
·
1d62fed
1
Parent(s):
9edfae2
added model
Browse files- handler.py +3 -4
handler.py
CHANGED
@@ -3,7 +3,6 @@ import numpy as np
|
|
3 |
from transformers import BertTokenizer, BertModel
|
4 |
import torch
|
5 |
import pickle
|
6 |
-
import os
|
7 |
|
8 |
|
9 |
|
@@ -16,10 +15,10 @@ def unpickle_obj(filepath):
|
|
16 |
|
17 |
class EndpointHandler():
|
18 |
def __init__(self, path=""):
|
19 |
-
self.model = unpickle_obj(f"{
|
20 |
-
self.tokenizer = BertTokenizer.from_pretrained(
|
21 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
22 |
-
self.bert = BertModel.from_pretrained(
|
23 |
|
24 |
def get_embeddings(self, texts: List[str]):
|
25 |
inputs = self.tokenizer(texts, return_tensors='pt', truncation=True,
|
|
|
3 |
from transformers import BertTokenizer, BertModel
|
4 |
import torch
|
5 |
import pickle
|
|
|
6 |
|
7 |
|
8 |
|
|
|
15 |
|
16 |
class EndpointHandler():
|
17 |
def __init__(self, path=""):
|
18 |
+
self.model = unpickle_obj(f"{path}/bert_lr.pkl")
|
19 |
+
self.tokenizer = BertTokenizer.from_pretrained(path, local_files_only=True)
|
20 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
21 |
+
self.bert = BertModel.from_pretrained(path).to(self.device)
|
22 |
|
23 |
def get_embeddings(self, texts: List[str]):
|
24 |
inputs = self.tokenizer(texts, return_tensors='pt', truncation=True,
|