-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassifier.py
More file actions
50 lines (42 loc) · 1.11 KB
/
classifier.py
File metadata and controls
50 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import time
from transformers import AutoTokenizer, AutoModelForTokenClassification, logging
from transformers import pipeline
import records
logging.set_verbosity_error()
print("Setting up Classifier...")
classifier = pipeline(
"zero-shot-classification",
model="facebook/bart-large-mnli",
device="cuda:0",
use_fast=True,
)
# classifier = pipeline(
# "zero-shot-classification",
# model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli",
# device="cuda:0",
# use_fast=True,
# )
def clas():
candidate_labels = [
"global health",
"management",
"equity equality",
"ESG",
"governance",
"climate change",
]
i = 0
start = time.time()
for out in classifier(records.iterator, candidate_labels):
print(out["scores"])
i = i + 1
if i % 100 == 0:
now = time.time()
elapsed = now - start
average = elapsed / 100
print("Average time per record: {:.4f} seconds".format(average))
start = now
# Example usage
if __name__ == "__main__":
clas()
# flair_detect()