-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
28 changed files
with
1,126 additions
and
535 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -47,4 +47,4 @@ docs/_build/ | |
|
||
# Keras model files | ||
history.p | ||
keras_model.* | ||
keras_model* |
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
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
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,8 @@ | ||
from ckanext.knowledgehub.lib.rnn.worker import PredictiveSearchWorker | ||
from ckanext.knowledgehub.lib.rnn.model import PredictiveSearchModel | ||
|
||
|
||
__all__ = [ | ||
'PredictiveSearchWorker', | ||
'PredictiveSearchModel' | ||
] |
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,40 @@ | ||
import os | ||
import time | ||
|
||
from ckan.common import config | ||
|
||
|
||
class PredictiveSearchConfig(object): | ||
''' Hold the configuration for the machine learning model and worker ''' | ||
|
||
def __init__(self): | ||
self.corpus_length = int(config.get( | ||
u'ckanext.knowledgehub.rnn.min_length_corpus', 10000)) | ||
self.sequence_length = config.get( | ||
u'ckanext.knowledgehub.rnn.sequence_length', 10) | ||
self.step = int( | ||
config.get(u'ckanext.knowledgehub.rnn.sentence_step', 1)) | ||
self.epochs = int( | ||
config.get(u'ckanext.knowledgehub.rnn.max_epochs', 50)) | ||
self.weights_path = config.get( | ||
u'ckanext.knowledgehub.rnn.model_weights', | ||
'./keras_model_weights.h5' | ||
) | ||
self.network_path = config.get( | ||
u'ckanext.knowledgehub.rnn.model_network', | ||
'./keras_model_network.h5' | ||
) | ||
self.history_path = config.get( | ||
u'ckanext.knowledgehub.rnn.history', | ||
'./history.p' | ||
) | ||
self.temp_weigths_path = os.path.join( | ||
os.path.dirname(self.weights_path), | ||
'keras_model_%s.h5' % time.time() | ||
) | ||
self.number_predictions = int( | ||
config.get( | ||
u'ckanext.knowledgehub.rnn.number_predictions', | ||
3 | ||
) | ||
) |
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,57 @@ | ||
import ckan.plugins.toolkit as toolkit | ||
|
||
|
||
class DataManager: | ||
''' Manage the training data''' | ||
|
||
@staticmethod | ||
def create_corpus(corpus): | ||
''' Store the machine learning corpus | ||
:param corpus: the machine learning corpus | ||
:type corpus: string | ||
:returns: the stored corpus | ||
:rtype: dict | ||
''' | ||
return toolkit.get_action('corpus_create')( | ||
{'ignore_auth': True}, | ||
{'corpus': corpus} | ||
) | ||
|
||
@staticmethod | ||
def get_corpus(): | ||
''' Get the data in knowledgehub and create corpus | ||
:returns: the machine learning corpus | ||
:rtype: string | ||
''' | ||
kwh_data = toolkit.get_action( | ||
'kwh_data_list')({'ignore_auth': True}, {}) | ||
|
||
corpus = '' | ||
if kwh_data.get('total'): | ||
data = kwh_data.get('data', []) | ||
for entry in data: | ||
corpus += ' %s' % entry.get('title') | ||
if entry.get('description'): | ||
corpus += ' %s' % entry.get('description') | ||
|
||
return corpus | ||
|
||
@staticmethod | ||
def get_last_corpus(): | ||
''' Return the corpus usd in the last training of the model ''' | ||
|
||
return toolkit.get_action('get_last_rnn_corpus')( | ||
{'ignore_auth': True}, {}) | ||
|
||
@staticmethod | ||
def prepare_corpus(corpus): | ||
''' Find the unique chars in the corpus and index the characters ''' | ||
|
||
unique_chars = sorted(list(set(corpus))) | ||
char_indices = dict((c, i) for i, c in enumerate(unique_chars)) | ||
indices_char = dict((i, c) for i, c in enumerate(unique_chars)) | ||
|
||
return (unique_chars, char_indices, indices_char) |
Oops, something went wrong.