How to use reporter_class method in Slash

Best Python code snippet using slash

run_experiment.py

Source:run_experiment.py Github

copy

Full Screen

...245 model_class = choose_model_class(args)246 regimen_class = regimen.ProbeRegimen247 task = task_class(args)248 expt_dataset = dataset_class(args, task)249 expt_reporter = reporter_class(args, expt_dataset)250 expt_probe = probe_class(args)251 expt_model = model_class(args)252 expt_regimen = regimen_class(args)253 expt_loss = loss_class(args)254 if train_probe:255 print('Training probe...')256 run_train_probe(args, expt_probe, expt_dataset, expt_model, expt_loss, expt_reporter, expt_regimen)257 if report_results:258 print('Reporting results of trained probe...')259 run_report_results(args, expt_probe, expt_dataset, expt_model, expt_loss, expt_reporter, expt_regimen)260def setup_new_experiment_dir(args, yaml_args, reuse_results_path, embeddings_path):261 """Constructs a directory in which results and params will be stored.262 If reuse_results_path is not None, then it is reused; no new263 directory is constrcted....

Full Screen

Full Screen

configuration.py

Source:configuration.py Github

copy

Full Screen

...217 ext=extension)218 file_path = osp.join(self.work_dir, filename)219 file_paths.append(file_path)220 modes = [self.mode for i in range(len(file_paths))]221 reporter = reporter_class(file_paths=file_paths, modes=modes,222 **self.reporter_partial_kwargs[idx])223 reporters.append(reporter)224 return reporters225 # TODO: remove, not used226 def _gen_work_mapper(self):227 """ """228 work_mapper = self._work_mapper_class(n_workers=self._default_n_workers)229 return work_mapper230 @property231 def reporters(self):232 """ """233 return deepcopy(self._reporters)234 @property235 def work_mapper(self):...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1from argparse import ArgumentParser2import os3import random4from datetime import datetime5import shutil6import yaml7from tqdm import tqdm8import torch9import random10import numpy as np11from . import data, model, probe, regimen, reporter, task, loss12def choose_task_classes(args):13 """Chooses which task class to use based on config.14 Args:15 args: the global config dictionary built by yaml.16 Returns:17 A class to be instantiated as a task specification.18 """19 if args['probe']['task_name'] == 'parse-distance':20 task_class = task.ParseDistanceTask21 reporter_class = reporter.WordPairReporter22 if args['probe_training']['loss'] == 'L1':23 loss_class = loss.L1DistanceLoss24 else:25 raise ValueError("Unknown loss type for given probe type: {}".format(26 args['probe_training']['loss']))27 elif args['probe']['task_name'] == 'parse-depth':28 task_class = task.ParseDepthTask29 reporter_class = reporter.WordReporter30 if args['probe_training']['loss'] == 'L1':31 loss_class = loss.L1DepthLoss32 else:33 raise ValueError("Unknown loss type for given probe type: {}".format(34 args['probe_training']['loss']))35 elif args['probe']['task_name'] == 'part-of-speech':36 task_class = task.PartOfSpeechLabelTask37 reporter_class = reporter.WordReporter38 if args['probe_training']['loss'] == 'cross-entropy':39 loss_class = loss.CrossEntropyLoss40 else:41 raise ValueError("Unknown loss type for given probe type: {}".format(42 args['probe_training']['loss']))43 elif args['probe']['task_name'] == 'rand-prefix-label':44 task_class = task.RandomPrefixLabelTask45 reporter_class = reporter.WordReporter46 if args['probe_training']['loss'] == 'cross-entropy':47 loss_class = loss.CrossEntropyLoss48 else:49 raise ValueError("Unknown loss type for given probe type: {}".format(50 args['probe_training']['loss']))51 elif args['probe']['task_name'] == 'rand-word-label':52 task_class = task.RandomWordLabelTask53 reporter_class = reporter.WordReporter54 if args['probe_training']['loss'] == 'cross-entropy':55 loss_class = loss.CrossEntropyLoss56 else:57 raise ValueError("Unknown loss type for given probe type: {}".format(58 args['probe_training']['loss']))59 elif args['probe']['task_name'] == 'corrupted-part-of-speech':60 task_class = task.CorruptedPartOfSpeechLabelTask61 reporter_class = reporter.WordReporter62 if args['probe_training']['loss'] == 'cross-entropy':63 loss_class = loss.CrossEntropyLoss64 else:65 raise ValueError("Unknown loss type for given probe type: {}".format(66 args['probe_training']['loss']))67 elif args['probe']['task_name'] == 'corrupted-edge-labels':68 task_class = task.CorruptedEdgePositionTask69 reporter_class = reporter.WordPairLabelReporter70 if args['probe_training']['loss'] == 'cross-entropy':71 loss_class = loss.CrossEntropyLoss72 else:73 raise ValueError("Unknown loss type for given probe type: {}".format(74 args['probe_training']['loss']))75 #elif args['probe']['task_name'] == 'corrupted-parse-distance':76 # task_class = task.CorruptedParseDistanceTask77 # reporter_class = reporter.WordPairReporter78 # if args['probe_training']['loss'] == 'L1':79 # loss_class = loss.L1DistanceLoss80 # else:81 # raise ValueError("Unknown loss type for given probe type: {}".format(82 # args['probe_training']['loss']))83 elif args['probe']['task_name'] == 'rand-parse-depth':84 task_class = task.RandomParseDepthTask85 reporter_class = reporter.WordReporter86 if args['probe_training']['loss'] == 'L1':87 loss_class = loss.L1DepthLoss88 else:89 raise ValueError("Unknown loss type for given probe type: {}".format(90 args['probe_training']['loss']))91 elif args['probe']['task_name'] == 'rand-linear-parse-depth':92 task_class = task.RandomLinearParseDepthTask93 reporter_class = reporter.WordReporter94 if args['probe_training']['loss'] == 'L1':95 loss_class = loss.L1DepthLoss96 else:97 raise ValueError("Unknown loss type for given probe type: {}".format(98 args['probe_training']['loss']))99 elif args['probe']['task_name'] == 'balanced-distance':100 task_class = task.BalancedBinaryTreeDistanceTask101 reporter_class = reporter.WordPairReporter102 if args['probe_training']['loss'] == 'L1':103 loss_class = loss.L1DistanceLoss104 else:105 raise ValueError("Unknown loss type for given probe type: {}".format(106 args['probe_training']['loss']))107 elif args['probe']['task_name'] == 'corrupted-parse-depth':108 task_class = task.CorruptedParseDepthTask109 reporter_class = reporter.WordReporter110 if args['probe_training']['loss'] == 'L1':111 loss_class = loss.L1DepthLoss112 else:113 raise ValueError("Unknown loss type for given probe type: {}".format(114 args['probe_training']['loss']))115 else:116 raise ValueError("Unknown probing task type: {}".format(117 args['probe']['task_name']))118 return task_class, reporter_class, loss_class119def choose_dataset_class(args):120 """Chooses which dataset class to use based on config.121 Args:122 args: the global config dictionary built by yaml.123 Returns:124 A class to be instantiated as a dataset.125 """126 if args['model']['model_type'] in {'ELMo-disk', 'ELMo-random-projection', 'ELMo-decay'}:127 dataset_class = data.ELMoDataset128 elif args['model']['model_type'] == 'BERT-disk':129 dataset_class = data.BERTDataset130 else:131 raise ValueError("Unknown model type for datasets: {}".format(132 args['model']['model_type']))133 return dataset_class134def choose_probe_class(args):135 """Chooses which probe and reporter classes to use based on config.136 Args:137 args: the global config dictionary built by yaml.138 Returns:139 A probe_class to be instantiated.140 """141 if args['probe']['task_signature'] == 'word':142 if args['probe']['psd_parameters']:143 return probe.OneWordPSDProbe144 elif 'probe_spec' not in args['probe'] or args['probe']['probe_spec']['probe_hidden_layers'] == 0:145 return probe.OneWordNonPSDProbe146 else:147 return probe.OneWordNNDepthProbe148 elif args['probe']['task_signature'] == 'word_pair':149 if args['probe']['psd_parameters']:150 return probe.TwoWordPSDProbe151 else:152 return probe.TwoWordNonPSDProbe153 elif args['probe']['task_signature'] == 'word_label':154 if 'probe_spec' not in args['probe'] or args['probe']['probe_spec']['probe_hidden_layers'] == 0:155 return probe.OneWordLinearLabelProbe156 else:157 if 'type' not in args['probe'] or args['probe']['type'] == 'none':158 return probe.OneWordNNLabelProbe159 elif args['probe'] or args['probe']['type'] == 'bayes':160 return probe.OneWordNNLabelProbeBayesCompression161 else:162 raise ValueError("Unknown Probe type: not 'none' and not 'bayesian'")163 elif args['probe']['task_signature'] == 'word_pair_label':164 if args['probe']['probe_spec']['probe_type'] == 'linear':165 return probe.TwoWordLinearLabelProbe166 if args['probe']['probe_spec']['probe_type'] == 'bilinear':167 return probe.TwoWordBilinearLabelProbe168 if args['probe']['probe_spec']['probe_type'] == 'MLP':169 return probe.TwoWordNNLabelProbe170 else:171 raise ValueError("Unknown TwoWordLabel type")172 else:173 raise ValueError("Unknown probe type (probe function signature): {}".format(174 args['probe']['task_signature']))175def choose_model_class(args):176 """Chooses which reporesentation learner class to use based on config.177 Args:178 args: the global config dictionary built by yaml.179 Returns:180 A class to be instantiated as a model to supply word representations.181 """182 if args['model']['model_type'] == 'ELMo-disk':183 return model.DiskModel184 elif args['model']['model_type'] == 'BERT-disk':185 return model.DiskModel186 elif args['model']['model_type'] == 'ELMo-random-projection':187 return model.ProjectionModel188 elif args['model']['model_type'] == 'ELMo-decay':189 return model.DecayModel190 elif args['model']['model_type'] == 'pytorch_model':191 raise ValueError("Using pytorch models for embeddings not yet supported...")192 else:193 raise ValueError("Unknown model type: {}".format(194 args['model']['model_type']))195def run_train_probe(args, probe, dataset, model, loss, reporter, regimen):196 """Trains a structural probe according to args.197 Args:198 args: the global config dictionary built by yaml.199 Describes experiment settings.200 probe: An instance of probe.Probe or subclass.201 Maps hidden states to linguistic quantities.202 dataset: An instance of data.SimpleDataset or subclass.203 Provides access to DataLoaders of corpora. 204 model: An instance of model.Model205 Provides word representations.206 reporter: An instance of reporter.Reporter207 Implements evaluation and visualization scripts.208 Returns:209 None; causes probe parameters to be written to disk.210 """211 regimen.train_until_convergence(probe, model, loss,212 dataset.get_train_dataloader(), dataset.get_dev_dataloader())213def run_report_results(args, probe, dataset, model, loss, reporter, regimen):214 """215 Reports results from a structural probe according to args.216 By default, does so only for dev set.217 Requires a simple code change to run on the test set.218 """219 probe_params_path = os.path.join(args['reporting']['root'],args['probe']['params_path'])220 probe.load_state_dict(torch.load(probe_params_path))221 probe.eval()222 dev_dataloader = dataset.get_dev_dataloader()223 dev_predictions = regimen.predict(probe, model, dev_dataloader)...

Full Screen

Full Screen

reporter.py

Source:reporter.py Github

copy

Full Screen

...57 """58 [reporter_name, run_type] = extract_embedded_run_type(reporter_name, run_type)59 reporter_config = self.get_reporter_config(reporter_name, scan_type, run_type)60 reporter_class: ReporterMeta = self.reporters[reporter_name]61 reporter_instance = reporter_class(reporter_config)62 return reporter_instance63 def _add_reporters(self, reporters: dict):64 """adds new tools to tools registry"""65 for reporter_name in reporters:66 reporter = reporters[reporter_name]67 if issubclass(reporter, ReporterMeta):68 if not hasattr(self.reporters, reporter_name):69 log_debug(f"-- installing reporter '{reporter_name}'")70 self.reporters[reporter_name] = reporter71 else:72 log_debug(f"-- skipping '{reporter_name}' already defined")73 continue74 # TODO: else check public functions75 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful