transform

old TransE-like models
git clone https://esimon.eu/repos/transform.git
Log | Files | Refs | README

config.py (847B)


      1 #!/usr/bin/env python2
      2 
      3 import numpy
      4 import json
      5 from model import *
      6 from relations import *
      7 
      8 def load_config(path):
      9     with open(path, 'r') as config_file:
     10         config = json.load(config_file)
     11         for k, v in config.iteritems():
     12             if isinstance(v, basestring) and v.startswith('python:'):
     13                 config[k] = eval(v[7:])
     14     return config
     15 
     16 def expand_config(base_config):
     17     size = base_config['size']
     18     configs = [ base_config.copy() for _ in xrange(size) ]
     19     for (config, index) in zip(configs, xrange(size)):
     20         if not isinstance(config['model name'], list):
     21             config['model name'] = ('{0} {1:0{width}}').format(config['model name'], index, width=len(str(size-1)))
     22         for k, v in config.iteritems():
     23             if isinstance(v, list):
     24                 config[k] = v[index]
     25     return configs