-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
76 lines (53 loc) · 1.92 KB
/
main.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
72
73
74
75
76
import argparse
import os
from pyseqlab.features_extraction import FOFeatureExtractor, HOFeatureExtractor
from pyseqlab.fo_crf import FirstOrderCRF, FirstOrderCRFModelRepresentation
from pyseqlab.ho_crf import HOCRFAD, HOCRFADModelRepresentation
from pyseqlab.hosemi_crf_ad import HOSemiCRFAD, HOSemiCRFADModelRepresentation
from kashgari.tasks.seq_labeling import BLSTMCRFModel
from crf import CRFModel
from embedding import EmbeddingModel
from utils import LENER_DATASET_DIR
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--model",
type=str,
required=True,
choices=("FirstOrderCRF", "HOCRFAD", "HOSemiCRFAD", "BLSTMCRF"),
)
parser.add_argument(
"--method", type=str, required=True, choices=("CRF", "EMBEDDING")
)
args = parser.parse_args()
output_path = os.path.join(os.path.dirname(__file__), "output")
model = None
if args.method == "CRF":
if args.model == "FirstOrderCRF":
model = CRFModel(
FirstOrderCRF,
FirstOrderCRFModelRepresentation,
FOFeatureExtractor,
output_path,
)
elif args.model == "HOCRFAD":
model = CRFModel(
HOCRFAD, HOCRFADModelRepresentation, HOFeatureExtractor, output_path
)
elif args.model == "HOSemiCRFAD":
model = CRFModel(
HOSemiCRFAD,
HOSemiCRFADModelRepresentation,
HOFeatureExtractor,
output_path,
)
else:
raise Exception(
"Model unknown for CRF. Please use FirstOrderCRF, HOCRFAD or HOSemiCRFAD"
)
elif args.method == "EMBEDDING":
if args.model == "BLSTMCRF":
model = EmbeddingModel(BLSTMCRFModel)
if model is not None:
model.train(epochs=60)
model.evaluate("test")