Load the model with saved tables
()
| 30 | |
| 31 | |
| 32 | def load_model(): |
| 33 | """ |
| 34 | Load the model with saved tables |
| 35 | """ |
| 36 | # Load model options |
| 37 | print 'Loading model parameters...' |
| 38 | with open('%s.pkl'%path_to_umodel, 'rb') as f: |
| 39 | uoptions = pkl.load(f) |
| 40 | with open('%s.pkl'%path_to_bmodel, 'rb') as f: |
| 41 | boptions = pkl.load(f) |
| 42 | |
| 43 | # Load parameters |
| 44 | uparams = init_params(uoptions) |
| 45 | uparams = load_params(path_to_umodel, uparams) |
| 46 | utparams = init_tparams(uparams) |
| 47 | bparams = init_params_bi(boptions) |
| 48 | bparams = load_params(path_to_bmodel, bparams) |
| 49 | btparams = init_tparams(bparams) |
| 50 | |
| 51 | # Extractor functions |
| 52 | print 'Compiling encoders...' |
| 53 | embedding, x_mask, ctxw2v = build_encoder(utparams, uoptions) |
| 54 | f_w2v = theano.function([embedding, x_mask], ctxw2v, name='f_w2v') |
| 55 | embedding, x_mask, ctxw2v = build_encoder_bi(btparams, boptions) |
| 56 | f_w2v2 = theano.function([embedding, x_mask], ctxw2v, name='f_w2v2') |
| 57 | |
| 58 | # Tables |
| 59 | print 'Loading tables...' |
| 60 | utable, btable = load_tables() |
| 61 | |
| 62 | # Store everything we need in a dictionary |
| 63 | print 'Packing up...' |
| 64 | model = {} |
| 65 | model['uoptions'] = uoptions |
| 66 | model['boptions'] = boptions |
| 67 | model['utable'] = utable |
| 68 | model['btable'] = btable |
| 69 | model['f_w2v'] = f_w2v |
| 70 | model['f_w2v2'] = f_w2v2 |
| 71 | |
| 72 | return model |
| 73 | |
| 74 | |
| 75 | def load_tables(): |
nothing calls this directly
no test coverage detected