-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathnlp.py
executable file
·42 lines (27 loc) · 899 Bytes
/
nlp.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
#!/usr/bin/env python3
# coding: utf-8
import sys
import pprint
import readline
from jetson_voice import NLP, ConfigArgParser
parser = ConfigArgParser()
parser.add_argument('--model', default='distilbert_sentiment', type=str)
args = parser.parse_args()
print(args)
# load the model
model = NLP(args.model)
# QA models should run the nlp_qa.py example
type = model.config.type
if type == 'qa':
raise ValueError("please run Question/Answer models with the nlp_qa.py sample")
while True:
print(f'\nEnter {type} query, or Q to quit:')
query = input('> ')
if query.upper() == 'Q':
sys.exit()
print('')
results = model(query)
if type == 'intent_slot' or type == 'text_classification':
pprint.pprint(results)
elif type == 'token_classification':
print(f'{model.tag_string(query, results, scores=True)}')