-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
executable file
·63 lines (53 loc) · 2.11 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
#!/usr/bin/env python3
import argparse
def train(args):
classifier = Classifier(binary=not args.multiclass)
classifier.train(args.filepath)
def predict(args):
classifier = Classifier(
granularity=args.granularity, binary=not args.multiclass
)
print('{}: {}'.format(args.sentence, classifier.predict(args.sentence)))
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Command line access to the Linguistic Uncertainty '
'Classifier Interface (LUCI).'
)
subparsers = parser.add_subparsers(title='Commands', dest='command')
subparsers.required = True
parser_train = subparsers.add_parser(
'train', help='Train uncertainty classifier.'
)
parser_train.add_argument(
'-m', '--multiclass', action='store_true',
help='When set, the response variable is considered multi-class. '
'Consequently, a multi-class classifier is trained.'
)
parser_train.add_argument(
'filepath',
help='The absolute path to a file containining the training data.'
)
parser_train.set_defaults(handler=train)
parser_predict = subparsers.add_parser(
'predict', help='Predict uncertainty of a sentence.'
)
parser_predict.add_argument(
'-g', '--granularity', choices=['word', 'sentence'],
default='word',
help='The granularity at which the prediction must be made. '
'Default is word.'
)
parser_predict.add_argument(
'-m', '--multiclass', action='store_true',
help='When set, the response variable is considered multi-class. '
'Consequently, a multi-class classifier is used for '
'prediction.'
)
parser_predict.add_argument(
'sentence',
help='A sentence for which the uncertainty is to be predicted.'
)
parser_predict.set_defaults(handler=predict)
args = parser.parse_args()
from uncertainty.classifier import Classifier
args.handler(args)