forked from SuiMingYang/ProductTypeClassify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
29 lines (23 loc) · 799 Bytes
/
api.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
from sklearn.externals import joblib
import pickle
from sklearn.feature_extraction.text import CountVectorizer
import jieba
from collections import Counter
"""
调用代码
"""
if __name__ == "__main__":
def put_category(l):
l=loaded_model.predict(vec.transform(jieba.lcut(l)))
l=sorted(Counter(l).items(),key = lambda kv:(kv[1]),reverse=True)
for i in l:
if i[0] !='nan':
text = i[0]
print(text)
return text
return ""
modelname = './model/extract_secondtype.sav'
loaded_model = joblib.load(modelname)
featurename = './model/feature.pkl'
vec = CountVectorizer(decode_error="replace", vocabulary=pickle.load(open(featurename, "rb")))
put_category('大码宽松长袖衬衣')