コード例 #1
0
    def create_recommendation_microservice(self,
                                           recommender_folder,
                                           memcache_servers=None,
                                           memcache_pool_size=2):
        """
        create recommedation Flask microservice app

        Parameters
        ----------

        recommender_folder : str
           location of recommender model files
        memcache_servers : comma separated string, optional
           memcache server locations, e.g., 127.0.0.1:11211 
        memcache_pool_size : int, optional
           size of memcache pool
        """
        app = Flask(__name__)

        if not memcache_servers is None:
            mc = pylibmc.Client(memcache_servers)
            _mc_pool = pylibmc.ClientPool(mc, memcache_pool_size)
            app.config["seldon_memcache"] = _mc_pool

        rw = seldon.Recommender_wrapper()
        recommender = rw.load_recommender(recommender_folder)
        app.config["seldon_recommender"] = recommender

        app.register_blueprint(recommend_blueprint)

        # other setup tasks
        return app
コード例 #2
0
import sys, getopt, argparse
from seldon.text.ngram_recommend import NgramModel

if __name__ == '__main__':
    parser = argparse.ArgumentParser(prog='upload model')
    parser.add_argument('--arpa', help='arpa file', required=True)
    parser.add_argument('--dst', help='dst folder', required=True)
    parser.add_argument(
        '--aws_key',
        help='aws key - needed if input or output is on AWS and no IAM')
    parser.add_argument(
        '--aws_secret',
        help='aws secret - needed if input or output on AWS  and no IAM')

    args = parser.parse_args()
    opts = vars(args)

    recommender = NgramModel()
    recommender.fit(args.arpa)

    import seldon
    if "aws_key" in opts:
        rw = seldon.Recommender_wrapper(aws_key=args.aws_key,
                                        aws_secret=args.aws_secret)
    else:
        rw = seldon.Recommender_wrapper()
    rw.save_recommender(recommender, args.dst)
コード例 #3
0
ファイル: build_model.py プロジェクト: zofuthan/seldon-server
docs = []
for filename in os.listdir("reuters-21578-json/data/full"):
    f = open("reuters-21578-json/data/full/" + filename)
    js = json.load(f)
    for j in js:
        if 'topics' in j and 'body' in j:
            d = {}
            d["id"] = j['id']
            d["text"] = j['body'].replace("\n", "")
            d["title"] = j['title']
            d["tags"] = ",".join(j['topics'])
            docs.append(d)

print "loaded ", len(docs), " documents"

from seldon.text import DocumentSimilarity, DefaultJsonCorpus
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)

corpus = DefaultJsonCorpus(docs)
ds = DocumentSimilarity(model_type='gensim_lsi')
ds.fit(corpus)
print "built model"

import seldon
rw = seldon.Recommender_wrapper()
rw.save_recommender(ds, "reuters_recommender")
print "saved recommender"