MCPcopy Create free account
hub / github.com/SooLab/CGFormer / PretrainedConfig

Class PretrainedConfig

bert/configuration_utils.py:31–408  ·  view source on GitHub ↗

r""" Base class for all configuration classes. Handles a few parameters common to all models' configurations as well as methods for loading/downloading/saving configurations. Note: A configuration file can be loaded and saved to disk. Loading the configuration file and u

Source from the content-addressed store, hash-verified

29
30
31class PretrainedConfig(object):
32 r""" Base class for all configuration classes.
33 Handles a few parameters common to all models' configurations as well as methods for loading/downloading/saving configurations.
34
35 Note:
36 A configuration file can be loaded and saved to disk. Loading the configuration file and using this file to initialize a model does **not** load the model weights.
37 It only affects the model's configuration.
38
39 Class attributes (overridden by derived classes):
40 - ``model_type``: a string that identifies the model type, that we serialize into the JSON file, and that we use to recreate the correct object in :class:`~transformers.AutoConfig`.
41
42 Args:
43 finetuning_task (:obj:`string` or :obj:`None`, `optional`, defaults to :obj:`None`):
44 Name of the task used to fine-tune the model. This can be used when converting from an original (TensorFlow or PyTorch) checkpoint.
45 num_labels (:obj:`int`, `optional`, defaults to `2`):
46 Number of classes to use when the model is a classification model (sequences/tokens)
47 output_hidden_states (:obj:`bool`, `optional`, defaults to :obj:`False`):
48 Should the model returns all hidden-states.
49 output_attentions (:obj:`bool`, `optional`, defaults to :obj:`False`):
50 Should the model returns all attentions.
51 torchscript (:obj:`bool`, `optional`, defaults to :obj:`False`):
52 Is the model used with Torchscript (for PyTorch models).
53 """
54 model_type: str = ""
55
56 def __init__(self, **kwargs):
57 # Attributes with defaults
58 self.output_hidden_states = kwargs.pop("output_hidden_states", False)
59 self.output_attentions = kwargs.pop("output_attentions", False)
60 self.use_cache = kwargs.pop("use_cache", True) # Not used by all models
61 self.torchscript = kwargs.pop("torchscript", False) # Only used by PyTorch models
62 self.use_bfloat16 = kwargs.pop("use_bfloat16", False)
63 self.pruned_heads = kwargs.pop("pruned_heads", {})
64
65 # Is decoder is used in encoder-decoder models to differentiate encoder from decoder
66 self.is_encoder_decoder = kwargs.pop("is_encoder_decoder", False)
67 self.is_decoder = kwargs.pop("is_decoder", False)
68
69 # Parameters for sequence generation
70 self.max_length = kwargs.pop("max_length", 20)
71 self.min_length = kwargs.pop("min_length", 0)
72 self.do_sample = kwargs.pop("do_sample", False)
73 self.early_stopping = kwargs.pop("early_stopping", False)
74 self.num_beams = kwargs.pop("num_beams", 1)
75 self.temperature = kwargs.pop("temperature", 1.0)
76 self.top_k = kwargs.pop("top_k", 50)
77 self.top_p = kwargs.pop("top_p", 1.0)
78 self.repetition_penalty = kwargs.pop("repetition_penalty", 1.0)
79 self.length_penalty = kwargs.pop("length_penalty", 1.0)
80 self.no_repeat_ngram_size = kwargs.pop("no_repeat_ngram_size", 0)
81 self.bad_words_ids = kwargs.pop("bad_words_ids", None)
82 self.num_return_sequences = kwargs.pop("num_return_sequences", 1)
83
84 # Fine-tuning task arguments
85 self.architectures = kwargs.pop("architectures", None)
86 self.finetuning_task = kwargs.pop("finetuning_task", None)
87 self.id2label = kwargs.pop("id2label", None)
88 self.label2id = kwargs.pop("label2id", None)

Callers 1

to_diff_dictMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected