oliverzh2000 commited on
Commit
6c4f0af
·
verified ·
1 Parent(s): 88aa168

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +41 -19
README.md CHANGED
@@ -31,7 +31,7 @@ Chinese Word Segmentation model using span scoring.
31
 
32
  - **Architecture:** ELECTRA-base (12 layers, 768 hidden, 12 heads) + span scoring MLP head
33
  - **Base model:** [hfl/chinese-electra-180g-base-discriminator](https://huggingface.co/hfl/chinese-electra-180g-base-discriminator)
34
- - **Parameters:** ~110M (encoder) + span head
35
  - **Task:** Given a sentence, score candidate word spans to find optimal segmentation
36
  - **Eval:** 90/97 perfect segmentation on hand-curated test set (93/97 including acceptable over-splits)
37
 
@@ -48,44 +48,66 @@ Smaller/faster variant of the above for lower-end devices.
48
 
49
  Word Sense Disambiguation bi-encoder for selecting the correct dictionary definition in context.
50
 
51
- - **Architecture:** BERT-base fine-tuned as a bi-encoder (SentenceTransformers)
52
- - **Base model:** [thenlper/gte-base-zh](https://huggingface.co/thenlper/gte-base-zh) (GTE Chinese base)
53
- - **Parameters:** ~110M
54
  - **Task:** Encode context sentence and candidate sense labels, rank by cosine similarity
55
  - **Eval:** Top-1 accuracy 88.7%, Top-3 99.6%, MRR 0.936 on 239 hand-curated disambiguation examples
56
 
57
  ## Usage
58
 
59
- These models are used by the Wen Reader iOS app via CoreML conversion. To export to CoreML:
 
 
60
 
61
  ```bash
62
  cd ml
 
 
 
 
 
63
  uv run python scripts/export_coreml.py span --model-dir models/cws_span_scorer_electra_base/final
64
  uv run python scripts/export_coreml.py wsd --model-dir models/wsd_biencoder_gte_base/final
 
 
 
 
 
 
 
 
 
 
 
65
  ```
66
 
67
  ## Training
68
 
69
  ### CWS Span Scorer
70
 
71
- Fine-tuned on a custom dataset (~914k span-scoring examples from ~104k sentences) built from:
72
- - [ICWB2](https://github.com/yuikns/icwb2-data) segmentation corpus (MSR, auto-matched and LLM-annotated disagreements)
73
- - LLM-annotated Chinese from ebooks (Claude Sonnet)
74
- - LLM-annotated wiki/subtitle data (Claude Opus)
75
 
76
- The model scores all candidate word spans at each position using a span scoring MLP head
77
- (taking span boundary representations + width embeddings as input). A dynamic programming decoder
78
- finds the optimal segmentation at inference time. Training uses cross-entropy loss over candidate
79
- spans at each ambiguous position. Encoder and head use discriminative learning rates.
 
 
80
 
81
  ### WSD Bi-encoder
82
 
83
- Fine-tuned on CC-CEDICT sense clusters built from:
84
- - [MiCLS](https://huggingface.co/datasets/wyy209/MiCLS) WSD corpus
85
- - Chinese sense labels generated by LLM translation of English CEDICT definitions
86
- - Context examples generated by LLM for each sense cluster
 
 
 
87
 
88
  Training uses grouped cross-entropy loss: contexts and sense labels are encoded by the same model,
89
  cosine similarity is computed between context embeddings and sense embeddings, and the loss is
90
- cross-entropy over the similarity scores (with temperature scaling). Contexts are grouped by word
91
- in each batch so sense embeddings are encoded once and reused across all contexts for that word.
 
31
 
32
  - **Architecture:** ELECTRA-base (12 layers, 768 hidden, 12 heads) + span scoring MLP head
33
  - **Base model:** [hfl/chinese-electra-180g-base-discriminator](https://huggingface.co/hfl/chinese-electra-180g-base-discriminator)
34
+ - **Parameters:** ~102M (encoder) + span head
35
  - **Task:** Given a sentence, score candidate word spans to find optimal segmentation
36
  - **Eval:** 90/97 perfect segmentation on hand-curated test set (93/97 including acceptable over-splits)
37
 
 
48
 
49
  Word Sense Disambiguation bi-encoder for selecting the correct dictionary definition in context.
50
 
51
+ - **Architecture:** GTE-base-zh fine-tuned as a bi-encoder (SentenceTransformers)
52
+ - **Base model:** [thenlper/gte-base-zh](https://huggingface.co/thenlper/gte-base-zh)
53
+ - **Parameters:** ~102M
54
  - **Task:** Encode context sentence and candidate sense labels, rank by cosine similarity
55
  - **Eval:** Top-1 accuracy 88.7%, Top-3 99.6%, MRR 0.936 on 239 hand-curated disambiguation examples
56
 
57
  ## Usage
58
 
59
+ These models are used by the Wen Reader iOS app via CoreML conversion.
60
+
61
+ To build the app from a fresh clone:
62
 
63
  ```bash
64
  cd ml
65
+
66
+ # 1. Download model weights from HF Hub
67
+ uv run python scripts/download_models.py
68
+
69
+ # 2. Export to CoreML
70
  uv run python scripts/export_coreml.py span --model-dir models/cws_span_scorer_electra_base/final
71
  uv run python scripts/export_coreml.py wsd --model-dir models/wsd_biencoder_gte_base/final
72
+
73
+ # 3. Bundle into app resources (vocab, CoreML packages, CEDICT database)
74
+ ./scripts/run_pipeline.sh bundle
75
+ ```
76
+
77
+ Or use the pipeline script:
78
+
79
+ ```bash
80
+ ./scripts/run_pipeline.sh download
81
+ ./scripts/run_pipeline.sh export
82
+ ./scripts/run_pipeline.sh bundle
83
  ```
84
 
85
  ## Training
86
 
87
  ### CWS Span Scorer
88
 
89
+ Fine-tuned on a custom dataset built from:
90
+ - [ICWB2](https://github.com/yuikns/icwb2-data) segmentation corpus (MSR, auto-matched where greedy segmenter agrees with gold, plus LLM-annotated disagreement cases)
91
+ - Chinese [Wikipedia](https://huggingface.co/datasets/wikimedia/wikipedia) and [OpenSubtitles](https://huggingface.co/datasets/FradSer/OpenSubtitles-en-zh-cn-20m) sentences, LLM-annotated (Claude Opus)
 
92
 
93
+ Sentences with ambiguous segmentation boundaries (where multiple valid CEDICT words overlap) are
94
+ identified, then an LLM annotates the correct segmentation. The model scores all candidate word
95
+ spans at each ambiguous position using a span scoring MLP head (taking span boundary token
96
+ representations + learned width embeddings as input). A dynamic programming decoder finds the
97
+ optimal segmentation at inference time. Training uses cross-entropy loss over candidate spans at
98
+ each ambiguous position. Encoder and head use discriminative learning rates.
99
 
100
  ### WSD Bi-encoder
101
 
102
+ Fine-tuned on CC-CEDICT sense clusters with data from:
103
+ - [MiCLS](https://huggingface.co/datasets/wyy209/MiCLS) WSD corpus (mapped to CEDICT senses via BGE embedding similarity)
104
+ - LLM-generated context examples for each sense cluster (Claude Opus and Sonnet)
105
+ - LLM-annotated ebook sentences segmented by the CWS span scorer (Claude Sonnet)
106
+
107
+ Sense clusters are derived from CC-CEDICT entries with related senses merged using LLM-assisted
108
+ clustering. Chinese sense labels are LLM-translated from the English CEDICT definitions.
109
 
110
  Training uses grouped cross-entropy loss: contexts and sense labels are encoded by the same model,
111
  cosine similarity is computed between context embeddings and sense embeddings, and the loss is
112
+ cross-entropy over the similarity scores (with temperature scaling at τ=0.1). Contexts are grouped
113
+ by word in each batch so sense embeddings are encoded once and reused across all contexts for that word.