Prompt tuning
mindnlp.peft.tuners.prompt_tuning.config
¶
prompt tuning config.
mindnlp.peft.tuners.prompt_tuning.config.PromptTuningConfig
dataclass
¶
Bases: PromptLearningConfig
This is the configuration class to store the configuration of a [PromptEmbedding].
| PARAMETER | DESCRIPTION |
|---|---|
prompt_tuning_init |
The initialization of the prompt embedding.
TYPE:
|
prompt_tuning_init_text |
The text to initialize the prompt embedding. Only used if
TYPE:
|
tokenizer_name_or_path |
The name or path of the tokenizer. Only used if
TYPE:
|
tokenizer_kwargs |
The keyword arguments to pass to
TYPE:
|
Source code in mindnlp/peft/tuners/prompt_tuning/config.py
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
mindnlp.peft.tuners.prompt_tuning.model
¶
prompt tuning model
mindnlp.peft.tuners.prompt_tuning.model.PromptEmbedding
¶
Bases: Cell
The model to encode virtual tokens into prompt embeddings.
| PARAMETER | DESCRIPTION |
|---|---|
config |
The configuration of the prompt embedding.
TYPE:
|
word_embeddings |
The word embeddings of the base transformer model.
TYPE:
|
Attributes:
- embedding (nn.Embedding) -- The embedding layer of the prompt embedding.
Example:
>>> from peft import PromptEmbedding, PromptTuningConfig
>>> config = PromptTuningConfig(
... peft_type="PROMPT_TUNING",
... task_type="SEQ_2_SEQ_LM",
... num_virtual_tokens=20,
... token_dim=768,
... num_transformer_submodules=1,
... num_attention_heads=12,
... num_layers=12,
... prompt_tuning_init="TEXT",
... prompt_tuning_init_text="Predict if sentiment of this review is positive, negative or neutral",
... tokenizer_name_or_path="t5-base",
... )
>>> # t5_model.shared is the word embeddings of the base model
>>> prompt_embedding = PromptEmbedding(config, t5_model.shared)
Input Shape: (batch_size, total_virtual_tokens)
Output Shape: (batch_size, total_virtual_tokens, token_dim)
Source code in mindnlp/peft/tuners/prompt_tuning/model.py
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |