Esempio n. 1
0
    def put(self,name):
        # parser = reqparse.RequestParser()
        # parser.add_argument('marks',
        #                     required=True,
        #                     help='Please enter the marks scored in all types of education'
        #                     )
        # data = parser.parse_args()
        # row = StudentModel.get_by_name(name)
        # ob = StudentModel(name,data['marks'])
        # if row:
        #     ob.update()
        #     return {'Message':'The student {} is got updated in the table'.format(name)}, 202
        # ob.insert()
        # return {'Message': "The student record is inserted successfully"}, 201

        parser = reqparse.RequestParser()
        parser.add_argument('marks',
                            required=True,
                            help='Please enter the marks scored in all types of education'
                            )
        student = StudentModel.get_by_name(name)
        data = parser.parse_args()
        if student:
            student.marks = data['marks']
            return {'Message': "The student record is updated successfully"},
        else:
            student = StudentModel(name,data['marks'])
        student.save_to_db()
        return {'Message': "The student record is inserted successfully"},
Esempio n. 2
0
    def post(self,name):

        if StudentModel.get_by_name(name):
            return {'message' : "student {} already present".format(name)}
        data_jason = request.get_json()
        ob = StudentModel(name, data_jason['marks'])
        ob.save_to_db()
        return {'Message': "The student record is inserted successfully"}, 201
Esempio n. 3
0
 def post(self,name):
     data_jason = request.get_json()
     row = StudentModel.get_by_name(name)
     if row:
         row.marks = data_jason['marks']
         row.save_to_db()
         return {'Message': 'The marks of the student {} has been updated in the table'.format(name)},201
     return {'Message':'not found'}, 404
Esempio n. 4
0
 def delete(self,name):
     student = StudentModel.get_by_name(name)
     if student:
         # conn = sqlite3.connect('user.db')
         # cursor = conn.cursor()
         # cursor.execute("delete from student where name = ?", (name,))
         # conn.commit()
         # conn.close()
         student.delete_from_db()
         return {'Message':'The student {} is delete from the table'.format(name)}
     return {'Message': 'The student {} is not present in the table'.format(name)}, 201
Esempio n. 5
0
"""

import json
from config import Configure
from utils.vocab import Vocab
from data.loader import DataLoader
from model.student import StudentModel
from utils import torch_utils, scorer, constant, helper

args = Configure.eval()

# load opt
model_file = 'saved_models/' + args.model_id + '/' + args.model
print("Loading model from {}".format(model_file))
opt = torch_utils.load_config(model_file)
student_model = StudentModel(opt)
student_model.load(model_file)

# load vocab
vocab_file = 'saved_models/' + args.model_id + '/vocab.pkl'
vocab = Vocab(vocab_file, load=True)
assert opt[
    'vocab_size'] == vocab.size, "Vocab size must match that in the saved model."

# load data
data_file = opt['data_dir'] + '/{}.json'.format(args.dataset)
print("Loading data from {} with batch size {}...".format(
    data_file, opt['batch_size']))
batch = DataLoader(data_file, opt['batch_size'], opt, vocab, evaluation=True)

helper.print_config(opt)
Esempio n. 6
0
    teacher_opt = torch_utils.load_config(teacher_model_file)
    teacher_model = TeacherModel(opt=teacher_opt)
    teacher_model.load(teacher_model_file)
    teacher_model.model.eval()
    for _, batch in enumerate(train_batch):
        inputs = [b.cuda() for b in batch[:-1]
                  ] if opt['cuda'] else [b for b in batch[:-1]]
        tch_final_logits, tch_inst_logits, tch_match_logits, _, _ = teacher_model.model(
            inputs)
        teacher_outputs.append([
            tch_final_logits.data.cpu().numpy(),
            tch_inst_logits.data.cpu().numpy(),
            tch_match_logits.data.cpu().numpy()
        ])

student_model = StudentModel(opt=opt, emb_matrix=emb_matrix)

id2label = dict([(v, k) for k, v in constant.LABEL_TO_ID.items()])
dev_f1_history = []
current_lr = opt['lr']

global_step = 0
global_start_time = time.time()
kd_para_str = '> epoch {}/{}:  lambda_kd: {:.6f}'
format_str = '{}: step {}/{} (epoch {}/{}), loss = {:.6f}, ground_loss = {:.6f}, teacher_loss = {:.6f}, hint_loss = {:.6f} ({:.3f} sec/batch), lr: {:.6f}'
max_steps = len(train_batch) * opt['num_epoch']

if opt['teacher_anneal']:
    print('>> max_lkd:', opt['lambda_kd'], 'grade:', opt['anneal_grade'])
    max_lkd = current_lkd = opt['lambda_kd']
    grade_epoch = math.ceil(opt['num_epoch'] /
Esempio n. 7
0
 def get(self,name):
     row = StudentModel.get_by_name(name)
     if row:
         return {'student marks' : row.marks}, 200
     return {'Message':'Not found'}, 404
Esempio n. 8
0
 def get(self,name):
     row = StudentModel.get_by_name(name)
     if row:
         return row.json(), 200
     return {'Message' : 'Not found'}, 404