Spaces:
Sleeping
Sleeping
Update classifier.py
Browse files- classifier.py +13 -7
classifier.py
CHANGED
@@ -1,16 +1,22 @@
|
|
1 |
import spaces
|
2 |
-
from transformers import pipeline
|
|
|
3 |
|
4 |
#@spaces.GPU(duration=60)
|
5 |
def classify(tweet, event_model, hftoken, threshold):
|
|
|
6 |
|
7 |
-
# event type prediction
|
8 |
-
event_predictor = pipeline(task="text-classification", model=event_model,
|
9 |
-
|
10 |
-
tokenizer_kwargs = {'padding': True, 'truncation': True, 'max_length': 512}
|
|
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
results["text"] = tweet
|
16 |
|
|
|
1 |
import spaces
|
2 |
+
from transformers import pipeline as tpipeline
|
3 |
+
from optimum.pipelines import pipeline as opipline
|
4 |
|
5 |
#@spaces.GPU(duration=60)
|
6 |
def classify(tweet, event_model, hftoken, threshold):
|
7 |
+
results = {"text": None, "event": None, "score": None}
|
8 |
|
9 |
+
# event type prediction with transformers pipeline
|
10 |
+
# event_predictor = pipeline(task="text-classification", model=event_model,
|
11 |
+
# batch_size=512, token=hftoken, device="cpu")
|
12 |
+
# tokenizer_kwargs = {'padding': True, 'truncation': True, 'max_length': 512}
|
13 |
+
# prediction = event_predictor(tweet, **tokenizer_kwargs)[0]
|
14 |
|
15 |
+
|
16 |
+
# with onnx pipeline
|
17 |
+
onnx_classifier = pipeline("text-classification", model=event_model, accelerator="ort")
|
18 |
+
prediction = onnx_classifier(text)[0]
|
19 |
+
|
20 |
|
21 |
results["text"] = tweet
|
22 |
|