-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
34 lines (28 loc) · 1.02 KB
/
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
#!/usr/bin/env python3
#
# Reuters newswire topic classification prediction example
#
import json
from lib.featurizer import Featurizer
from lib.categorizer import Categorizer
from lib.classifier import Classifier
testdata = [
{"text": "local chamber of commerce takes action on legislation"},
{"text": "consumption of food is estimated to have increased twofold in the past year"},
{"text": "banking company offers settlement in long running financial case"},
{"text": "negotiations on foreign affairs between china and australia enter into a new phase"}
]
f = Featurizer.load('model/reuters')
x = f.transform(testdata)
x_inv = f.transform_inv(x)
del f
m = Classifier.load('model/reuters')
y = m.predict(x)
del m
c = Categorizer.load('model/reuters_y')
y = c.transform_inv(y)
for i, line in enumerate(testdata):
print("Input:", json.dumps(line))
print("Features:", json.dumps(x_inv[i]))
print("Prediction:", y[i])
# too bad we don't know the category name - https://stackoverflow.com/questions/45138290