<commit_before>"""Classification task."""
import numpy as np

from matchzoo import engine


class Classification(engine.BaseTask):
    """Classification task.

    Examples:
        >>> classification_task = Classification(num_classes=2)
        >>> classification_task.metrics = ['precision']
        >>> classification_task.num_classes
        2
        >>> classification_task.output_shape
        (2,)
        >>> classification_task.output_dtype
        <class 'int'>
        >>> print(classification_task)
        Classification task with 2 classes

    """

    def __init__(self, num_classes: int = 2):
        """Classification task."""
        super().__init__()
        if not isinstance(num_classes, int):
            raise TypeError("Number of classes must be an integer.")
        if num_classes < 2:
            raise ValueError("Number of classes can't be smaller than 2")
        self._num_classes = num_classes

    @property
    def num_classes(self) -> int:
        """:return: number of classes to classify."""
        return self._num_classes

    @classmethod
    def list_available_losses(cls) -> list:
        """:return: a list of available losses."""
        return ['categorical_crossentropy']

    @classmethod
    def list_available_metrics(cls) -> list:
        """:return: a list of available metrics."""
        return ['acc']

    @property
    def output_shape(self) -> tuple:
        """:return: output shape of a single sample of the task."""
        return self._num_classes,

    @property
    def output_dtype(self):
        """:return: target data type, expect `int` as output."""
        return int

    def one_hot_encode(self, arr) ->np.ndarray:
        """:return: A one-hot encoded vector."""
        vec = np.zeros((self._num_classes,))
        vec[arr] = 1
        return vec

    def __str__(self):
        """:return: Task name as string."""
        return f'Classification task with {self._num_classes} classes'
<commit_msg>Fix one hot data type.<commit_after>"""Classification task."""
import numpy as np

from matchzoo import engine


class Classification(engine.BaseTask):
    """Classification task.

    Examples:
        >>> classification_task = Classification(num_classes=2)
        >>> classification_task.metrics = ['precision']
        >>> classification_task.num_classes
        2
        >>> classification_task.output_shape
        (2,)
        >>> classification_task.output_dtype
        <class 'int'>
        >>> print(classification_task)
        Classification task with 2 classes

    """

    def __init__(self, num_classes: int = 2):
        """Classification task."""
        super().__init__()
        if not isinstance(num_classes, int):
            raise TypeError("Number of classes must be an integer.")
        if num_classes < 2:
            raise ValueError("Number of classes can't be smaller than 2")
        self._num_classes = num_classes

    @property
    def num_classes(self) -> int:
        """:return: number of classes to classify."""
        return self._num_classes

    @classmethod
    def list_available_losses(cls) -> list:
        """:return: a list of available losses."""
        return ['categorical_crossentropy']

    @classmethod
    def list_available_metrics(cls) -> list:
        """:return: a list of available metrics."""
        return ['acc']

    @property
    def output_shape(self) -> tuple:
        """:return: output shape of a single sample of the task."""
        return self._num_classes,

    @property
    def output_dtype(self):
        """:return: target data type, expect `int` as output."""
        return int

    def one_hot_encode(self, arr) ->np.ndarray:
        """:return: A one-hot encoded vector."""
        vec = np.zeros((self._num_classes,), dtype=np.int64)
        vec[arr] = 1
        return vec

    def __str__(self):
        """:return: Task name as string."""
        return f'Classification task with {self._num_classes} classes'

{'fraction_non_alphanumeric': 0.11672955974842768, 'fraction_numerical': 0.004528301886792453, 'mean_word_length': 2.55, 'pattern_counts': {'":': 14, '<': 7, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2341480', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1059, 'n_words': 323}