masahiroid commited on
Commit
b84238f
·
verified ·
1 Parent(s): 6342438

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +30 -12
README.md CHANGED
@@ -13,22 +13,29 @@ pipeline_tag: token-classification
13
 
14
  # bert-base-ner-mlx
15
 
 
 
 
 
 
16
  [dslim/bert-base-NER](https://huggingface.co/dslim/bert-base-NER)(標準的なBERT-baseに
17
  固有表現抽出ヘッドを乗せたモデル。CoNLL-2003、PER/ORG/LOC/MISCの4種)の
18
  [MLX](https://github.com/ml-explore/mlx)版です。
19
 
20
- This is an unofficial MLX conversion of
21
- [dslim/bert-base-NER](https://huggingface.co/dslim/bert-base-NER).
22
- All credit for the original model goes to its author.
23
 
24
- ## これはmlx-embeddingsでは読み込めません
 
 
 
 
25
 
26
  `mlx-embeddings`はembedding/reranker用のpooling出力をターゲットにしており、トークン単位の
27
  分類ヘッド(各トークンに対して独立にラベルを出す構成)には対応していないため、**MLXでの
28
  実装をゼロから書き起こして**変換しています。同梱の`bert_ner_mlx.py`が必要です。構造自体は
29
  標準的なpost-norm BERTエンコーダー + 線形分類ヘッドとシンプルです。
30
 
31
- ## 使い方
32
 
33
  ```python
34
  import mlx.core as mx
@@ -55,17 +62,28 @@ for tok, label_id in zip(tokens, labels):
55
  print(tok, model.config.id2label[label_id] if hasattr(model, "config") else label_id)
56
  ```
57
 
 
 
 
58
  ラベルは元モデルと同じ: `{0: "O", 1: "B-MISC", 2: "I-MISC", 3: "B-PER", 4: "I-PER",
59
  5: "B-ORG", 6: "I-ORG", 7: "B-LOC", 8: "I-LOC"}`。
60
 
61
- ## 精度検証
 
 
 
62
 
63
  PyTorch fp32リファレンスと、実際の文章1件(人名・地名・組織名を含む)で比較:
64
 
65
- | 精度 | logitsコサイン類似度 | ラベル一致率 |
66
  |---|---|---|
67
  | MLX fp32 | 1.0 | 100% |
68
- | MLX fp16(本リリース) | 0.99999994 | 100% |
 
 
 
 
 
69
 
70
  fp16変換の際、attention maskのマスク値に`-1e9`のようなfp16で表現できない大きな負数を使うと、
71
  マスクされていない(`mask=1`)位置で`0 * (-inf)`が発生してNaNになる罠があった。
@@ -76,13 +94,13 @@ fp16の範囲内に収まる`-1e4`に変更して解消している(詳細は`
76
 
77
  | Item | Value |
78
  |---|---|
79
- | Base model | `dslim/bert-base-NER`(BERT-base、108M params) |
80
  | Precision | float16 |
81
- | Framework | MLX(`bert_ner_mlx.py`によるゼロからの実装) |
82
 
83
  ## Notes
84
 
85
  - This is a community conversion, not an official release from the original author.
86
  - 本変換は非公式のコミュニティ版です。
87
- - セキュリティー監査には[model-audit-lite](https://github.com/masahirocom/model-audit-lite)を
88
- 使用しています(詳細は`SECURITY.md`)。
 
13
 
14
  # bert-base-ner-mlx
15
 
16
+ This is an unofficial [MLX](https://github.com/ml-explore/mlx) conversion of
17
+ [dslim/bert-base-NER](https://huggingface.co/dslim/bert-base-NER) (a standard
18
+ BERT-base with a named-entity-recognition head on top, trained on CoNLL-2003:
19
+ PER/ORG/LOC/MISC). All credit for the original model goes to its author.
20
+
21
  [dslim/bert-base-NER](https://huggingface.co/dslim/bert-base-NER)(標準的なBERT-baseに
22
  固有表現抽出ヘッドを乗せたモデル。CoNLL-2003、PER/ORG/LOC/MISCの4種)の
23
  [MLX](https://github.com/ml-explore/mlx)版です。
24
 
25
+ ## This cannot be loaded with mlx-embeddings / mlx-embeddingsでは読み込めません
 
 
26
 
27
+ `mlx-embeddings` targets pooled embedding/reranker outputs and doesn't
28
+ support a per-token classification head. This model was **reimplemented from
29
+ scratch for MLX** and requires the bundled `bert_ner_mlx.py`. The
30
+ architecture itself is simple: a standard post-norm BERT encoder plus a
31
+ linear classification head.
32
 
33
  `mlx-embeddings`はembedding/reranker用のpooling出力をターゲットにしており、トークン単位の
34
  分類ヘッド(各トークンに対して独立にラベルを出す構成)には対応していないため、**MLXでの
35
  実装をゼロから書き起こして**変換しています。同梱の`bert_ner_mlx.py`が必要です。構造自体は
36
  標準的なpost-norm BERTエンコーダー + 線形分類ヘッドとシンプルです。
37
 
38
+ ## Usage / 使い方
39
 
40
  ```python
41
  import mlx.core as mx
 
62
  print(tok, model.config.id2label[label_id] if hasattr(model, "config") else label_id)
63
  ```
64
 
65
+ Labels are the same as the original model: `{0: "O", 1: "B-MISC", 2: "I-MISC",
66
+ 3: "B-PER", 4: "I-PER", 5: "B-ORG", 6: "I-ORG", 7: "B-LOC", 8: "I-LOC"}`.
67
+
68
  ラベルは元モデルと同じ: `{0: "O", 1: "B-MISC", 2: "I-MISC", 3: "B-PER", 4: "I-PER",
69
  5: "B-ORG", 6: "I-ORG", 7: "B-LOC", 8: "I-LOC"}`。
70
 
71
+ ## Accuracy / 精度検証
72
+
73
+ Compared against the PyTorch fp32 reference on a real sentence containing
74
+ person/location/organization entities:
75
 
76
  PyTorch fp32リファレンスと、実際の文章1件(人名・地名・組織名を含む)で比較:
77
 
78
+ | Precision / 精度 | Logits cosine sim. | Label agreement |
79
  |---|---|---|
80
  | MLX fp32 | 1.0 | 100% |
81
+ | MLX fp16 (this release) | 0.99999994 | 100% |
82
+
83
+ During fp16 conversion, using an attention-mask value like `-1e9` (which
84
+ doesn't fit in fp16) caused `0 * (-inf) = NaN` at unmasked (`mask=1`)
85
+ positions. Fixed by switching to `-1e4`, which fits fp16's range (full
86
+ details are in the conversion-toolkit repo, not `SECURITY.md`).
87
 
88
  fp16変換の際、attention maskのマスク値に`-1e9`のようなfp16で表現できない大きな負数を使うと、
89
  マスクされていない(`mask=1`)位置で`0 * (-inf)`が発生してNaNになる罠があった。
 
94
 
95
  | Item | Value |
96
  |---|---|
97
+ | Base model | `dslim/bert-base-NER` (BERT-base, 108M params) |
98
  | Precision | float16 |
99
+ | Framework | MLX (from-scratch `bert_ner_mlx.py`) |
100
 
101
  ## Notes
102
 
103
  - This is a community conversion, not an official release from the original author.
104
  - 本変換は非公式のコミュニティ版です。
105
+ - Security audit uses [model-audit-lite](https://github.com/masahirocom/model-audit-lite)
106
+ (see `SECURITY.md` for details).