File size: 2,358 Bytes
26f3ae9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd863d3
 
 
 
 
 
 
26f3ae9
 
 
 
 
 
 
 
 
877fdb8
 
 
 
 
 
 
 
26f3ae9
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Configuration class for SentimentClassifier."""

from typing import Optional

from transformers import PretrainedConfig


class SentimentClassifierConfig(PretrainedConfig):
    """
    Configuration class for SentimentClassifier model.

    This class stores the configuration of a :class:`~SentimentClassifier` model.
    It is used to instantiate a SentimentClassifier model according to the specified
    arguments, defining the model architecture.

    Args:
        pretrained_model (:obj:`str`, defaults to :obj:`"xlm-roberta-base"`):
            Name of the pre-trained transformer model to use as encoder.
        num_labels (:obj:`int`, defaults to :obj:`3`):
            Number of sentiment classes (positive/neutral/negative).
        dropout (:obj:`float`, defaults to :obj:`0.1`):
            Dropout probability for the classification head.
        hidden_size (:obj:`int`, optional):
            Hidden size of the encoder model. If None, will be auto-detected from encoder config.
        model_type (:obj:`str`, defaults to :obj:`"sentiment-classifier"`):
            Model type identifier for the Hugging Face Hub.
    """

    model_type = "sentiment-classifier"

    # Enable trust_remote_code by mapping to the custom classes
    # This tells HuggingFace where to find the custom model and config classes
    auto_map = {
        "AutoConfig": "configuration_sentiment.SentimentClassifierConfig",
        "AutoModelForSequenceClassification": "sentiment_classifier.SentimentClassifier",
    }

    def __init__(
        self,
        pretrained_model: str = "xlm-roberta-base",
        num_labels: int = 3,
        dropout: float = 0.1,
        hidden_size: Optional[int] = None,
        **kwargs,
    ):
        """Initialize SentimentClassifierConfig."""
        # Set auto_map in kwargs before calling super().__init__
        # This ensures it gets saved to config.json
        if "auto_map" not in kwargs:
            kwargs["auto_map"] = {
                "AutoConfig": "configuration_sentiment.SentimentClassifierConfig",
                "AutoModelForSequenceClassification": "sentiment_classifier.SentimentClassifier",
            }

        super().__init__(**kwargs)

        self.pretrained_model = pretrained_model
        self.num_labels = num_labels
        self.dropout = dropout
        self.hidden_size = hidden_size