Best Python code snippet using Airtest
projection_layers.py
Source:projection_layers.py
...21class ProjectionLayer(base_layers.BaseLayer):22 """Base class for encoders."""23 def __init__(self, model_config, mode):24 """Create projection."""25 def _get_params(varname, default_value=None):26 value = model_config[varname] if varname in model_config else default_value27 default = "" if varname in model_config else " (default)"28 logging.info("%s = %s%s", varname, value, default)29 setattr(self, varname, value)30 self.mode = mode31 _get_params("feature_size")32 _get_params("max_seq_len", 0)33 _get_params("add_eos_tag", False)34 _get_params("add_bos_tag", False)35 _get_params("hashtype", "murmur")36 _get_params("split_on_space", True)37 _get_params("token_separators", "")38 _get_params("vocabulary", "")39 _get_params("quantize")40 _get_params("word_novelty_bits", 0)41 _get_params("doc_size_levels", 0)42 self.distortion_probability = 0.043 if mode == base_layers.TRAIN:44 _get_params("distortion_probability", 0.0)45 parameters = base_layers.Parameters(mode, self.quantize)46 super(ProjectionLayer, self).__init__(parameters=parameters)47 def call(self, inputs):48 projection, _, seq_length = ssp.sequence_string_projection(49 input=inputs,50 feature_size=self.feature_size,51 max_splits=self.max_seq_len - 1,52 hashtype=self.hashtype,53 distortion_probability=self.distortion_probability,54 split_on_space=self.split_on_space,55 token_separators=self.token_separators,56 word_novelty_bits=self.word_novelty_bits,57 doc_size_levels=self.doc_size_levels,58 add_eos_tag=self.add_eos_tag,59 add_bos_tag=self.add_bos_tag,60 vocabulary=self.vocabulary)61 modes = [base_layers.PREDICT, base_layers.TFLITE]62 if self.mode not in modes and self.max_seq_len > 0:63 short_by = self.max_seq_len - tf.shape(projection)[1]64 projection = tf.pad(projection, [[0, 0], [0, short_by], [0, 0]])65 batch_size = self.get_batch_dimension(inputs)66 projection = tf.reshape(projection,67 [batch_size, self.max_seq_len, self.feature_size])68 if self.mode in modes:69 projection = self.qrange_tanh(projection)70 return projection, seq_length71class ProjectionLayerPreSegmented(base_layers.BaseLayer):72 """Base class for encoders."""73 def __init__(self, model_config, mode):74 """Create projection."""75 def _get_params(varname, default_value=None):76 value = model_config[varname] if varname in model_config else default_value77 default = "" if varname in model_config else " (default)"78 logging.info("%s = %s%s", varname, value, default)79 setattr(self, varname, value)80 self.mode = mode81 _get_params("feature_size")82 _get_params("add_eos_tag", False)83 _get_params("add_bos_tag", False)84 _get_params("vocabulary", "")85 _get_params("quantize")86 self.distortion_probability = 0.087 if mode == base_layers.TRAIN:88 _get_params("distortion_probability", 0.0)89 parameters = base_layers.Parameters(mode, self.quantize)90 super(ProjectionLayerPreSegmented, self).__init__(parameters=parameters)91 def call(self, inputs, sequence_length):92 projection = sspv2.sequence_string_projection_v2(93 input=inputs,94 sequence_length=sequence_length,95 feature_size=self.feature_size,96 distortion_probability=self.distortion_probability,97 add_eos_tag=self.add_eos_tag,98 add_bos_tag=self.add_bos_tag,99 vocabulary=self.vocabulary)100 modes = [base_layers.PREDICT, base_layers.TFLITE]101 if self.mode in modes:102 projection = self.qrange_tanh(projection)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!