Kalaoke commited on
Commit
72528aa
·
1 Parent(s): cc6c3a1

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +13 -24
handler.py CHANGED
@@ -1,4 +1,3 @@
1
- from dataclasses import dataclass
2
  import torch
3
  import numpy as np
4
  import transformers
@@ -208,29 +207,6 @@ class BiBert_MultiTaskPipeline(Pipeline):
208
  dict_scores = dict_scores[:top_k]
209
  return dict_scores
210
 
211
-
212
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
213
- checkpoint="HCKLab/BiBert-MultiTask-1"
214
-
215
- tokenizer = AutoTokenizer.from_pretrained(checkpoint)
216
-
217
- tasks = [
218
- Task(id=0, name='label_classification', type='seq_classification', num_labels=5),
219
- Task(id=1, name='binary_classification', type='seq_classification', num_labels=2)
220
- ]
221
-
222
- multitask_model = BertForSequenceClassification.from_pretrained(
223
- checkpoint,
224
- tasks_map=tasks
225
- ).to(device)
226
-
227
-
228
- PIPELINE_REGISTRY.register_pipeline(
229
- "bibert-multitask-classification",
230
- pipeline_class=BiBert_MultiTaskPipeline,
231
- pt_model=BertForSequenceClassification
232
- )
233
-
234
  class EndpointHandler():
235
  def __init__(self, path=""):
236
  # Preload all the elements you are going to need at inference.
@@ -239,6 +215,19 @@ class EndpointHandler():
239
  pipeline_class=BiBert_MultiTaskPipeline,
240
  pt_model=BertForSequenceClassification
241
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  self.classifier_s = pipeline("bibert-multitask-classification", model = multitask_model, task_id="0", tokenizer=tokenizer, device = device)
243
  self.classifier_p = pipeline("bibert-multitask-classification", model = multitask_model, task_id="1", tokenizer=tokenizer, device = device)
244
 
 
 
1
  import torch
2
  import numpy as np
3
  import transformers
 
207
  dict_scores = dict_scores[:top_k]
208
  return dict_scores
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  class EndpointHandler():
211
  def __init__(self, path=""):
212
  # Preload all the elements you are going to need at inference.
 
215
  pipeline_class=BiBert_MultiTaskPipeline,
216
  pt_model=BertForSequenceClassification
217
  )
218
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
219
+
220
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
221
+
222
+ tasks = [
223
+ Task(id=0, name='label_classification', type='seq_classification', num_labels=5),
224
+ Task(id=1, name='binary_classification', type='seq_classification', num_labels=2)
225
+ ]
226
+
227
+ multitask_model = BertForSequenceClassification.from_pretrained(
228
+ path,
229
+ tasks_map=tasks
230
+ ).to(device)
231
  self.classifier_s = pipeline("bibert-multitask-classification", model = multitask_model, task_id="0", tokenizer=tokenizer, device = device)
232
  self.classifier_p = pipeline("bibert-multitask-classification", model = multitask_model, task_id="1", tokenizer=tokenizer, device = device)
233