Following this instruction :
1. Strictly adhere to PEP-8 standards, ensuring code is clean, well-structured, and follows Python's style guide for readability.
2. Use appropriate modules like `typing` for type hints, ensuring code clarity, maintainability, and leveraging Python's standard libraries effectively.
3. Focus on time, space, robustness, scalability; write optimized, efficient code that can handle large datasets and scale seamlessly.
4. Implement comprehensive error handling, catching exceptions gracefully, providing meaningful error messages, and ensuring code robustness under unexpected conditions.
5. Ensure the developer agent writes advanced, maintainable Python code, balancing performance and readability while adhering to best practices.


TASK: Using transformers module AutoTokenizer or calling tokenizer from other module , 

1) develop  advanced prompt_template class
2) we advanced tokenization , with proper special tokens , padding , max_length, very advanced tokenization 

return  dic(str, tensor) input_ids ,  labels , masked_ids 


NOTE: write code task 




below api is fixed (dont write below code) again

from typing import List, Any, Set
from datasets import load_dataset, Dataset as HFDataset
from torch.utils.data.dataset import Dataset as TorchDataset, ConcatDataset
import logging

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


class HFDatasetWrapper(TorchDataset):
    """
    A wrapper to adapt a HuggingFace Dataset to PyTorch's Dataset interface,
    ensuring only specified columns are returned.
    """
    def __init__(self, hf_dataset: HFDataset, columns: List[str]) -> None:
        self.hf_dataset = hf_dataset
        self.columns = columns

    def __getitem__(self, idx: int) -> Any:
        item = self.hf_dataset[int(idx)]
        return {col: item[col] for col in self.columns}

    def __len__(self) -> int:
        return len(self.hf_dataset)


def load_and_concat_datasets(dataset_names: List[str]) -> TorchDataset:
    """
    Loads multiple datasets by name, selecting common columns, and concatenates them.

    Parameters:
        dataset_names (List[str]): List of dataset names to load.

    Returns:
        TorchDataset: Concatenated PyTorch Dataset containing data from all datasets.
    """
    datasets_list = []
    datasets_columns: List[Set[str]] = []
    datasets_splits = []

    for name in dataset_names:
        try:
            # Load the dataset by name
            dataset = load_dataset(name)
            logger.info(f"Loaded dataset '{name}' successfully.")

            # Select the 'train' split if available, else use the first available split
            if 'train' in dataset:
                split_dataset = dataset['train']
            else:
                split_name = next(iter(dataset.keys()))
                split_dataset = dataset[split_name]
                logger.warning(
                    f"Dataset '{name}' does not have a 'train' split. "
                    f"Using split '{split_name}' instead."
                )

            datasets_splits.append(split_dataset)
            datasets_columns.append(set(split_dataset.column_names))

        except Exception as e:
            logger.error(f"Error loading dataset '{name}': {e}")
            continue

    if not datasets_splits:
        raise ValueError("No datasets were loaded successfully.")

    # Find common columns among all datasets
    common_columns = set.intersection(*datasets_columns)
    if not common_columns:
        raise ValueError("No common columns found among the datasets.")

    common_columns = list(common_columns)
    logger.info(f"Common columns among datasets: {common_columns}")

    for split_dataset in datasets_splits:
        # Wrap the dataset and select common columns
        wrapped_dataset = HFDatasetWrapper(split_dataset, common_columns)
        datasets_list.append(wrapped_dataset)

    concatenated_dataset = ConcatDataset(datasets_list)
    logger.info("Datasets concatenated successfully.")
    return concatenated_dataset