-
Notifications
You must be signed in to change notification settings - Fork 5
/
simple_test.py
71 lines (61 loc) · 1.75 KB
/
simple_test.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
64
65
66
67
68
69
70
71
from torch._C import TracingState
from transformers import pipeline, AutoTokenizer
import torch
from utils.util import read_json
import argparse
import pprint
import time
def main(config):
device = 0 if torch.cuda.is_available() else -1
print(transformers.__version__)
model_path = config.model_path
config_path = config.config_path
model = torch.load(model_path)
model_config = read_json(config_path)
tokenizer = AutoTokenizer.from_pretrained(config.tokenizer)
pipe = pipeline(
task="text-classification",
config=model_config,
model=model.model,
tokenizer=tokenizer,
device=device
)
for i in range(config.num):
text = input(f"문장을 입력하세요 {i+1} / {config.num}: ")
start_time = time.time()
result = pipe(text)
end_time = time.time()
print(f'inference time: {end_time - start_time}')
pprint.pprint(result)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-m",
"--model_path",
default=None,
type=str,
help="saved model file (.pt) path (default: None)",
)
parser.add_argument(
"-c",
"--config_path",
default=None,
type=str,
help="saved model config file path (default: None)",
)
parser.add_argument(
"-t",
"--tokenizer",
default="beomi/KcELECTRA-base",
type=str,
help="pretrained tokenizer name (default: beomi/KcELECTRA-base)",
)
parser.add_argument(
"-n",
"--num",
default=3,
type=int,
help="How many times will you check the sentence? (default: 1)",
)
args = parser.parse_args()
main(args)