musabc commited on
Commit
c55c554
·
verified ·
1 Parent(s): b8d39f1

Upload sft_02_tokenize.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. sft_02_tokenize.py +6 -4
sft_02_tokenize.py CHANGED
@@ -42,6 +42,7 @@ SYS_HEADER = "### Sistem:\n"
42
  USER_HEADER = "### Kullanici:\n"
43
  ASST_HEADER = "### Asistan:\n"
44
  EOT_ID = 0 # <|endoftext|>
 
45
 
46
 
47
  def build_prompt_and_response(rec: dict) -> tuple[str, str]:
@@ -96,8 +97,9 @@ def tokenize_records(records: list, tok: Tokenizer, max_len: int,
96
  continue
97
 
98
  prompt_ids = tok.encode(prompt).ids
99
- # Response sonuna <|endoftext|> ekle
100
- response_ids = tok.encode(response).ids + [EOT_ID]
 
101
 
102
  total_len = len(prompt_ids) + len(response_ids)
103
  if total_len > max_len:
@@ -107,8 +109,8 @@ def tokenize_records(records: list, tok: Tokenizer, max_len: int,
107
  # Prompt zaten cok uzun — at
108
  dropped += 1
109
  continue
110
- # Response'tan kes ama son token <|endoftext|> kalsin
111
- response_ids = response_ids[:avail - 1] + [EOT_ID]
112
  long_truncated += 1
113
 
114
  tokens = np.array(prompt_ids + response_ids, dtype=np.uint16)
 
42
  USER_HEADER = "### Kullanici:\n"
43
  ASST_HEADER = "### Asistan:\n"
44
  EOT_ID = 0 # <|endoftext|>
45
+ N_EOT_TRAILING = 4 # response sonuna kac EOT — model "STOP"u guclu ogrenir
46
 
47
 
48
  def build_prompt_and_response(rec: dict) -> tuple[str, str]:
 
97
  continue
98
 
99
  prompt_ids = tok.encode(prompt).ids
100
+ # Response sonuna N_EOT_TRAILING adet <|endoftext|> ekle
101
+ # (model "STOP"u net ogrensin diye — tek EOT %0.17 ile cok zayif sinyal)
102
+ response_ids = tok.encode(response).ids + [EOT_ID] * N_EOT_TRAILING
103
 
104
  total_len = len(prompt_ids) + len(response_ids)
105
  if total_len > max_len:
 
109
  # Prompt zaten cok uzun — at
110
  dropped += 1
111
  continue
112
+ # Response'tan kes ama N_EOT_TRAILING EOT kalsin
113
+ response_ids = response_ids[:avail - N_EOT_TRAILING] + [EOT_ID] * N_EOT_TRAILING
114
  long_truncated += 1
115
 
116
  tokens = np.array(prompt_ids + response_ids, dtype=np.uint16)