Update README.md
Browse files
README.md
CHANGED
@@ -1,13 +1,18 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
# Model Card for Model ID
|
7 |
|
8 |
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
|
10 |
-
|
|
|
11 |
|
12 |
## Model Details
|
13 |
|
@@ -17,13 +22,10 @@ tags: []
|
|
17 |
|
18 |
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
|
20 |
-
- **Developed by:**
|
21 |
-
|
22 |
-
- **
|
23 |
-
- **
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
### Model Sources [optional]
|
29 |
|
@@ -35,165 +37,186 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
35 |
|
36 |
## Uses
|
37 |
|
38 |
-
|
39 |
|
40 |
### Direct Use
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
-
|
64 |
-
### Recommendations
|
65 |
-
|
66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
-
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
|
70 |
## How to Get Started with the Model
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
## Training Details
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
-
|
93 |
-
#### Training Hyperparameters
|
94 |
-
|
95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
-
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
-
|
99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
104 |
-
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
|
199 |
-
[More Information Needed]
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
base_model:
|
6 |
+
- google/gemma-2-9b-it
|
7 |
+
pipeline_tag: text-classification
|
8 |
---
|
9 |
|
10 |
# Model Card for Model ID
|
11 |
|
12 |
<!-- Provide a quick summary of what the model is/does. -->
|
13 |
|
14 |
+
Given a (Query, ModelAAnswer, ModelBAnswer)
|
15 |
+
This model gives a vector in 3D like lMSYS (ModelAWin Proba), (ModelBWin Proba), (Tie Proba)
|
16 |
|
17 |
## Model Details
|
18 |
|
|
|
22 |
|
23 |
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
24 |
|
25 |
+
- **Developed by:** @sayoulala (Yang Zhou)
|
26 |
+
|
27 |
+
- **Model type:** Gemma for Sentence Classification
|
28 |
+
- **Language(s) (NLP):** English Only
|
|
|
|
|
|
|
29 |
|
30 |
### Model Sources [optional]
|
31 |
|
|
|
37 |
|
38 |
## Uses
|
39 |
|
40 |
+
Mimic human preference given a query and 2 different answers.
|
41 |
|
42 |
### Direct Use
|
43 |
|
44 |
+
```python
|
45 |
+
import torch
|
46 |
+
from torch import nn
|
47 |
+
from torch.nn import CrossEntropyLoss, MSELoss, BCEWithLogitsLoss
|
48 |
+
from transformers import Gemma2PreTrainedModel,Gemma2Model
|
49 |
+
from transformers.modeling_outputs import SequenceClassifierOutputWithPast
|
50 |
+
from typing import Optional, List, Union, Tuple
|
51 |
+
from dataclasses import dataclass
|
52 |
+
|
53 |
+
@dataclass
|
54 |
+
class Config:
|
55 |
+
gemma_dir = 'wath5/kgl_lmsys_pref_classif'
|
56 |
+
max_length = 2000
|
57 |
+
batch_size = 8
|
58 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
59 |
+
|
60 |
+
cfg = Config()
|
61 |
+
|
62 |
+
class Gemma2ForSequenceClassificationV1(Gemma2PreTrainedModel):
|
63 |
+
def __init__(self, config):
|
64 |
+
super().__init__(config)
|
65 |
+
self.num_labels = config.num_labels
|
66 |
+
self.model = Gemma2Model(config)
|
67 |
+
self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
|
68 |
+
|
69 |
+
# Initialize weights and apply final processing
|
70 |
+
self.post_init()
|
71 |
+
|
72 |
+
def get_input_embeddings(self):
|
73 |
+
return self.model.embed_tokens
|
74 |
+
|
75 |
+
def set_input_embeddings(self, value):
|
76 |
+
self.model.embed_tokens = value
|
77 |
+
|
78 |
+
def forward(
|
79 |
+
self,
|
80 |
+
input_ids: torch.LongTensor = None,
|
81 |
+
attention_mask: Optional[torch.Tensor] = None,
|
82 |
+
position_ids: Optional[torch.LongTensor] = None,
|
83 |
+
past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,
|
84 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
85 |
+
labels: Optional[torch.LongTensor] = None,
|
86 |
+
use_cache: Optional[bool] = None,
|
87 |
+
output_attentions: Optional[bool] = None,
|
88 |
+
output_hidden_states: Optional[bool] = None,
|
89 |
+
return_dict: Optional[bool] = None,
|
90 |
+
) -> Union[Tuple, SequenceClassifierOutputWithPast]:
|
91 |
+
r"""
|
92 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
93 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
94 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
95 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
96 |
+
"""
|
97 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
98 |
+
|
99 |
+
transformer_outputs = self.model(
|
100 |
+
input_ids,
|
101 |
+
attention_mask=attention_mask,
|
102 |
+
position_ids=position_ids,
|
103 |
+
past_key_values=past_key_values,
|
104 |
+
inputs_embeds=inputs_embeds,
|
105 |
+
use_cache=use_cache,
|
106 |
+
output_attentions=output_attentions,
|
107 |
+
output_hidden_states=output_hidden_states,
|
108 |
+
return_dict=return_dict,
|
109 |
+
)
|
110 |
+
hidden_states = transformer_outputs[0]
|
111 |
+
# logits = self.score(hidden_states)
|
112 |
+
|
113 |
+
if input_ids is not None:
|
114 |
+
batch_size = input_ids.shape[0]
|
115 |
+
else:
|
116 |
+
batch_size = inputs_embeds.shape[0]
|
117 |
+
|
118 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
119 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
120 |
+
if self.config.pad_token_id is None:
|
121 |
+
sequence_lengths = -1
|
122 |
+
else:
|
123 |
+
if input_ids is not None:
|
124 |
+
# if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
|
125 |
+
sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
|
126 |
+
sequence_lengths = sequence_lengths % input_ids.shape[-1]
|
127 |
+
sequence_lengths = sequence_lengths.to(hidden_states.device)
|
128 |
+
else:
|
129 |
+
sequence_lengths = -1
|
130 |
+
hidden_states = hidden_states[
|
131 |
+
torch.arange(batch_size, device=hidden_states.device), sequence_lengths] # eos
|
132 |
+
pooled_logits = self.score(hidden_states)
|
133 |
+
|
134 |
+
return pooled_logits
|
135 |
+
|
136 |
+
|
137 |
+
tokenizer = AutoTokenizer.from_pretrained("/kaggle/input/v7-dpo-16bit-01234-8bit-all/v7_dpo_16bit_01234_8bit_all")
|
138 |
+
|
139 |
+
model = Gemma2ForSequenceClassificationV1.from_pretrained(
|
140 |
+
cfg.gemma_dir,
|
141 |
+
num_labels=3,
|
142 |
+
device_map=cfg.device,
|
143 |
+
use_cache=False,
|
144 |
+
)
|
145 |
+
model.config.pad_token_id = tokenizer.pad_token_id
|
146 |
+
```
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
## How to Get Started with the Model
|
150 |
|
151 |
+
```python
|
152 |
+
from transformers.data.data_collator import pad_without_fast_tokenizer_warning
|
153 |
+
|
154 |
+
@torch.no_grad()
|
155 |
+
def single_prompt_inference(prompt, model, device, max_length=cfg.max_length):
|
156 |
+
"""
|
157 |
+
Perform inference on a single prompt.
|
158 |
+
|
159 |
+
Args:
|
160 |
+
prompt (str): The input prompt for inference.
|
161 |
+
model (torch.nn.Module): The model used for inference.
|
162 |
+
device (torch.device): The device to run inference on.
|
163 |
+
tokenizer (Tokenizer): Tokenizer for preprocessing input text.
|
164 |
+
max_length (int): Maximum sequence length for tokenization.
|
165 |
+
|
166 |
+
Returns:
|
167 |
+
dict: Probabilities for "a_win", "b_win", and "tie".
|
168 |
+
"""
|
169 |
+
# Tokenize the input prompt
|
170 |
+
input_ids = tokenizer(prompt, truncation=True, max_length=max_length)['input_ids']
|
171 |
+
input_ids.append(tokenizer.eos_token_id) # Add EOS token if needed
|
172 |
+
|
173 |
+
# Prepare inputs
|
174 |
+
inputs = pad_without_fast_tokenizer_warning(
|
175 |
+
tokenizer,
|
176 |
+
{"input_ids": [input_ids]}, # Wrap in a list for compatibility
|
177 |
+
padding="max_length",
|
178 |
+
pad_to_multiple_of=None,
|
179 |
+
max_length=max_length,
|
180 |
+
return_tensors="pt",
|
181 |
+
)
|
182 |
+
|
183 |
+
# Move inputs to the appropriate device
|
184 |
+
inputs = inputs.to(device)
|
185 |
+
|
186 |
+
# Run the model
|
187 |
+
outputs = model(**inputs)
|
188 |
+
|
189 |
+
# Get probabilities using softmax
|
190 |
+
proba = outputs.softmax(-1).cpu().squeeze()
|
191 |
+
|
192 |
+
return {
|
193 |
+
"winner_model_a": proba[0].item(),
|
194 |
+
"winner_model_b": proba[1].item(),
|
195 |
+
"tie": proba[2].item(),
|
196 |
+
}
|
197 |
+
|
198 |
+
|
199 |
+
def create_rounds(query: str,
|
200 |
+
answer_a: str,
|
201 |
+
answer_b: str) -> str:
|
202 |
+
prompt =f"""User question:
|
203 |
+
\"""{query}\"""
|
204 |
+
Answer A:
|
205 |
+
\"""{answer_a}\"""
|
206 |
+
Answer B:
|
207 |
+
\"""{answer_b}\"""
|
208 |
+
"""
|
209 |
+
return prompt
|
210 |
+
|
211 |
+
query = "Hello, what is the height of the reassembled blind product?"
|
212 |
+
answer_a = "Vous pouvez trouver toutes les informations techniques, y compris la hauteur du produit store remonté, directement sur la fiche produit de notre site. Cliquez sur l'onglet 'Produits' dnas la barre de navigation ou utilisez le moteur de recherche pour accéder au produit recherché. Avez vous une autre question ?"
|
213 |
+
answer_b = "The height of the aluminum Venetian blind is 130 cm."
|
214 |
+
prompt_direct = create_rounds(query, answer_a, answer_b)
|
215 |
+
|
216 |
+
single_prompt_inference(prompt_direct, model=model, device=cfg.device)
|
217 |
+
```
|
218 |
|
219 |
## Training Details
|
220 |
|
221 |
+
https://github.com/shyoulala/LMSYS_BlackPearl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
|
|