def readEntertainDB(filename):
    try:
        with open(filename, mode='rt', encoding='UTF8') as file:
            datareader = csv.reader(file)
            # row_count = sum(1 for row in datareader)
            # print('row count of file: ' + filename + ' is ' + str(row_count))
            row = next(datareader)  # yield the header row
            for row in datareader:
                imdb_id = ''
                type = ''
                title = ''
                genre = ''
                if (len(row) > 0):
                    imdb_id = row[0]
                if (len(row) > 1):
                    type = row[1]
                if (len(row) > 2):
                    title = row[2]
                if (len(row) > 3):
                    genre = row[3]

                if (not imdb_id in imdb_data):  # imdb id already exist
                    imdb_item = imdb.Imdb()
                    imdb_item.id = imdb_id
                    imdb_item.type = type
                    imdb_item.title = title
                    imdb_item.genre = genre
                    imdb_data[imdb_id] = imdb_item
    except Exception as e:
        print('exception while reading entertainment db : ' + str(e))
예제 #2
0
def train():

    paddle.init(use_gpu=False, trainer_count=1)

    data = paddle.layer.data(
        name='data', type=paddle.data_type.integer_value_sequence(102100))

    label = paddle.layer.data(name='label',
                              type=paddle.data_type.integer_value(2))

    output = model(data)

    loss = paddle.layer.classification_cost(input=output, label=label)

    parameters = paddle.parameters.create(loss)
    print(parameters.keys())

    optimizer = paddle.optimizer.Adam(learning_rate=0.001)

    trainer = paddle.trainer.SGD(parameters=parameters,
                                 update_equation=optimizer,
                                 cost=loss)
    path = 'data/imdb.pkl'
    dataset = imdb.Imdb(path)
    train_data_reader = dataset.create_reader('train')
    test_data_reader = dataset.create_reader('test')

    feeding = {'data': 0, 'label': 1}

    def event_handler(event):
        if isinstance(event, paddle.event.EndIteration):
            if event.batch_id % 5 == 0:
                class_error_rate = event.metrics[
                    'classification_error_evaluator']
                print("\npass %d, Batch: %d cost: %f error: %s" %
                      (event.pass_id, event.batch_id, event.cost,
                       class_error_rate))
            else:
                sys.stdout.write('.')
                sys.stdout.flush()
        if isinstance(event, paddle.event.EndPass):
            # save parameters
            with gzip.open('output/params_pass_%d.tar.gz' % event.pass_id,
                           'w') as f:
                parameters.to_tar(f)
            result = trainer.test(reader=paddle.batch(test_data_reader,
                                                      batch_size=32),
                                  feeding=feeding)
            class_error_rate = result.metrics['classification_error_evaluator']
            print("\nTest with Pass %d, cost: %s error: %f" %
                  (event.pass_id, result.cost, class_error_rate))

    trainer.train(reader=paddle.batch(train_data_reader, batch_size=32),
                  event_handler=event_handler,
                  num_passes=10,
                  feeding=feeding)
예제 #3
0
#  http://www.gnu.org/copyleft/gpl.html
#

import os
import random
import datetime
import re
import imdb
import game
import library

import xbmcvfs

from strings import *

IMDB = imdb.Imdb()


class Answer(object):
    def __init__(self, id, text, image=None, sortWeight=None, correct=False):
        self.correct = correct
        self.id = id
        self.text = text
        self.coverFile = image
        self.sortWeight = sortWeight

    def setCoverFile(self, coverFile):
        self.coverFile = coverFile

    def __repr__(self):
        return "<Answer(id=%s, text=%s, correct=%s)>" % (self.id, self.text, self.correct)