def __init__(self, parserpath, savedir): self.savedir = savedir self.parserpath = parserpath self.kwargs = {} # Parser configuration file configfilepath = self.parserpath + '/' + self.savedir + '/config.cfg' self.kwargs['config_file'] = configfilepath # Pre-trained parser model self.kwargs['default'] = {'save_dir': self.parserpath + '/' + self.savedir} self.kwargs['is_evaluation'] = True self.network = Network(**self.kwargs)
def parse(save_dir, **kwargs): """""" kwargs['config_file'] = os.path.join(save_dir, 'config.cfg') files = kwargs.pop('files') output_file = kwargs.pop('output_file', None) output_dir = kwargs.pop('output_dir', None) if len(files) > 1 and output_file is not None: raise ValueError('Cannot provide a value for --output_file when parsing multiple files') kwargs['is_evaluation'] = True network = Network(**kwargs) network.parse(files, output_file=output_file, output_dir=output_dir) return
def train(save_dir, **kwargs): """""" kwargs['config_file'] = kwargs.pop('config_file', '') load = kwargs.pop('load') try: if not load and os.path.isdir(save_dir): raw_input('Save directory already exists. Press <Enter> to continue or <Ctrl-c> to abort.') if os.path.isfile(os.path.join(save_dir, 'config.cfg')): os.remove(os.path.join(save_dir, 'config.cfg')) except KeyboardInterrupt: print() sys.exit(0) network = Network(**kwargs) network.train(load=load) return
def network_init(save_dir, **kwargs): kwargs['config_file'] = os.path.join(save_dir, 'config.cfg') short = kwargs.pop('short', False) if short: kwargs['config_file'] = os.path.join(save_dir, 'config_short.cfg') kwargs['is_evaluation'] = True network = Network(**kwargs) return network
def train(save_dir, **kwargs): """""" load = kwargs.pop('load') try: if not load and os.path.isdir(save_dir): raw_input( 'Save directory already exists. Press <Enter> to continue or <Ctrl-c> to abort.' ) if os.path.isfile(os.path.join(save_dir, 'config.cfg')): os.remove(os.path.join(save_dir, 'config.cfg')) except KeyboardInterrupt: sys.exit(0) #print (kwargs) #print ("train files:",kwargs['train_files']) print("initializing") network = Network(**kwargs) print("initialized") network.train(load=load) return
class UnstableParser: """ Perform parsing using the UnstableParser (universal dependency parser """ def __init__(self, parserpath, savedir): self.savedir = savedir self.parserpath = parserpath self.kwargs = {} # Parser configuration file configfilepath = self.parserpath + '/' + self.savedir + '/config.cfg' self.kwargs['config_file'] = configfilepath # Pre-trained parser model self.kwargs['default'] = {'save_dir': self.parserpath + '/' + self.savedir} self.kwargs['is_evaluation'] = True self.network = Network(**self.kwargs) def parse(self, outputdir, files): """ Parse the files using a pre-trained UnstableParser model """ self.network.parse(files, output_dir=outputdir)
@property def vocabs(self): return self._vocabs @property def datasets(self): return self._datasets @property def optimizer(self): return self._optimizer @property def save_vars(self): return filter(lambda x: u'Pretrained/Embeddings:0' != x.name, tf.global_variables()) @property def non_save_vars(self): return filter(lambda x: u'Pretrained/Embeddings:0' == x.name, tf.global_variables()) @property def global_step(self): return self._global_step @property def global_epoch(self): return self._global_epoch #*************************************************************** if __name__ == '__main__': """""" from parser import Network configurable = Configurable() network = Network.from_configurable(configurable) network.train()