def train(self):
        # Load features into Elasticsearch
        initDefaultStore()
        loadFeatures(ES_FEATURE_SET_NAME)
        # Parse a judgments
        label_file = self.find_label_file()
        print(self.find_label_file(),file=sys.stderr)
        movieJudgments = judgmentsByQid(
            judgmentsFromFile(filename=label_file))
        # Use proposed Elasticsearch queries (1.json.jinja ... N.json.jinja) to generate a training set
        # output as "sample_judgments_wfeatures.txt"
        logFeatures(self.__es, judgmentsByQid=movieJudgments)
        buildFeaturesJudgmentsFile(
            movieJudgments, filename='sample_judgments_wfeatures.txt')
        # Train each ranklib model type
        # for modelType in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
        modelType = int(ES_MODEL_TYPE)
        # 0, MART
        # 1, RankNet
        # 2, RankBoost
        # 3, AdaRank
        # 4, coord Ascent
        # 6, LambdaMART
        # 7, ListNET
        # 8, Random Forests
        # 9, Linear Regression
        print("*** Training %s " % modelType)
        self.trainModel(judgmentsWithFeaturesFile='sample_judgments_wfeatures.txt',
                        modelOutput='model.txt', whichModel=modelType)
        self.saveModel(scriptName=ES_MODEL_NAME,
                       featureSet='movie_features', modelFname='model.txt')

        with open('/opt/services/flaskapp/src/training_log.txt') as flog:
            log_lines = flog.readlines()

        print(label_file)
        return '{}{}\n{}'.format('Model trained and deployed to Elasticsearch: \n', ''.join(log_lines[-5:-3]), 'Now test the model')
Ejemplo n.º 2
0
    import configparser
    from elasticsearch5 import Elasticsearch
    from sys import argv
    from judgments import judgmentsFromFile, judgmentsByQid, duplicateJudgmentsByWeight

    config = configparser.ConfigParser()
    config.read('settings.cfg')
    esUrl = config['DEFAULT']['ESHost']
    if len(argv) > 1:
        esUrl = argv[1]

    es = Elasticsearch(esUrl, timeout=1000)

    # Load features into Elasticsearch
    initDefaultStore(esUrl)
    loadFeatures(esUrl)
    # Parse a judgments
    movieJudgments = judgmentsByQid(
        judgmentsFromFile(filename=HUMAN_JUDGMENTS))
    movieJudgments = duplicateJudgmentsByWeight(movieJudgments)
    trainJudgments, testJudgments = partitionJudgments(movieJudgments,
                                                       testProportion=0.0)

    # Use proposed Elasticsearch queries (1.json.jinja ... N.json.jinja) to generate a training set
    # output as "sample_judgments_wfeatures.txt"
    logFeatures(es, judgmentsByQid=movieJudgments)

    buildFeaturesJudgmentsFile(trainJudgments, filename=TRAIN_JUDGMENTS)
    buildFeaturesJudgmentsFile(testJudgments, filename=TEST_JUDGMENTS)
Ejemplo n.º 3
0
        resp = requests.post(fullPath,
                             data=json.dumps(modelPayload),
                             headers=head,
                             auth=ES_AUTH)
        print(resp.status_code)
        if (resp.status_code >= 300):
            print(resp.text)


if __name__ == "__main__":
    import configparser
    from judgments import judgmentsFromFile, judgmentsByQid

    es = Elasticsearch(timeout=1000)
    # Load features into Elasticsearch
    initDefaultStore()
    loadFeatures()
    # Parse a judgments
    movieJudgments = judgmentsByQid(
        judgmentsFromFile(filename='search_sample_judgments.txt'))
    # Use proposed Elasticsearch queries (1.json.jinja ... N.json.jinja) to generate a training set
    # output as "sample_judgments_wfeatures.txt"
    logFeatures(es, judgmentsByQid=movieJudgments)
    buildFeaturesJudgmentsFile(
        movieJudgments, filename='search_sample_judgments_wfeatures.txt')
    # Train each ranklib model type
    for modelType in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
        # 0, MART
        # 1, RankNet
        # 2, RankBoost
        # 3, AdaRank
        resp = requests.post(fullPath, data=json.dumps(modelPayload), headers=head, auth=ES_AUTH)
        print(resp.status_code)
        if (resp.status_code >= 300):
            print(resp.text)





if __name__ == "__main__":
    import configparser
    from judgments import judgmentsFromFile, judgmentsByQid

    es = Elasticsearch(timeout=1000)
    # Load features into Elasticsearch
    initDefaultStore()
    loadFeatures()
    # Parse a judgments
    movieJudgments = judgmentsByQid(judgmentsFromFile(filename='sample_judgments.txt'))
    # Use proposed Elasticsearch queries (1.json.jinja ... N.json.jinja) to generate a training set
    # output as "sample_judgments_wfeatures.txt"
    logFeatures(es, judgmentsByQid=movieJudgments)
    buildFeaturesJudgmentsFile(movieJudgments, filename='sample_judgments_wfeatures.txt')
    # Train each ranklib model type
    for modelType in [0,1,2,3,4,5,6,7,8,9]:
        # 0, MART
        # 1, RankNet
        # 2, RankBoost
        # 3, AdaRank
        # 4, coord Ascent
        # 6, LambdaMART