-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpacker.py
63 lines (54 loc) · 1.83 KB
/
packer.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
from transformers import (
AutoModelWithLMHead,
AutoTokenizer,
AutoModelForTokenClassification,
AutoModelForSequenceClassification
)
from service import SummarizerService, NERService, CategorizationService
def pack_summarizer():
svc = SummarizerService()
model_name = "sshleifer/distilbart-cnn-12-6"
model = AutoModelWithLMHead.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
artifact = {
"model": model,
"tokenizer": tokenizer
}
svc.pack("model", artifact)
print(f"Summarizer service packed: {svc.save()}")
def pack_ner():
svc = NERService()
model_name = "dbmdz/bert-large-cased-finetuned-conll03-english"
tokenizer_name = "bert-base-cased"
model = AutoModelForTokenClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
artifact = {
"model": model,
"tokenizer": tokenizer
}
svc.pack("model", artifact)
print(f"NER service packed: {svc.save()}")
def pack_categorization():
svc = CategorizationService()
model_name = "facebook/bart-large-mnli"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
artifact = {
"model": model,
"tokenizer": tokenizer
}
svc.pack("model", artifact)
print(f"Categorization service packed: {svc.save()}")
if __name__ == "__main__":
args = sys.argv[1:]
print(f"Parsed services to pack: {', '.join(args)}")
if "summarizer" in args:
print("Packing Summarizer service...")
pack_summarizer()
if "ner" in args:
print("Packing NER service...")
pack_ner()
if "categorization" in args:
print("Packing Categorization service...")
pack_categorization()