forked from alfredfrancis/ai-chatbot-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
iky
committed
Jun 30, 2016
1 parent
4955a97
commit 046f97e
Showing
125 changed files
with
439 additions
and
338 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import ast | ||
|
||
import pycrfsuite | ||
|
||
from intentClassifier import Intent_classifier | ||
#from bson.json_util import loads, dumps | ||
#from bson.objectid import ObjectId | ||
|
||
from ikyWareHouse.mongo import _retrieve | ||
from featuresExtractor import extractFeatures | ||
|
||
def sentToFeatures(sent): | ||
return [extractFeatures(sent, i) for i in range(len(sent))] | ||
|
||
|
||
def sentToLabels(sent): | ||
return [label for token, postag, label in sent] | ||
|
||
|
||
def sentToTokens(sent): | ||
return [token for token, postag, label in sent] | ||
|
||
def buildStoryModel(storyId): | ||
|
||
cursor = _retrieve("labled_queries", {"story_id": storyId}) | ||
|
||
train_sents = [] | ||
for item in cursor: | ||
train_sents.append(ast.literal_eval(item["item"].encode('ascii', 'ignore'))) | ||
|
||
X_train = [_sent2features(s) for s in train_sents] | ||
y_train = [_sent2labels(s) for s in train_sents] | ||
|
||
trainer = pycrfsuite.Trainer(verbose=False) | ||
for xseq, yseq in zip(X_train, y_train): | ||
trainer.append(xseq, yseq) | ||
|
||
trainer.set_params({ | ||
'c1': 1.0, # coefficient for L1 penalty | ||
'c2': 1e-3, # coefficient for L2 penalty | ||
'max_iterations': 50, # stop earlier | ||
|
||
# include transitions that are possible, but not observed | ||
'feature.possible_transitions': True | ||
}) | ||
trainer.train('models/%s.model' % story_id) | ||
|
||
Intent_classifier().train() | ||
return "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# NER support functions for Feature extration | ||
def extractFeatures(sent, i): | ||
word = sent[i][0] | ||
postag = sent[i][1] | ||
features = [ | ||
'bias', | ||
'word.lower=' + word.lower(), | ||
'word[-3:]=' + word[-3:], | ||
'word[-2:]=' + word[-2:], | ||
'word.isupper=%s' % word.isupper(), | ||
'word.istitle=%s' % word.istitle(), | ||
'word.isdigit=%s' % word.isdigit(), | ||
'postag=' + postag, | ||
'postag[:2]=' + postag[:2], | ||
] | ||
if i > 0: | ||
word1 = sent[i - 1][0] | ||
postag1 = sent[i - 1][1] | ||
features.extend([ | ||
'-1:word.lower=' + word1.lower(), | ||
'-1:word.istitle=%s' % word1.istitle(), | ||
'-1:word.isupper=%s' % word1.isupper(), | ||
'-1:postag=' + postag1, | ||
'-1:postag[:2]=' + postag1[:2], | ||
]) | ||
else: | ||
features.append('BOS') | ||
|
||
if i < len(sent) - 1: | ||
word1 = sent[i + 1][0] | ||
postag1 = sent[i + 1][1] | ||
features.extend([ | ||
'+1:word.lower=' + word1.lower(), | ||
'+1:word.istitle=%s' % word1.istitle(), | ||
'+1:word.isupper=%s' % word1.isupper(), | ||
'+1:postag=' + postag1, | ||
'+1:postag[:2]=' + postag1[:2], | ||
]) | ||
else: | ||
features.append('EOS') | ||
|
||
return features |
File renamed without changes.
42 changes: 21 additions & 21 deletions
42
iky_server/intent_classifier.py → ikyCore/intentClassifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import actions | ||
import re | ||
|
||
from ikyActions import actions | ||
|
||
|
||
# ORACLE database connection | ||
# import cx_Oracle | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
import ikyWebServer.home | ||
import ikyWebServer.ui | ||
import ikyWebServer.api |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.