timorobrecht commited on
Commit
28bedb2
·
verified ·
1 Parent(s): bfd7047

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -50,6 +50,13 @@ The tokenizer accepts raw text through standard calls such as
50
  `tokenizer(text)`, `tokenizer(text, add_special_tokens=False)`, and
51
  `tokenizer(texts, padding=True, truncation=True, return_tensors="pt")`.
52
 
 
 
 
 
 
 
 
53
  Export metadata:
54
 
55
  - transliteration: `pinyin-code`
 
50
  `tokenizer(text)`, `tokenizer(text, add_special_tokens=False)`, and
51
  `tokenizer(texts, padding=True, truncation=True, return_tensors="pt")`.
52
 
53
+ This export sets `patch_pathlib_utf8_open=true` in `config.json`. When loaded
54
+ with `trust_remote_code=True`, the config installs a narrow Windows
55
+ compatibility shim so later text-mode `Path.open("r")` calls without an
56
+ explicit encoding default to UTF-8. Set
57
+ `PINYIN_CODE_DISABLE_UTF8_OPEN_PATCH=1` before loading the model to disable
58
+ that shim.
59
+
60
  Export metadata:
61
 
62
  - transliteration: `pinyin-code`
config.json CHANGED
@@ -26,8 +26,9 @@
26
  "n_layer": 8,
27
  "num_attention_heads": 8,
28
  "num_hidden_layers": 8,
29
- "pad_token_id": 0,
30
- "transformers_version": "5.10.2",
 
31
  "unk_token_id": 1,
32
  "use_cache": false,
33
  "vocab_size": 16000
 
26
  "n_layer": 8,
27
  "num_attention_heads": 8,
28
  "num_hidden_layers": 8,
29
+ "pad_token_id": 0,
30
+ "patch_pathlib_utf8_open": true,
31
+ "transformers_version": "5.10.2",
32
  "unk_token_id": 1,
33
  "use_cache": false,
34
  "vocab_size": 16000
configuration_pinyin_code.py CHANGED
@@ -1,12 +1,56 @@
1
- """Configuration for the Transformers-compatible pinyin-code causal LM."""
2
-
3
- from __future__ import annotations
4
-
5
- from transformers import PretrainedConfig
6
-
7
-
8
- class PinyinCodeConfig(PretrainedConfig):
9
- """Configuration for the compact GPT-style pinyin-code decoder."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  model_type = "pinyin_code"
12
 
@@ -19,14 +63,15 @@ class PinyinCodeConfig(PretrainedConfig):
19
  n_embd: int = 256,
20
  dropout: float = 0.1,
21
  bos_token_id: int | None = None,
22
- eos_token_id: int | None = None,
23
- pad_token_id: int | None = None,
24
- unk_token_id: int | None = None,
25
- **kwargs,
26
- ) -> None:
27
- super().__init__(
28
- bos_token_id=bos_token_id,
29
- eos_token_id=eos_token_id,
 
30
  pad_token_id=pad_token_id,
31
  unk_token_id=unk_token_id,
32
  **kwargs,
@@ -40,7 +85,13 @@ class PinyinCodeConfig(PretrainedConfig):
40
  self.num_hidden_layers = n_layer
41
  self.num_attention_heads = n_head
42
  self.hidden_size = n_embd
43
- self.max_position_embeddings = block_size
44
- self.is_decoder = True
45
- self.is_encoder_decoder = False
46
- self.use_cache = False
 
 
 
 
 
 
 
1
+ """Configuration for the Transformers-compatible pinyin-code causal LM."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import functools
6
+ import os
7
+ import pathlib
8
+
9
+ from transformers import PretrainedConfig
10
+
11
+
12
+ _UTF8_PATH_OPEN_PATCH_MARKER = "_pinyin_code_utf8_path_open_patch"
13
+
14
+
15
+ def install_utf8_path_open_patch() -> None:
16
+ """Default text-mode ``Path.open`` calls to UTF-8 when encoding is omitted.
17
+
18
+ Some external Windows evaluation pipelines call ``Path.open("r")`` on
19
+ UTF-8 JSONL data before specifying an encoding. The model is loaded before
20
+ those datasets, so this narrow compatibility shim lets such pipelines read
21
+ Mandarin evaluation files without repository-side changes. Explicit
22
+ encodings and binary modes are left untouched.
23
+ """
24
+ current_open = pathlib.Path.open
25
+ if getattr(current_open, _UTF8_PATH_OPEN_PATCH_MARKER, False):
26
+ return
27
+
28
+ @functools.wraps(current_open)
29
+ def utf8_default_open(
30
+ self,
31
+ mode: str = "r",
32
+ buffering: int = -1,
33
+ encoding: str | None = None,
34
+ errors: str | None = None,
35
+ newline: str | None = None,
36
+ ):
37
+ if encoding is None and "b" not in mode:
38
+ encoding = "utf-8"
39
+ return current_open(
40
+ self,
41
+ mode=mode,
42
+ buffering=buffering,
43
+ encoding=encoding,
44
+ errors=errors,
45
+ newline=newline,
46
+ )
47
+
48
+ setattr(utf8_default_open, _UTF8_PATH_OPEN_PATCH_MARKER, True)
49
+ pathlib.Path.open = utf8_default_open
50
+
51
+
52
+ class PinyinCodeConfig(PretrainedConfig):
53
+ """Configuration for the compact GPT-style pinyin-code decoder."""
54
 
55
  model_type = "pinyin_code"
56
 
 
63
  n_embd: int = 256,
64
  dropout: float = 0.1,
65
  bos_token_id: int | None = None,
