src/baselines/input_pipeline.py
def create_examples_albert(examples, tokenizer):
  """Create examples for Albert.
    Albert uses whole-word masking, so [MASK] should be replaced with the
    number of tokens that the option has. This version only accounts for SINGLE token
    masking, see create_examples_albert_wwm for details on the other approach.

    """
  example = T.valmap(T.get(0), examples)
  # substitute mask with <mask>

  # get option ids
  option_encodings = _get_option_encodings(example, tokenizer, True)
  option_input_ids = [o.input_ids[0] for o in option_encodings]

  # substitute [MASK]
  example['question'] = re.sub(r'( \[MASK\])|(\[MASK\])', tokenizer.mask_token,
                               example['question'])

  # format text input
  text_input = '{context} {question}'.format_map(example)

  # get BatchEncoding
  instance = tokenizer(text=text_input, padding='do_not_pad',
                       add_special_tokens=True)
  # locate pad token
  target_tok_idx = try_get_index(instance.tokens(), tokenizer.mask_token)

  # add example-general info
  instance['example_idx'] = example['example_idx']
  instance['option_idx'] = list(range(4))
  instance['target_tok_idx'] = target_tok_idx
  instance['option_input_ids'] = option_input_ids

  return {k: [instance[k]] for k in instance.keys()}
Create examples for Albert.
    Albert uses whole-word masking, so [MASK] should be replaced with the
    number of tokens that the option has. This version only accounts for SINGLE token
    masking, see create_examples_albert_wwm for details on the other approach.

    
Create examples for Albert.
Albert uses whole-word masking, so [MASK] should be replaced with the
number of tokens that the option has. This version only accounts for SINGLE token
masking, see create_examples_albert_wwm for details on the other approach.
Create examples for Albert . Albert uses whole - word masking so [ MASK ] should be replaced with the number of tokens that the option has . This version only accounts for SINGLE token masking see create_examples_albert_wwm for details on the other approach .
def create_examples_albert(examples, tokenizer):
  example = T.valmap(T.get(0), examples)
  option_encodings = _get_option_encodings(example, tokenizer, True)
  option_input_ids = [o.input_ids[0] for o in option_encodings]
  example['question'] = re.sub(r'( \[MASK\])|(\[MASK\])', tokenizer.mask_token,
                               example['question'])
  text_input = '{context} {question}'.format_map(example)
  instance = tokenizer(text=text_input, padding='do_not_pad',
                       add_special_tokens=True)
  target_tok_idx = try_get_index(instance.tokens(), tokenizer.mask_token)
  instance['example_idx'] = example['example_idx']
  instance['option_idx'] = list(range(4))
  instance['target_tok_idx'] = target_tok_idx
  instance['option_input_ids'] = option_input_ids
  return {k: [instance[k]] for k in instance.keys()}
def create_examples_albert ( examples , tokenizer ) : example = T . valmap ( T . get ( 0 ) , examples ) option_encodings = _get_option_encodings ( example , tokenizer , True ) option_input_ids = [ o . input_ids [ 0 ] for o in option_encodings ] example [ 'question' ] = re . sub ( r'( \[MASK\])|(\[MASK\])' , tokenizer . mask_token , example [ 'question' ] ) text_input = '{context} {question}' . format_map ( example ) instance = tokenizer ( text = text_input , padding = 'do_not_pad' , add_special_tokens = True ) target_tok_idx = try_get_index ( instance . tokens ( ) , tokenizer . mask_token ) instance [ 'example_idx' ] = example [ 'example_idx' ] instance [ 'option_idx' ] = list ( range ( 4 ) ) instance [ 'target_tok_idx' ] = target_tok_idx instance [ 'option_input_ids' ] = option_input_ids return { k : [ instance [ k ] ] for k in instance . keys ( ) }
Create examples for Albert.
Create examples for Albert .
"""Create examples for Albert.
    Albert uses whole-word masking, so [MASK] should be replaced with the
    number of tokens that the option has. This version only accounts for SINGLE token
    masking, see create_examples_albert_wwm for details on the other approach.

    """ # substitute mask with <mask> # get option ids # substitute [MASK] # format text input # get BatchEncoding # locate pad token # add example-general info
examples
tokenizer