Text Classification
Transformers
PyTorch
TensorBoard
bert
Generated from Trainer
text-embeddings-inference
Instructions to use HCKLab/BiBert-MultiTask-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HCKLab/BiBert-MultiTask-1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="HCKLab/BiBert-MultiTask-1", device_map="auto")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("HCKLab/BiBert-MultiTask-1") model = AutoModelForSequenceClassification.from_pretrained("HCKLab/BiBert-MultiTask-1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update handler.py
Browse files- 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 |
|