def load_and_cache_examples(args, tokenizer, max_depth=50, evaluate=False, output_examples=False):
    r"""
    Load and process the raw data.
    """
    if args.local_rank not in [-1, 0] and not evaluate:
        torch.distributed.barrier()  # Make sure only the first process in distributed training process the dataset,
        # and the others will use the cache

    # Load data features from cache or dataset file
    input_file = args.predict_file if evaluate else args.train_file

    cached_features_file = os.path.join(os.path.dirname(input_file), 'cached', 'cached_{}_{}_{}_{}'.format(
        'dev' if evaluate else 'train',
        "markuplm",
        str(args.max_seq_length),
        str(max_depth)
    ))
    if not os.path.exists(os.path.dirname(cached_features_file)):
        os.makedirs(os.path.dirname(cached_features_file))

    if os.path.exists(cached_features_file) and not args.overwrite_cache:
        logger.info("Loading features from cached file %s", cached_features_file)
        features = torch.load(cached_features_file)
        if output_examples:
            examples, tag_list = read_squad_examples(input_file=input_file,
                                                     root_dir=args.root_dir,
                                                     is_training=not evaluate,
                                                     tokenizer=tokenizer,
                                                     simplify=True,
                                                     max_depth=max_depth
                                                     )
        else:
            examples = None
    else:
        logger.info("Creating features from dataset file at %s", input_file)

        examples, _ = read_squad_examples(input_file=input_file,
                                          root_dir=args.root_dir,
                                          is_training=not evaluate,
                                          tokenizer=tokenizer,
                                          simplify=False,
                                          max_depth=max_depth)

        features = convert_examples_to_features(examples=examples,
                                                tokenizer=tokenizer,
                                                max_seq_length=args.max_seq_length,
                                                doc_stride=args.doc_stride,
                                                max_query_length=args.max_query_length,
                                                is_training=not evaluate,
                                                cls_token=tokenizer.cls_token,
                                                sep_token=tokenizer.sep_token,
                                                pad_token=tokenizer.pad_token_id,
                                                sequence_a_segment_id=0,
                                                sequence_b_segment_id=0,
                                                max_depth=max_depth)

        if args.local_rank in [-1, 0] and args.save_features:
            logger.info("Saving features into cached file %s", cached_features_file)
            torch.save(features, cached_features_file)

    if args.local_rank == 0 and not evaluate:
        torch.distributed.barrier()  # Make sure only the first process in distributed training process the dataset,
        # and the others will use the cache

    # Convert to Tensors and build dataset
    all_input_ids = torch.tensor([f.input_ids for f in features], dtype=torch.long)
    all_input_mask = torch.tensor([f.input_mask for f in features], dtype=torch.long)
    all_segment_ids = torch.tensor([f.segment_ids for f in features], dtype=torch.long)

    all_xpath_tags_seq = torch.tensor([f.xpath_tags_seq for f in features], dtype=torch.long)
    all_xpath_subs_seq = torch.tensor([f.xpath_subs_seq for f in features], dtype=torch.long)

    if evaluate:
        all_feature_index = torch.arange(all_input_ids.size(0), dtype=torch.long)
        dataset = StrucDataset(all_input_ids, all_input_mask, all_segment_ids, all_feature_index,
                               all_xpath_tags_seq, all_xpath_subs_seq, )
    else:
        all_start_positions = torch.tensor([f.start_position for f in features], dtype=torch.long)
        all_end_positions = torch.tensor([f.end_position for f in features], dtype=torch.long)
        dataset = StrucDataset(all_input_ids, all_input_mask, all_segment_ids,
                               all_xpath_tags_seq, all_xpath_subs_seq,
                               all_start_positions, all_end_positions, )

    if output_examples:
        dataset = (dataset, examples, features)
    return dataset

    Load and process the raw data.
    
markuplm/examples/fine_tuning/run_websrc/run.py