def METHOD_NAME(self, data: Dict[str, Any]) -> Dict[str, Any]:
    r"""
    Building training samples.
    step 1. Preprocess the data using the logic of `_build_infer_sample`
        and make sure the label data in the result.
    step 2. Preprocess the label data. Contains:
        - add ` ` before the label value and add `ref_dict` value
        - tokenize the label as `target` value without `bos` token.
        - add `bos` token and remove `eos` token of `target` as `prev_output_tokens`.
        - add constraints mask.
    Args:
        data (`Dict[str, Any]`): Input data, should contains the key of `image`,
            `prompt` and `label`, `image` refers the image input data, `prompt`
            refers the text input data the `label` is the supervised data for training.
    Return:
        A dict object, contains source, image, mask, label, target tokens,
        and previous output tokens data.
    """
    sample = self._build_infer_sample(data)
    target = ' {}'.format(sample['label'])
    sample['ref_dict'] = {sample['label']: 1.0}
    sample['target'] = self.tokenize_text(target, add_bos=False)
    sample['prev_output_tokens'] = torch.cat(
        [self.bos_item, sample['target'][:-1]])
    if self.constraint_trie is not None:
        constraint_mask = torch.zeros((len(sample['prev_output_tokens']),
                                       len(self.tgt_dict))).bool()
        for i in range(len(sample['prev_output_tokens'])):
            constraint_prefix_token = sample[
                'prev_output_tokens'][:i + 1].tolist()
            constraint_nodes = self.constraint_trie.get_next_layer(
                constraint_prefix_token)
            constraint_mask[i][constraint_nodes] = True
        sample['constraint_mask'] = constraint_mask
    return sample