Update README.md
Browse files
README.md
CHANGED
@@ -1,77 +1,210 @@
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
-
license: mit
|
3 |
datasets:
|
4 |
-
-
|
|
|
|
|
|
|
|
|
5 |
language:
|
6 |
- en
|
|
|
|
|
|
|
7 |
widget:
|
8 |
-
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
pipeline_tag: text2text-generation
|
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 |
import torch
|
50 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
51 |
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
64 |
-
model.to(device)
|
65 |
-
inputs = encodeds.to(device)
|
66 |
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
for i in tokenizer.decode(generated_ids[0], skip_special_tokens=True).split('<end_of_turn>')[:2]:
|
72 |
-
ans += i
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
```
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
---
|
|
|
6 |
datasets:
|
7 |
+
- DIBT/10k_prompts_ranked
|
8 |
+
- NickyNicky/10k_prompts_ranked_all_chatml_json_gemma
|
9 |
+
- NickyNicky/10k_prompts_ranked_all
|
10 |
+
model:
|
11 |
+
- NickyNicky/gemma-2b-it_oasst2_chatML_Cluster_2_V1
|
12 |
language:
|
13 |
- en
|
14 |
+
|
15 |
+
library_name: transformers
|
16 |
+
|
17 |
widget:
|
18 |
+
- text: |
|
19 |
+
<bos><start_of_turn>system
|
20 |
+
You are a prompt evaluator response format json.
|
21 |
+
ngrams_length: "8" | cluster_length: "15".
|
22 |
+
lista de codigos linguisticos disponibles: ["en", "en"].<end_of_turn>
|
23 |
+
<start_of_turn>user
|
24 |
+
### |detect_prompt|:
|
25 |
+
What were the main contributions of Eratosthenes to the development of mathematics in ancient Greece?<end_of_turn>
|
26 |
+
<start_of_turn>model\n
|
27 |
+
license: apache-2.0
|
|
|
28 |
---
|
29 |
+
|
30 |
+
|
31 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/641b435ba5f876fe30c5ae0a/WlTKZRULBsCGcZ8L71ViI.png)
|
32 |
+
|
33 |
+
|
34 |
+
```
|
35 |
+
reference data model:
|
36 |
+
|
37 |
+
datasets:
|
38 |
+
link: https://huggingface.co/datasets/NickyNicky/oasst2_clusters
|
39 |
+
|
40 |
+
model:
|
41 |
+
- google/gemma-2b-it
|
42 |
+
Link:
|
43 |
+
https://huggingface.co/google/gemma-2b-it
|
44 |
+
|
45 |
+
base fine tune: NickyNicky/gemma-2b-it_oasst2_chatML_Cluster_2_V1
|
46 |
+
|
47 |
+
Epoch: 2
|
48 |
+
|
49 |
+
future experts: test
|
50 |
+
|
51 |
+
Eval model:
|
52 |
+
- link:
|
53 |
+
soon
|
54 |
+
|
55 |
+
```
|
56 |
+
|
57 |
+
|
58 |
+
## train/loss 0.5407
|
59 |
+
|
60 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/641b435ba5f876fe30c5ae0a/n3HVaz58rb-nOR0Bc64LO.png)
|
61 |
+
|
62 |
+
|
63 |
+
##
|
64 |
+
|
65 |
+
|
66 |
+
```Python
|
67 |
+
!python -m pip install --upgrade pip
|
68 |
+
!pip install "torch>=2.1.1" -U
|
69 |
+
!pip install torchaudio==2.2.0
|
70 |
+
!pip install -q datasets trl peft bitsandbytes sentencepiece wandb
|
71 |
+
!pip install -q accelerate safetensors deepspeed
|
72 |
+
!pip install -q scipy ninja -U
|
73 |
+
!pip install -q -U transformers==4.38.0
|
74 |
+
!pip install flash-attn==2.5.5 --no-build-isolation
|
75 |
+
```
|
76 |
+
|
77 |
+
|
78 |
+
## Version
|
79 |
+
```py
|
80 |
+
import torch
|
81 |
+
torch.__version__
|
82 |
+
#OUTPUTS: ('2.2.0+cu121' )
|
83 |
+
```
|
84 |
+
|
85 |
+
## How to use
|
86 |
+
```py
|
87 |
+
|
88 |
+
from transformers import (
|
89 |
+
AutoModelForCausalLM,
|
90 |
+
AutoTokenizer,
|
91 |
+
BitsAndBytesConfig,
|
92 |
+
HfArgumentParser,
|
93 |
+
TrainingArguments,
|
94 |
+
pipeline,
|
95 |
+
logging,
|
96 |
+
GenerationConfig,
|
97 |
+
TextIteratorStreamer,
|
98 |
+
)
|
99 |
+
|
100 |
+
from transformers import StoppingCriteria, StoppingCriteriaList
|
101 |
+
|
102 |
import torch
|
|
|
103 |
|
104 |
+
# model_id='NickyNicky/gemma-2b-it_oasst2_chatML_Cluster2_aya_multilingual'
|
105 |
+
model_id= "NickyNicky/gemma-2b-it_oasst2_chatML_Cluster2_aya_multilingual_10k_prompts_ranked_all_json_V1"
|
106 |
+
model = AutoModelForCausalLM.from_pretrained(model_id,
|
107 |
+
device_map="auto",
|
108 |
+
trust_remote_code=True,
|
109 |
+
torch_dtype=torch.bfloat16,
|
110 |
+
attn_implementation="flash_attention_2",
|
111 |
+
# load_in_4bit=True,
|
112 |
+
# low_cpu_mem_usage= True,
|
113 |
+
|
114 |
+
)
|
115 |
+
|
116 |
+
max_length=2100
|
117 |
+
print("max_length",max_length)
|
118 |
+
|
119 |
+
|
120 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id,
|
121 |
+
# use_fast = False,
|
122 |
+
max_length=max_length,)
|
123 |
+
|
124 |
+
|
125 |
+
class ListOfTokensStoppingCriteria(StoppingCriteria):
|
126 |
+
"""
|
127 |
+
Clase para definir un criterio de parada basado en una lista de tokens específicos.
|
128 |
+
"""
|
129 |
+
def __init__(self, tokenizer, stop_tokens):
|
130 |
+
self.tokenizer = tokenizer
|
131 |
+
# Codifica cada token de parada y guarda sus IDs en una lista
|
132 |
+
self.stop_token_ids_list = [tokenizer.encode(stop_token, add_special_tokens=False) for stop_token in stop_tokens]
|
133 |
+
|
134 |
+
def __call__(self, input_ids, scores, **kwargs):
|
135 |
+
# Verifica si los últimos tokens generados coinciden con alguno de los conjuntos de tokens de parada
|
136 |
+
for stop_token_ids in self.stop_token_ids_list:
|
137 |
+
len_stop_tokens = len(stop_token_ids)
|
138 |
+
if len(input_ids[0]) >= len_stop_tokens:
|
139 |
+
if input_ids[0, -len_stop_tokens:].tolist() == stop_token_ids:
|
140 |
+
return True
|
141 |
+
return False
|
142 |
+
|
143 |
+
# Uso del criterio de parada personalizado
|
144 |
+
stop_tokens = ["<end_of_turn>"] # Lista de tokens de parada
|
145 |
+
|
146 |
+
# Inicializa tu criterio de parada con el tokenizer y la lista de tokens de parada
|
147 |
+
stopping_criteria = ListOfTokensStoppingCriteria(tokenizer, stop_tokens)
|
148 |
+
|
149 |
+
# Añade tu criterio de parada a una StoppingCriteriaList
|
150 |
+
stopping_criteria_list = StoppingCriteriaList([stopping_criteria])
|
151 |
+
|
152 |
+
|
153 |
+
prompt="""What were the main contributions of Eratosthenes to the development of mathematics in ancient Greece?"""
|
154 |
+
|
155 |
+
#EXAMPLE #1
|
156 |
+
input_text = f'''<bos><start_of_turn>system
|
157 |
+
You are a prompt evaluator response format json.
|
158 |
+
ngrams_length: "8" | cluster_length: "15".
|
159 |
+
lista de codigos linguisticos disponibles: ["en", "en"].<end_of_turn>
|
160 |
+
<start_of_turn>user
|
161 |
+
### |detect_prompt|:
|
162 |
+
{prompt}<end_of_turn>
|
163 |
+
<start_of_turn>model
|
164 |
+
'''
|
165 |
+
|
166 |
+
### OUTPUT EXAMPLE
|
167 |
+
'''
|
168 |
+
{
|
169 |
+
"ngrams_length": "8",
|
170 |
+
"ngrams": ["main", "contribution", "eratosthenes", "development", "mathematic", "ancient", "greece", "ancient greece"],
|
171 |
+
"cluster_length": "15",
|
172 |
+
"cluster": ["quantum", "magnetic", "star", "metal", "planet", "gravity", "force", "universe", "distance", "compound", "gravitational", "quantum computing", "solar", "sun", "earth"],
|
173 |
+
"cluster_desc": ["Astrophysics", "Quantum Computing"],
|
174 |
+
"avg_rating": "5.0",
|
175 |
+
"kind": "synthetic"
|
176 |
+
|
177 |
+
}<end_of_turn><eos>
|
178 |
+
'''
|
179 |
+
|
180 |
+
|
181 |
|
182 |
+
inputs = tokenizer.encode(input_text,
|
183 |
+
return_tensors="pt",
|
184 |
+
add_special_tokens=False).to("cuda:0")
|
185 |
+
max_new_tokens=700
|
186 |
+
generation_config = GenerationConfig(
|
187 |
+
max_new_tokens=max_new_tokens,
|
188 |
+
temperature=0.32,
|
189 |
+
#top_p=0.9,
|
190 |
+
top_k=45,
|
191 |
+
repetition_penalty=1., #1.1
|
192 |
+
do_sample=True,
|
193 |
+
)
|
194 |
+
outputs = model.generate(generation_config=generation_config,
|
195 |
+
input_ids=inputs,
|
196 |
+
stopping_criteria=stopping_criteria_list,)
|
197 |
+
tokenizer.decode(outputs[0], skip_special_tokens=False) #True
|
198 |
+
```
|
199 |
|
|
|
|
|
|
|
200 |
|
201 |
+
## code
|
202 |
|
203 |
+
```
|
204 |
+
https://colab.research.google.com/drive/1z26uLnTZWZ994G_dgyghNzh4hF2eEA6Z?usp=sharing
|
205 |
+
```
|
|
|
|
|
206 |
|
207 |
+
## generated dataset model NickyNicky/prompts_ranked_808.
|
208 |
+
```
|
209 |
+
https://huggingface.co/datasets/NickyNicky/prompts_ranked_808
|
210 |
```
|