def __init__(self, ## COMPONENTS embed_encoder=None, segment_composer=None, final_transducer=None, ## OPTIONS length_prior=3.3, length_prior_alpha=None, # GeometricSequence epsilon_greedy=None, # GeometricSequence reinforce_scale=None, # GeometricSequence confidence_penalty=None, # SegmentationConfidencePenalty # For segmentation warmup (Always use the poisson prior) segmentation_warmup=0, ## FLAGS learn_delete = False, use_baseline = True, z_normalization = True, learn_segmentation = True, compose_char = False, log_reward = True, debug=False, print_sample=False): model = ParamManager.my_params(self) # Sanity check assert embed_encoder is not None assert segment_composer is not None assert final_transducer is not None # The Embed Encoder transduces the embedding vectors to a sequence of vector self.embed_encoder = embed_encoder if not hasattr(embed_encoder, "hidden_dim"): embed_encoder_dim = yaml_context.default_layer_dim else: embed_encoder_dim = embed_encoder.hidden_dim # The Segment transducer produced word embeddings based on sequence of character embeddings self.segment_composer = segment_composer # The final transducer self.final_transducer = final_transducer # Decision layer of segmentation self.segment_transform = linear.Linear(input_dim = embed_encoder_dim, output_dim = 3 if learn_delete else 2) # The baseline linear regression model self.baseline = linear.Linear(input_dim = embed_encoder_dim, output_dim = 1) # Flags self.use_baseline = use_baseline self.learn_segmentation = learn_segmentation self.learn_delete = learn_delete self.z_normalization = z_normalization self.debug = debug self.compose_char = compose_char self.print_sample = print_sample self.log_reward = log_reward # Fixed Parameters self.length_prior = length_prior self.segmentation_warmup = segmentation_warmup # Variable Parameters self.length_prior_alpha = length_prior_alpha self.lmbd = reinforce_scale self.eps = epsilon_greedy self.confidence_penalty = confidence_penalty # States of the object self.train = False
def __init__(self, exp_global=Ref(Path("exp_global")), evaluation_metric=None, sample_length=50, use_baseline=False, decoder_hidden_dim=None): self.sample_length = sample_length if evaluation_metric is None: self.evaluation_metric = xnmt.evaluator.BLEUEvaluator(ngram=4, smooth=1) else: self.evaluation_metric = evaluation_metric self.use_baseline = use_baseline if self.use_baseline: model = exp_global.dynet_param_collection.param_col decoder_hidden_dim = decoder_hidden_dim or exp_global.default_layer_dim self.baseline = linear.Linear(input_dim=decoder_hidden_dim, output_dim=1, model=model)
def __init__(self, yaml_context, embed_encoder=None, segment_transducer=None, learn_segmentation=True, reinforcement_param=None, length_prior=3.5, learn_delete=False, length_prior_alpha=1.0, use_baseline=True, segmentation_warmup_counter=None): register_handler(self) model = yaml_context.dynet_param_collection.param_col # The Embed Encoder transduces the embedding vectors to a sequence of vector self.embed_encoder = embed_encoder # The Segment transducer predict a category based on the collected vector self.segment_transducer = segment_transducer # The Segment Encoder decides whether to segment or not self.segment_transform = linear.Linear( input_dim=embed_encoder.hidden_dim, output_dim=3 if learn_delete else 2, model=model) # The baseline linear regression model self.baseline = linear.Linear(input_dim=embed_encoder.hidden_dim, output_dim=1, model=model) self.use_baseline = use_baseline # Whether to learn segmentation or not self.learn_segmentation = learn_segmentation # Whether to learn deletion or not self.learn_delete = learn_delete # Other Parameters self.length_prior = length_prior self.length_prior_alpha = length_prior_alpha self.lmbd = reinforcement_param # States of the object self.train = True self.warmup_counter = 0 self.segmentation_warmup_counter = segmentation_warmup_counter
def __init__(self, evaluation_metric=None, sample_length=50, use_baseline=False, decoder_hidden_dim=Ref("exp_global.default_layer_dim")): self.sample_length = sample_length if evaluation_metric is None: self.evaluation_metric = xnmt.evaluator.BLEUEvaluator(ngram=4, smooth=1) else: self.evaluation_metric = evaluation_metric self.use_baseline = use_baseline if self.use_baseline: self.baseline = linear.Linear(input_dim=decoder_hidden_dim, output_dim=1)
def __init__(self, evaluation_metric=None, sample_length=50, use_baseline=False, inv_eval=True, decoder_hidden_dim=Ref("exp_global.default_layer_dim"), baseline=None): self.use_baseline = use_baseline self.inv_eval = inv_eval if evaluation_metric is None: self.evaluation_metric = xnmt.evaluator.FastBLEUEvaluator(ngram=4, smooth=1) else: self.evaluation_metric = evaluation_metric if self.use_baseline: self.baseline = self.add_serializable_component( "baseline", baseline, lambda: linear.Linear(input_dim=decoder_hidden_dim, output_dim=1))