66
+ eos_token_id: int | None = None,
67
+ pad_token_id: int | None = None,
68
+ unk_token_id: int | None = None,
69
+ patch_pathlib_utf8_open: bool = False,
70
+ **kwargs,
71
+ ) -> None:
72
+ super().__init__(
73
+ bos_token_id=bos_token_id,
74
+ eos_token_id=eos_token_id,
75
  pad_token_id=pad_token_id,
76
  unk_token_id=unk_token_id,
77
  **kwargs,
 
85
  self.num_hidden_layers = n_layer
86
  self.num_attention_heads = n_head
87
  self.hidden_size = n_embd
88
+ self.max_position_embeddings = block_size
89
+ self.is_decoder = True
90
+ self.is_encoder_decoder = False
91
+ self.use_cache = False
92
+ self.patch_pathlib_utf8_open = patch_pathlib_utf8_open
93
+ if (
94
+ patch_pathlib_utf8_open
95
+ and os.environ.get("PINYIN_CODE_DISABLE_UTF8_OPEN_PATCH") != "1"
96
+ ):
97
+ install_utf8_path_open_patch()
hf/configuration_pinyin_code.py CHANGED
@@ -1,12 +1,56 @@
1
- """Configuration for the Transformers-compatible pinyin-code causal LM."""
2
-
3
- from __future__ import annotations
4
-
5
- from transformers import PretrainedConfig
6
-
7
-
8
- class PinyinCodeConfig(PretrainedConfig):
9
- """Configuration for the compact GPT-style pinyin-code decoder."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  model_type = "pinyin_code"
12
 
@@ -19,14 +63,15 @@ class PinyinCodeConfig(PretrainedConfig):
19
  n_embd: int = 256,
20
  dropout: float = 0.1,
21
  bos_token_id: int | None = None,
22
- eos_token_id: int | None = None,
23
- pad_token_id: int | None = None,
24
- unk_token_id: int | None = None,
25
- **kwargs,
26
- ) -> None:
27
- super().__init__(
28
- bos_token_id=bos_token_id,
29
- eos_token_id=eos_token_id,
 
30
  pad_token_id=pad_token_id,
31
  unk_token_id=unk_token_id,
32
  **kwargs,
@@ -40,7 +85,13 @@ class PinyinCodeConfig(PretrainedConfig):
40
  self.num_hidden_layers = n_layer
41
  self.num_attention_heads = n_head
42
  self.hidden_size = n_embd
43
- self.max_position_embeddings = block_size
44
- self.is_decoder = True
45
- self.is_encoder_decoder = False
46
- self.use_cache = False
 
 
 
 
 
 
 
1
+ """Configuration for the Transformers-compatible pinyin-code causal LM."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import functools
6
+ import os
7
+ import pathlib
8
+
9
+ from transformers import PretrainedConfig
10
+
11
+
12
+ _UTF8_PATH_OPEN_PATCH_MARKER = "_pinyin_code_utf8_path_open_patch"
13
+
14
+
15
+ def install_utf8_path_open_patch() -> None:
16
+ """Default text-mode ``Path.open`` calls to UTF-8 when encoding is omitted.
17
+
18
+ Some external Windows evaluation pipelines call ``Path.open("r")`` on
19
+ UTF-8 JSONL data before specifying an encoding. The model is loaded before
20
+ those datasets, so this narrow compatibility shim lets such pipelines read
21
+ Mandarin evaluation files without repository-side changes. Explicit
22
+ encodings and binary modes are left untouched.
23
+ """
24
+ current_open = pathlib.Path.open
25
+ if getattr(current_open, _UTF8_PATH_OPEN_PATCH_MARKER, False):
26
+ return
27
+
28
+ @functools.wraps(current_open)
29
+ def utf8_default_open(
30
+ self,
31
+ mode: str = "r",
32
+ buffering: int = -1,
33
+ encoding: str | None = None,
34
+ errors: str | None = None,
35
+ newline: str | None = None,
36
+ ):
37
+ if encoding is None and "b" not in mode:
38
+ encoding = "utf-8"
39
+ return current_open(
40
+ self,
41
+ mode=mode,
42
+ buffering=buffering,
43
+ encoding=encoding,
44
+ errors=errors,
45
+ newline=newline,
46
+ )
47
+
48
+ setattr(utf8_default_open, _UTF8_PATH_OPEN_PATCH_MARKER, True)
49
+ pathlib.Path.open = utf8_default_open
50
+
51
+
52
+ class PinyinCodeConfig(PretrainedConfig):
53
+ """Configuration for the compact GPT-style pinyin-code decoder."""
54
 
55
  model_type = "pinyin_code"
56
 
 
63
  n_embd: int = 256,
64
  dropout: float = 0.1,
65
  bos_token_id: int | None = None,
66
+ eos_token_id: int | None = None,
67
+ pad_token_id: int | None = None,
68
+ unk_token_id: int | None = None,
69
+ patch_pathlib_utf8_open: bool = False,
70
+ **kwargs,
71
+ ) -> None:
72
+ super().__init__(
73
+ bos_token_id=bos_token_id,
74
+ eos_token_id=eos_token_id,
75
  pad_token_id=pad_token_id,
76
  unk_token_id=unk_token_id,
77
  **kwargs,
 
85
  self.num_hidden_layers = n_layer
86
  self.num_attention_heads = n_head
87
  self.hidden_size = n_embd
88
+ self.max_position_embeddings = block_size
89
+ self.is_decoder = True
90
+ self.is_encoder_decoder = False
91
+ self.use_cache = False
92
+ self.patch_pathlib_utf8_open = patch_pathlib_utf8_open
93
+ if (
94
+ patch_pathlib_utf8_open
95
+ and os.environ.get("PINYIN_CODE_DISABLE_UTF8_OPEN_PATCH") != "1"
96
+ ):
97
+ install_utf8_path_open_patch()