-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_intent.py
More file actions
30 lines (21 loc) · 789 Bytes
/
get_intent.py
File metadata and controls
30 lines (21 loc) · 789 Bytes
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
import big_config
from sklearn.linear_model import LogisticRegression
from sklearn.feature_extraction.text import CountVectorizer
BOT_CONFIG = big_config.BOT_CONFIG
dataset = []
for intent, intent_data in BOT_CONFIG['intents'].items():
for example in intent_data['examples']:
dataset.append([example, intent])
X_text = [x for x, y in dataset]
y = [y for x, y in dataset]
vectorizer = CountVectorizer(analyzer='char', ngram_range=(1, 3))
X = vectorizer.fit_transform(X_text)
clf = LogisticRegression()
clf.fit(X, y)
def get_intent(text):
probas = clf.predict_proba(vectorizer.transform([text]))[0]
proba = max(probas)
if proba > 0.3:
index = list(probas).index(proba)
return clf.classes_[index]
print(get_intent('что послушать'))