def transform(instance, tokenizer, max_seq_length, max_predictions_per_seq, do_pad=True):
pad = tokenizer.convert_tokens_to_ids(['<STR_LIT>'])[<NUM_LIT:0>]<EOL>input_ids = tokenizer.convert_tokens_to_ids(instance.tokens)<EOL>input_mask = [<NUM_LIT:1>] * len(input_ids)<EOL>segment_ids = list(instance.segment_ids)<EOL>assert len(input_ids) <= max_seq_length<EOL>valid_lengths = len(input_ids)<EOL>masked_lm_positions = list(instance.masked_lm_positions)<EOL>masked_lm_ids = tokenizer.convert_tokens_to_ids(<EOL>instance.masked_lm_labels)<EOL>masked_lm_weights = [<NUM_LIT:1.0>] * len(masked_lm_ids)<EOL>masked_lm_valid_lengths = len(masked_lm_ids)<EOL>if do_pad:<EOL><INDENT>while len(input_ids) < max_seq_length:<EOL><INDENT>input_ids.append(pad)<EOL>input_mask.append(<NUM_LIT:0>)<EOL>segment_ids.append(<NUM_LIT:0>)<EOL><DEDENT>while len(masked_lm_positions) < max_predictions_per_seq:<EOL><INDENT>masked_lm_positions.append(<NUM_LIT:0>)<EOL>masked_lm_ids.append(pad)<EOL>masked_lm_weights.append(<NUM_LIT:0.0>)<EOL><DEDENT>assert len(input_ids) == max_seq_length<EOL>assert len(input_mask) == max_seq_length<EOL>assert len(segment_ids) == max_seq_length<EOL><DEDENT>next_sentence_label = <NUM_LIT:1> if instance.is_random_next else <NUM_LIT:0><EOL>features = {}<EOL>features['<STR_LIT>'] = input_ids<EOL>features['<STR_LIT>'] = input_mask<EOL>features['<STR_LIT>'] = segment_ids<EOL>features['<STR_LIT>'] = masked_lm_positions<EOL>features['<STR_LIT>'] = masked_lm_ids<EOL>features['<STR_LIT>'] = [instance.segment_a_lengths]<EOL>features['<STR_LIT>'] = [instance.segment_b_lengths]<EOL>features['<STR_LIT>'] = masked_lm_ids<EOL>features['<STR_LIT>'] = masked_lm_weights<EOL>features['<STR_LIT>'] = [next_sentence_label]<EOL>features['<STR_LIT>'] = [valid_lengths]<EOL>features['<STR_LIT>'] = [masked_lm_valid_lengths]<EOL>return features<EOL>
Transform instance to inputs for MLM and NSP.