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