Salama1429 commited on
Commit
500aec4
·
verified ·
1 Parent(s): d474128

Upload folder using huggingface_hub

Browse files
Files changed (8) hide show
  1. .gitattributes +3 -1
  2. README.md +967 -0
  3. config.yaml +35 -0
  4. model.onnx +3 -0
  5. pcs47_1jun.nemo +3 -0
  6. pipeline.py +21 -0
  7. requirements.txt +1 -0
  8. sp.model +3 -0
.gitattributes CHANGED
@@ -25,7 +25,6 @@
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
  *.tflite filter=lfs diff=lfs merge=lfs -text
30
  *.tgz filter=lfs diff=lfs merge=lfs -text
31
  *.wasm filter=lfs diff=lfs merge=lfs -text
@@ -33,3 +32,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
 
28
  *.tflite filter=lfs diff=lfs merge=lfs -text
29
  *.tgz filter=lfs diff=lfs merge=lfs -text
30
  *.wasm filter=lfs diff=lfs merge=lfs -text
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ pcs47_12may.nemo filter=lfs diff=lfs merge=lfs -text
36
+ pcs47_12may.tar filter=lfs diff=lfs merge=lfs -text
37
+ pcs47_1jun.nemo filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,967 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: generic
4
+ tags:
5
+ - text2text-generation
6
+ - punctuation
7
+ - sentence-boundary-detection
8
+ - truecasing
9
+ - true-casing
10
+ language:
11
+ - af
12
+ - am
13
+ - ar
14
+ - bg
15
+ - bn
16
+ - de
17
+ - el
18
+ - en
19
+ - es
20
+ - et
21
+ - fa
22
+ - fi
23
+ - fr
24
+ - gu
25
+ - hi
26
+ - hr
27
+ - hu
28
+ - id
29
+ - is
30
+ - it
31
+ - ja
32
+ - kk
33
+ - kn
34
+ - ko
35
+ - ky
36
+ - lt
37
+ - lv
38
+ - mk
39
+ - ml
40
+ - mr
41
+ - nl
42
+ - or
43
+ - pa
44
+ - pl
45
+ - ps
46
+ - pt
47
+ - ro
48
+ - ru
49
+ - rw
50
+ - so
51
+ - sr
52
+ - sw
53
+ - ta
54
+ - te
55
+ - tr
56
+ - uk
57
+ - zh
58
+ widget:
59
+ - text: "hola amigo cómo estás es un día lluvioso hoy"
60
+ - text: "please rsvp for the party asap preferably before 8 pm tonight"
61
+ - text: "este modelo fue entrenado en un gpu a100 en realidad no se que dice esta frase lo traduje con nmt"
62
+ - text: "此模型向文本添加标点符号它支持47种语言并在a100gpu上接受过训练它可以在每种语言上运行而无需每种语言的特殊路径"
63
+ - text: "यह मॉडल 47 भाषाओं में विराम चिह्न जोड़ता है यह भाषा विशिष्ट पथ के बिना काम करता है यह प्रत्येक भाषा के लिए विशेष पथों के बिना प्रत्येक भाषा पर कार्य कर सकता है"
64
+ ---
65
+
66
+ # Model Overview
67
+ This is an `xlm-roberta` fine-tuned to restore punctuation, true-case (capitalize),
68
+ and detect sentence boundaries (full stops) in 47 languages.
69
+
70
+ # Usage
71
+
72
+ If you want to just play with the model, the widget on this page will suffice. To use the model offline,
73
+ the following snippets show how to use the model both with a wrapper (that I wrote, available from `PyPI`)
74
+ and manual usuage (using the ONNX and SentencePiece models in this repo).
75
+
76
+ ## Usage via `punctuators` package
77
+
78
+
79
+ <details>
80
+
81
+ <summary>Click to see usage with wrappers</summary>
82
+
83
+ The easiest way to use this model is to install [punctuators](https://github.com/1-800-BAD-CODE/punctuators):
84
+
85
+ ```bash
86
+ $ pip install punctuators
87
+ ```
88
+
89
+ But this is just an ONNX and SentencePiece model, so you may run it as you wish.
90
+
91
+ The input to the `punctuators` API is a list (batch) of strings.
92
+ Each string will be punctuated, true-cased, and segmented on predicted full stops.
93
+ The output will therefore be a list of list of strings: one list of segmented sentences per input text.
94
+ To disable full stops, use `m.infer(texts, apply_sbd=False)`.
95
+ The output will then be a list of strings: one punctuated, true-cased string per input text.
96
+
97
+ <details open>
98
+
99
+ <summary>Example Usage</summary>
100
+
101
+ ```python
102
+
103
+ from typing import List
104
+
105
+ from punctuators.models import PunctCapSegModelONNX
106
+
107
+ m: PunctCapSegModelONNX = PunctCapSegModelONNX.from_pretrained(
108
+ "1-800-BAD-CODE/xlm-roberta_punctuation_fullstop_truecase"
109
+ )
110
+
111
+ input_texts: List[str] = [
112
+ "hola mundo cómo estás estamos bajo el sol y hace mucho calor santa coloma abre los huertos urbanos a las escuelas de la ciudad",
113
+ "hello friend how's it going it's snowing outside right now in connecticut a large storm is moving in",
114
+ "未來疫苗將有望覆蓋3歲以上全年齡段美國與北約軍隊已全部撤離還有鐵路公路在內的各項基建的來源都將枯竭",
115
+ "በባለፈው ሳምንት ኢትዮጵያ ከሶማሊያ 3 ሺህ ወታደሮቿንም እንዳስወጣች የሶማሊያው ዳልሳን ሬድዮ ዘግቦ ነበር ጸጥታ ሃይሉና ህዝቡ ተቀናጅቶ በመስራቱ በመዲናዋ ላይ የታቀደው የጥፋት ሴራ ከሽፏል",
116
+ "こんにちは友人" "調子はどう" "今日は雨の日でしたね" "乾いた状態を保つために一日中室内で過ごしました",
117
+ "hallo freund wie geht's es war heute ein regnerischer tag nicht wahr ich verbrachte den tag drinnen um trocken zu bleiben",
118
+ "हैलो दोस्त ये कैसा चल रहा है आज बारिश का दिन था न मैंने सूखा रहने के लिए दिन घर के अंदर बिताया",
119
+ "كيف تجري الامور كان يومًا ممطرًا اليوم أليس كذلك قضيت اليوم في الداخل لأظل جافًا",
120
+ ]
121
+
122
+ results: List[List[str]] = m.infer(
123
+ texts=input_texts, apply_sbd=True,
124
+ )
125
+ for input_text, output_texts in zip(input_texts, results):
126
+ print(f"Input: {input_text}")
127
+ print(f"Outputs:")
128
+ for text in output_texts:
129
+ print(f"\t{text}")
130
+ print()
131
+
132
+ ```
133
+
134
+ </details>
135
+
136
+
137
+ <details open>
138
+
139
+ <summary>Expected output</summary>
140
+
141
+ ```text
142
+ Input: hola mundo cómo estás estamos bajo el sol y hace mucho calor santa coloma abre los huertos urbanos a las escuelas de la ciudad
143
+ Outputs:
144
+ Hola mundo, ¿cómo estás?
145
+ Estamos bajo el sol y hace mucho calor.
146
+ Santa Coloma abre los huertos urbanos a las escuelas de la ciudad.
147
+
148
+ Input: hello friend how's it going it's snowing outside right now in connecticut a large storm is moving in
149
+ Outputs:
150
+ Hello friend, how's it going?
151
+ It's snowing outside right now.
152
+ In Connecticut, a large storm is moving in.
153
+
154
+ Input: 未來疫苗將有望覆蓋3歲以上全年齡段美國與北約軍隊已全部撤離還有鐵路公路在內的各項基建的來源都將枯竭
155
+ Outputs:
156
+ 未來,疫苗將有望覆蓋3歲以上全年齡段。
157
+ 美國與北約軍隊已全部撤離。
158
+ 還有,鐵路,公路在內的各項基建的來源都將枯竭。
159
+
160
+ Input: በባለፈው ሳምንት ኢትዮጵያ ከሶማሊያ 3 ሺህ ወታደሮቿንም እንዳስወጣች የሶማሊያው ዳልሳን ሬድዮ ዘግቦ ነበር ጸጥታ ሃይሉና ህዝቡ ተቀናጅቶ በመስራቱ በመዲናዋ ላይ የታቀደው የጥፋት ሴራ ከሽፏል
161
+ Outputs:
162
+ በባለፈው ሳምንት ኢትዮጵያ ከሶማሊያ 3 ሺህ ወታደሮቿንም እንዳስወጣች የሶማሊያው ዳልሳን ሬድዮ ዘግቦ ነበር።
163
+ ጸጥታ ሃይሉና ህዝቡ ተቀናጅቶ በመስራቱ በመዲናዋ ላይ የታቀደው የጥፋት ሴራ ከሽፏል።
164
+
165
+ Input: こんにちは友人調子はどう今日は雨の日でしたね乾いた状態を保つために一日中室内で過ごしました
166
+ Outputs:
167
+ こんにちは、友人、調子はどう?
168
+ 今日は雨の日でしたね。
169
+ 乾いた状態を保つために、一日中、室内で過ごしました。
170
+
171
+ Input: hallo freund wie geht's es war heute ein regnerischer tag nicht wahr ich verbrachte den tag drinnen um trocken zu bleiben
172
+ Outputs:
173
+ Hallo Freund, wie geht's?
174
+ Es war heute ein regnerischer Tag, nicht wahr?
175
+ Ich verbrachte den Tag drinnen, um trocken zu bleiben.
176
+
177
+ Input: हैलो दोस्त ये कैसा चल रहा है आज बारिश का दिन था न मैंने सूखा रहने के लिए दिन घर के अंदर बिताया
178
+ Outputs:
179
+ हैलो दोस्त, ये कैसा चल रहा है?
180
+ आज बारिश का दिन था न, मैंने सूखा रहने के लिए दिन घर के अंदर बिताया।
181
+
182
+ Input: كيف تجري الامور كان يومًا ممطرًا اليوم أليس كذلك قضيت اليوم في الداخل لأظل جافًا
183
+ Outputs:
184
+ كيف تجري الامور؟
185
+ كان يومًا ممطرًا اليوم، أليس كذلك؟
186
+ قضيت اليوم في الداخل لأظل جافًا.
187
+
188
+ ```
189
+
190
+ </details>
191
+
192
+ </details>
193
+
194
+ ## Manual Usage
195
+ If you want to use the ONNX and SP models without wrappers, see the following example.
196
+
197
+ <details>
198
+
199
+ <summary>Click to see manual usage</summary>
200
+
201
+
202
+ ```python
203
+ from typing import List
204
+
205
+ import numpy as np
206
+ import onnxruntime as ort
207
+ from huggingface_hub import hf_hub_download
208
+ from omegaconf import OmegaConf
209
+ from sentencepiece import SentencePieceProcessor
210
+
211
+ # Download the models from HF hub. Note: to clean up, you can find these files in your HF cache directory
212
+ spe_path = hf_hub_download(repo_id="1-800-BAD-CODE/xlm-roberta_punctuation_fullstop_truecase", filename="sp.model")
213
+ onnx_path = hf_hub_download(repo_id="1-800-BAD-CODE/xlm-roberta_punctuation_fullstop_truecase", filename="model.onnx")
214
+ config_path = hf_hub_download(
215
+ repo_id="1-800-BAD-CODE/xlm-roberta_punctuation_fullstop_truecase", filename="config.yaml"
216
+ )
217
+
218
+ # Load the SP model
219
+ tokenizer: SentencePieceProcessor = SentencePieceProcessor(spe_path) # noqa
220
+ # Load the ONNX graph
221
+ ort_session: ort.InferenceSession = ort.InferenceSession(onnx_path)
222
+ # Load the model config with labels, etc.
223
+ config = OmegaConf.load(config_path)
224
+ # Potential classification labels before each subtoken
225
+ pre_labels: List[str] = config.pre_labels
226
+ # Potential classification labels after each subtoken
227
+ post_labels: List[str] = config.post_labels
228
+ # Special class that means "predict nothing"
229
+ null_token = config.get("null_token", "<NULL>")
230
+ # Special class that means "all chars in this subtoken end with a period", e.g., "am" -> "a.m."
231
+ acronym_token = config.get("acronym_token", "<ACRONYM>")
232
+ # Not used in this example, but if your sequence exceed this value, you need to fold it over multiple inputs
233
+ max_len = config.max_length
234
+ # For reference only, graph has no language-specific behavior
235
+ languages: List[str] = config.languages
236
+
237
+ # Encode some input text, adding BOS + EOS
238
+ input_text = "hola mundo cómo estás estamos bajo el sol y hace mucho calor santa coloma abre los huertos urbanos a las escuelas de la ciudad"
239
+ input_ids = [tokenizer.bos_id()] + tokenizer.EncodeAsIds(input_text) + [tokenizer.eos_id()]
240
+
241
+ # Create a numpy array with shape [B, T], as the graph expects as input.
242
+ # Note that we do not pass lengths to the graph; if you are using a batch, padding should be tokenizer.pad_id() and the
243
+ # graph's attention mechanisms will ignore pad_id() without requiring explicit sequence lengths.
244
+ input_ids_arr: np.array = np.array([input_ids])
245
+
246
+ # Run the graph, get outputs for all analytics
247
+ pre_preds, post_preds, cap_preds, sbd_preds = ort_session.run(None, {"input_ids": input_ids_arr})
248
+ # Squeeze off the batch dimensions and convert to lists
249
+ pre_preds = pre_preds[0].tolist()
250
+ post_preds = post_preds[0].tolist()
251
+ cap_preds = cap_preds[0].tolist()
252
+ sbd_preds = sbd_preds[0].tolist()
253
+
254
+ # Segmented sentences
255
+ output_texts: List[str] = []
256
+ # Current sentence, which is built until we hit a sentence boundary prediction
257
+ current_chars: List[str] = []
258
+ # Iterate over the outputs, ignoring the first (BOS) and final (EOS) predictions and tokens
259
+ for token_idx in range(1, len(input_ids) - 1):
260
+ token = tokenizer.IdToPiece(input_ids[token_idx])
261
+ # Simple SP decoding
262
+ if token.startswith("▁") and current_chars:
263
+ current_chars.append(" ")
264
+ # Token-level predictions
265
+ pre_label = pre_labels[pre_preds[token_idx]]
266
+ post_label = post_labels[post_preds[token_idx]]
267
+ # If we predict "pre-punct", insert it before this token
268
+ if pre_label != null_token:
269
+ current_chars.append(pre_label)
270
+ # Iterate over each char. Skip SP's space token,
271
+ char_start = 1 if token.startswith("▁") else 0
272
+ for token_char_idx, char in enumerate(token[char_start:], start=char_start):
273
+ # If this char should be capitalized, apply upper case
274
+ if cap_preds[token_idx][token_char_idx]:
275
+ char = char.upper()
276
+ # Append char
277
+ current_chars.append(char)
278
+ # if this is an acronym, add a period after every char (p.m., a.m., etc.)
279
+ if post_label == acronym_token:
280
+ current_chars.append(".")
281
+ # Maybe this subtoken ends with punctuation
282
+ if post_label != null_token and post_label != acronym_token:
283
+ current_chars.append(post_label)
284
+
285
+ # If this token is a sentence boundary, finalize the current sentence and reset
286
+ if sbd_preds[token_idx]:
287
+ output_texts.append("".join(current_chars))
288
+ current_chars.clear()
289
+
290
+ # Maybe push final sentence, if the final token was not classified as a sentence boundary
291
+ if current_chars:
292
+ output_texts.append("".join(current_chars))
293
+
294
+ # Pretty print
295
+ print(f"Input: {input_text}")
296
+ print("Outputs:")
297
+ for text in output_texts:
298
+ print(f"\t{text}")
299
+
300
+ ```
301
+
302
+ Expected output:
303
+
304
+ ```text
305
+ Input: hola mundo cómo estás estamos bajo el sol y hace mucho calor santa coloma abre los huertos urbanos a las escuelas de la ciudad
306
+ Outputs:
307
+ Hola mundo, ¿cómo estás?
308
+ Estamos bajo el sol y hace mucho calor.
309
+ Santa Coloma abre los huertos urbanos a las escuelas de la ciudad.
310
+ ```
311
+
312
+ </details>
313
+
314
+ &nbsp;
315
+
316
+
317
+ # Model Architecture
318
+
319
+ This model implements the following graph, which allows punctuation, true-casing, and fullstop prediction
320
+ in every language without language-specific behavior:
321
+
322
+ ![graph.png](https://cdn-uploads.huggingface.co/production/uploads/62d34c813eebd640a4f97587/WJ8aWIM4A--xzYu8FR4ht.png)
323
+
324
+ <details>
325
+
326
+ <summary>Click to see graph explanations</summary>
327
+
328
+ We start by tokenizing the text and encoding it with XLM-Roberta, which is the pre-trained portion of this graph.
329
+
330
+ Then we predict punctuation before and after every subtoken.
331
+ Predicting before each token allows for Spanish inverted question marks.
332
+ Predicting after every token allows for all other punctuation, including punctuation within continuous-script
333
+ languages and acronyms.
334
+
335
+ We use embeddings to represent the predicted punctuation tokens to inform the sentence boundary head of the
336
+ punctuation that'll be inserted into the text. This allows proper full stop prediction, since certain punctuation
337
+ tokens (periods, questions marks, etc.) are strongly correlated with sentence boundaries.
338
+
339
+ We then shift full stop predictions to the right by one, to inform the true-casing head of where the beginning
340
+ of each new sentence is. This is important since true-casing is strongly correlated to sentence boundaries.
341
+
342
+ For true-casing, we predict `N` predictions per subtoken, where `N` is the number of characters in the subtoken.
343
+ In practice, `N` is the maximum subtoken length and extra predictions are ignored. Essentially, true-casing is
344
+ modeled as a multi-label problem. This allows for upper-casing arbitrary characters, e.g., "NATO", "MacDonald", "mRNA", etc.
345
+
346
+ Applying all these predictions to the input text, we can punctuate, true-case, and split sentences in any language.
347
+
348
+ </details>
349
+
350
+ ## Tokenizer
351
+
352
+ <details>
353
+
354
+ <summary>Click to see how the XLM-Roberta tokenizer was un-hacked</summary>
355
+
356
+ Instead of the hacky wrapper used by FairSeq and strangely ported (not fixed) by HuggingFace, the `xlm-roberta` SentencePiece model was adjusted to correctly encode
357
+ the text. Per HF's comments,
358
+
359
+ ```python
360
+ # Original fairseq vocab and spm vocab must be "aligned":
361
+ # Vocab | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
362
+ # -------- | ------- | ------- | ------ | ------- | --- | --- | --- | ----- | ----- | ----
363
+ # fairseq | '<s>' | '<pad>' | '</s>' | '<unk>' | ',' | '.' | '▁' | 's' | '▁de' | '-'
364
+ # spm | '<unk>' | '<s>' | '</s>' | ',' | '.' | '▁' | 's' | '▁de' | '-' | '▁a'
365
+ ```
366
+
367
+ The SP model was un-hacked with the following snippet
368
+ (SentencePiece experts, let me know if there is a problem here):
369
+
370
+ ```python
371
+ from sentencepiece import SentencePieceProcessor
372
+ from sentencepiece.sentencepiece_model_pb2 import ModelProto
373
+
374
+ m = ModelProto()
375
+ m.ParseFromString(open("/path/to/xlmroberta/sentencepiece.bpe.model", "rb").read())
376
+
377
+ pieces = list(m.pieces)
378
+ pieces = (
379
+ [
380
+ ModelProto.SentencePiece(piece="<s>", type=ModelProto.SentencePiece.Type.CONTROL),
381
+ ModelProto.SentencePiece(piece="<pad>", type=ModelProto.SentencePiece.Type.CONTROL),
382
+ ModelProto.SentencePiece(piece="</s>", type=ModelProto.SentencePiece.Type.CONTROL),
383
+ ModelProto.SentencePiece(piece="<unk>", type=ModelProto.SentencePiece.Type.UNKNOWN),
384
+ ]
385
+ + pieces[3:]
386
+ + [ModelProto.SentencePiece(piece="<mask>", type=ModelProto.SentencePiece.Type.USER_DEFINED)]
387
+ )
388
+ del m.pieces[:]
389
+ m.pieces.extend(pieces)
390
+
391
+ with open("/path/to/new/sp.model", "wb") as f:
392
+ f.write(m.SerializeToString())
393
+ ```
394
+
395
+ Now we can use just the SP model without a wrapper.
396
+
397
+ </details>
398
+
399
+ ## Post-Punctuation Tokens
400
+ This model predicts the following set of punctuation tokens after each subtoken:
401
+
402
+ | Token | Description | Relevant Languages |
403
+ | ---: | :---------- | :----------- |
404
+ | \<NULL\> | No punctuation | All |
405
+ | \<ACRONYM\> | Every character in this subword is followed by a period | Primarily English, some European |
406
+ | . | Latin full stop | Many |
407
+ | , | Latin comma | Many |
408
+ | ? | Latin question mark | Many |
409
+ | ? | Full-width question mark | Chinese, Japanese |
410
+ | , | Full-width comma | Chinese, Japanese |
411
+ | 。 | Full-width full stop | Chinese, Japanese |
412
+ | 、 | Ideographic comma | Chinese, Japanese |
413
+ | ・ | Middle dot | Japanese |
414
+ | । | Danda | Hindi, Bengali, Oriya |
415
+ | ؟ | Arabic question mark | Arabic |
416
+ | ; | Greek question mark | Greek |
417
+ | ። | Ethiopic full stop | Amharic |
418
+ | ፣ | Ethiopic comma | Amharic |
419
+ | ፧ | Ethiopic question mark | Amharic |
420
+
421
+
422
+ ## Pre-Punctuation Tokens
423
+ This model predicts the following set of punctuation tokens before each subword:
424
+
425
+ | Token | Description | Relevant Languages |
426
+ | ---: | :---------- | :----------- |
427
+ | \<NULL\> | No punctuation | All |
428
+ | ¿ | Inverted question mark | Spanish |
429
+
430
+
431
+
432
+ # Training Details
433
+ This model was trained in the NeMo framework on an A100 for approximately 7 hours.
434
+ You may view the `tensorboard` log on [tensorboard.dev](https://tensorboard.dev/experiment/xxnULI1aTeK37vUDL4ejiw/#scalars).
435
+
436
+ This model was trained with News Crawl data from WMT.
437
+ 1M lines of text for each language was used, except for a few low-resource languages which may have used less.
438
+ Languages were chosen based on whether the News Crawl corpus contained enough reliable-quality data as judged by the author.
439
+
440
+ # Limitations
441
+
442
+ This model was trained on news data, and may not perform well on conversational or informal data.
443
+
444
+ This model is unlikely to be of production quality.
445
+ It was trained with "only" 1M lines per language, and the dev sets may have been noisy due to the nature of web-scraped news data.
446
+
447
+ This model over-predicts Spanish question marks, especially the inverted question mark `¿` (see metrics below).
448
+ Since `¿` is a rare token, especially in the context of a 47-language model, Spanish questions were over-sampled
449
+ by selecting more of these sentences from additional training data that was not used. However, this seems to have
450
+ "over-corrected" the problem and a lot of Spanish question marks are predicted.
451
+
452
+ The model may also over-predict commas.
453
+
454
+ If you find any general limitations not mentioned here, let me know so all limitations can be addressed in the
455
+ next fine-tuning.
456
+
457
+ # Evaluation
458
+ In these metrics, keep in mind that
459
+ 1. The data is noisy
460
+ 2. Sentence boundaries and true-casing are conditioned on predicted punctuation, which is the most difficult task and sometimes incorrect.
461
+ When conditioning on reference punctuation, true-casing and SBD is practically 100% for most languages.
462
+ 4. Punctuation can be subjective. E.g.,
463
+
464
+ `Hola mundo, ¿cómo estás?`
465
+
466
+ or
467
+
468
+ `Hola mundo. ¿Cómo estás?`
469
+
470
+ When the sentences are longer and more practical, these ambiguities abound and affect all 3 analytics.
471
+
472
+ ## Test Data and Example Generation
473
+ Each test example was generated using the following procedure:
474
+
475
+ 1. Concatenate 11 random sentences (1 + 10 for each sentence in the test set)
476
+ 2. Lower-case the concatenated sentence
477
+ 3. Remove all punctuation
478
+
479
+ Targets are generated as we lower-case letters and remove punctuation.
480
+
481
+ The data is a held-out portion of News Crawl, which has been deduplicated.
482
+ 3,000 lines of data per language was used, generating 3,000 unique examples of 11 sentences each.
483
+ We generate 3,000 examples, where example `i` begins with sentence `i` and is followed by 10 random
484
+ sentences selected from the 3,000 sentence test set.
485
+
486
+ For measuring true-casing and sentence boundary detection, reference punctuation tokens were used for
487
+ conditioning (see graph above). If we use predicted punctuation instead, then incorrect punctuation will
488
+ result in true-casing and SBD targets not aligning correctly and these metrics will be artificially low.
489
+
490
+ ## Selected Language Evaluation Reports
491
+ For now, metrics for a few selected languages are shown below.
492
+ Given the amount of work required to collect and pretty-print metrics in 47 languages, I'll add more eventually.
493
+
494
+ Expand any of the following tabs to see metrics for that language.
495
+
496
+
497
+ <details>
498
+ <summary>English</summary>
499
+
500
+ ```text
501
+ punct_post test report:
502
+ label precision recall f1 support
503
+ <NULL> (label_id: 0) 99.25 98.43 98.84 564908
504
+ <ACRONYM> (label_id: 1) 63.14 84.67 72.33 613
505
+ . (label_id: 2) 90.97 93.91 92.42 32040
506
+ , (label_id: 3) 73.95 84.32 78.79 24271
507
+ ? (label_id: 4) 79.05 81.94 80.47 1041
508
+ ? (label_id: 5) 0.00 0.00 0.00 0
509
+ , (label_id: 6) 0.00 0.00 0.00 0
510
+ 。 (label_id: 7) 0.00 0.00 0.00 0
511
+ 、 (label_id: 8) 0.00 0.00 0.00 0
512
+ ・ (label_id: 9) 0.00 0.00 0.00 0
513
+ । (label_id: 10) 0.00 0.00 0.00 0
514
+ ؟ (label_id: 11) 0.00 0.00 0.00 0
515
+ ، (label_id: 12) 0.00 0.00 0.00 0
516
+ ; (label_id: 13) 0.00 0.00 0.00 0
517
+ ። (label_id: 14) 0.00 0.00 0.00 0
518
+ ፣ (label_id: 15) 0.00 0.00 0.00 0
519
+ ፧ (label_id: 16) 0.00 0.00 0.00 0
520
+ -------------------
521
+ micro avg 97.60 97.60 97.60 622873
522
+ macro avg 81.27 88.65 84.57 622873
523
+ weighted avg 97.77 97.60 97.67 622873
524
+ ```
525
+
526
+ ```
527
+ cap test report:
528
+ label precision recall f1 support
529
+ LOWER (label_id: 0) 99.72 99.85 99.78 2134956
530
+ UPPER (label_id: 1) 96.33 93.52 94.91 91996
531
+ -------------------
532
+ micro avg 99.59 99.59 99.59 2226952
533
+ macro avg 98.03 96.68 97.34 2226952
534
+ weighted avg 99.58 99.59 99.58 2226952
535
+ ```
536
+
537
+ ```
538
+ seg test report:
539
+ label precision recall f1 support
540
+ NOSTOP (label_id: 0) 99.99 99.98 99.99 591540
541
+ FULLSTOP (label_id: 1) 99.61 99.89 99.75 34333
542
+ -------------------
543
+ micro avg 99.97 99.97 99.97 625873
544
+ macro avg 99.80 99.93 99.87 625873
545
+ weighted avg 99.97 99.97 99.97 625873
546
+ ```
547
+
548
+ </details>
549
+
550
+
551
+
552
+ <details>
553
+ <summary>Spanish</summary>
554
+
555
+ ```text
556
+ punct_pre test report:
557
+ label precision recall f1 support
558
+ <NULL> (label_id: 0) 99.94 99.89 99.92 636941
559
+ ¿ (label_id: 1) 56.73 71.35 63.20 1288
560
+ -------------------
561
+ micro avg 99.83 99.83 99.83 638229
562
+ macro avg 78.34 85.62 81.56 638229
563
+ weighted avg 99.85 99.83 99.84 638229
564
+ ```
565
+
566
+ ```
567
+ punct_post test report:
568
+ label precision recall f1 support
569
+ <NULL> (label_id: 0) 99.19 98.41 98.80 578271
570
+ <ACRONYM> (label_id: 1) 30.10 56.36 39.24 55
571
+ . (label_id: 2) 91.92 93.12 92.52 30856
572
+ , (label_id: 3) 72.98 82.44 77.42 27761
573
+ ? (label_id: 4) 52.77 71.85 60.85 1286
574
+ ? (label_id: 5) 0.00 0.00 0.00 0
575
+ , (label_id: 6) 0.00 0.00 0.00 0
576
+ 。 (label_id: 7) 0.00 0.00 0.00 0
577
+ 、 (label_id: 8) 0.00 0.00 0.00 0
578
+ ・ (label_id: 9) 0.00 0.00 0.00 0
579
+ । (label_id: 10) 0.00 0.00 0.00 0
580
+ ؟ (label_id: 11) 0.00 0.00 0.00 0
581
+ ، (label_id: 12) 0.00 0.00 0.00 0
582
+ ; (label_id: 13) 0.00 0.00 0.00 0
583
+ ። (label_id: 14) 0.00 0.00 0.00 0
584
+ ፣ (label_id: 15) 0.00 0.00 0.00 0
585
+ ፧ (label_id: 16) 0.00 0.00 0.00 0
586
+ -------------------
587
+ micro avg 97.40 97.40 97.40 638229
588
+ macro avg 69.39 80.44 73.77 638229
589
+ weighted avg 97.60 97.40 97.48 638229
590
+ ```
591
+
592
+ ```
593
+ cap test report:
594
+ label precision recall f1 support
595
+ LOWER (label_id: 0) 99.82 99.86 99.84 2324724
596
+ UPPER (label_id: 1) 95.92 94.70 95.30 79266
597
+ -------------------
598
+ micro avg 99.69 99.69 99.69 2403990
599
+ macro avg 97.87 97.28 97.57 2403990
600
+ weighted avg 99.69 99.69 99.69 2403990
601
+ ```
602
+
603
+ ```
604
+ seg test report:
605
+ label precision recall f1 support
606
+ NOSTOP (label_id: 0) 99.99 99.96 99.98 607057
607
+ FULLSTOP (label_id: 1) 99.31 99.88 99.60 34172
608
+ -------------------
609
+ micro avg 99.96 99.96 99.96 641229
610
+ macro avg 99.65 99.92 99.79 641229
611
+ weighted avg 99.96 99.96 99.96 641229
612
+ ```
613
+
614
+ </details>
615
+
616
+
617
+ <details>
618
+ <summary>Amharic</summary>
619
+
620
+ ```text
621
+ punct_post test report:
622
+ label precision recall f1 support
623
+ <NULL> (label_id: 0) 99.83 99.28 99.56 729664
624
+ <ACRONYM> (label_id: 1) 0.00 0.00 0.00 0
625
+ . (label_id: 2) 0.00 0.00 0.00 0
626
+ , (label_id: 3) 0.00 0.00 0.00 0
627
+ ? (label_id: 4) 0.00 0.00 0.00 0
628
+ ? (label_id: 5) 0.00 0.00 0.00 0
629
+ , (label_id: 6) 0.00 0.00 0.00 0
630
+ 。 (label_id: 7) 0.00 0.00 0.00 0
631
+ 、 (label_id: 8) 0.00 0.00 0.00 0
632
+ ・ (label_id: 9) 0.00 0.00 0.00 0
633
+ । (label_id: 10) 0.00 0.00 0.00 0
634
+ ؟ (label_id: 11) 0.00 0.00 0.00 0
635
+ ، (label_id: 12) 0.00 0.00 0.00 0
636
+ ; (label_id: 13) 0.00 0.00 0.00 0
637
+ ። (label_id: 14) 91.27 97.90 94.47 25341
638
+ ፣ (label_id: 15) 61.93 82.11 70.60 5818
639
+ ፧ (label_id: 16) 67.41 81.73 73.89 1177
640
+ -------------------
641
+ micro avg 99.08 99.08 99.08 762000
642
+ macro avg 80.11 90.26 84.63 762000
643
+ weighted avg 99.21 99.08 99.13 762000
644
+ ```
645
+
646
+ ```
647
+ cap test report:
648
+ label precision recall f1 support
649
+ LOWER (label_id: 0) 98.40 98.03 98.21 1064
650
+ UPPER (label_id: 1) 71.23 75.36 73.24 69
651
+ -------------------
652
+ micro avg 96.65 96.65 96.65 1133
653
+ macro avg 84.81 86.69 85.73 1133
654
+ weighted avg 96.74 96.65 96.69 1133
655
+ ```
656
+
657
+ ```
658
+ seg test report:
659
+ label precision recall f1 support
660
+ NOSTOP (label_id: 0) 99.99 99.85 99.92 743158
661
+ FULLSTOP (label_id: 1) 95.20 99.62 97.36 21842
662
+ -------------------
663
+ micro avg 99.85 99.85 99.85 765000
664
+ macro avg 97.59 99.74 98.64 765000
665
+ weighted avg 99.85 99.85 99.85 765000
666
+ ```
667
+
668
+ </details>
669
+
670
+
671
+ <details>
672
+ <summary>Chinese</summary>
673
+
674
+ ```text
675
+ punct_post test report:
676
+ label precision recall f1 support
677
+ <NULL> (label_id: 0) 99.53 97.31 98.41 435611
678
+ <ACRONYM> (label_id: 1) 0.00 0.00 0.00 0
679
+ . (label_id: 2) 0.00 0.00 0.00 0
680
+ , (label_id: 3) 0.00 0.00 0.00 0
681
+ ? (label_id: 4) 0.00 0.00 0.00 0
682
+ ? (label_id: 5) 81.85 87.31 84.49 1513
683
+ , (label_id: 6) 74.08 93.67 82.73 35921
684
+ 。 (label_id: 7) 96.51 96.93 96.72 32097
685
+ 、 (label_id: 8) 0.00 0.00 0.00 0
686
+ ・ (label_id: 9) 0.00 0.00 0.00 0
687
+ । (label_id: 10) 0.00 0.00 0.00 0
688
+ ؟ (label_id: 11) 0.00 0.00 0.00 0
689
+ ، (label_id: 12) 0.00 0.00 0.00 0
690
+ ; (label_id: 13) 0.00 0.00 0.00 0
691
+ ። (label_id: 14) 0.00 0.00 0.00 0
692
+ ፣ (label_id: 15) 0.00 0.00 0.00 0
693
+ ፧ (label_id: 16) 0.00 0.00 0.00 0
694
+ -------------------
695
+ micro avg 97.00 97.00 97.00 505142
696
+ macro avg 87.99 93.81 90.59 505142
697
+ weighted avg 97.48 97.00 97.15 505142
698
+ ```
699
+
700
+ ```
701
+ cap test report:
702
+ label precision recall f1 support
703
+ LOWER (label_id: 0) 94.89 94.98 94.94 2951
704
+ UPPER (label_id: 1) 81.34 81.03 81.18 796
705
+ -------------------
706
+ micro avg 92.02 92.02 92.02 3747
707
+ macro avg 88.11 88.01 88.06 3747
708
+ weighted avg 92.01 92.02 92.01 3747
709
+ ```
710
+
711
+ ```
712
+ seg test report:
713
+ label precision recall f1 support
714
+ NOSTOP (label_id: 0) 99.99 99.97 99.98 473642
715
+ FULLSTOP (label_id: 1) 99.55 99.90 99.72 34500
716
+ -------------------
717
+ micro avg 99.96 99.96 99.96 508142
718
+ macro avg 99.77 99.93 99.85 508142
719
+ weighted avg 99.96 99.96 99.96 508142
720
+ ```
721
+
722
+ </details>
723
+
724
+
725
+ <details>
726
+ <summary>Japanese</summary>
727
+
728
+ ```text
729
+ punct_post test report:
730
+ label precision recall f1 support
731
+ <NULL> (label_id: 0) 99.34 95.90 97.59 406341
732
+ <ACRONYM> (label_id: 1) 0.00 0.00 0.00 0
733
+ . (label_id: 2) 0.00 0.00 0.00 0
734
+ , (label_id: 3) 0.00 0.00 0.00 0
735
+ ? (label_id: 4) 0.00 0.00 0.00 0
736
+ ? (label_id: 5) 70.55 73.56 72.02 1456
737
+ , (label_id: 6) 0.00 0.00 0.00 0
738
+ 。 (label_id: 7) 94.38 96.95 95.65 32537
739
+ 、 (label_id: 8) 54.28 87.62 67.03 18610
740
+ ・ (label_id: 9) 28.18 71.64 40.45 1100
741
+ । (label_id: 10) 0.00 0.00 0.00 0
742
+ ؟ (label_id: 11) 0.00 0.00 0.00 0
743
+ ، (label_id: 12) 0.00 0.00 0.00 0
744
+ ; (label_id: 13) 0.00 0.00 0.00 0
745
+ ። (label_id: 14) 0.00 0.00 0.00 0
746
+ ፣ (label_id: 15) 0.00 0.00 0.00 0
747
+ ፧ (label_id: 16) 0.00 0.00 0.00 0
748
+ -------------------
749
+ micro avg 95.51 95.51 95.51 460044
750
+ macro avg 69.35 85.13 74.55 460044
751
+ weighted avg 96.91 95.51 96.00 460044
752
+ ```
753
+
754
+ ```
755
+ cap test report:
756
+ label precision recall f1 support
757
+ LOWER (label_id: 0) 92.33 94.03 93.18 4174
758
+ UPPER (label_id: 1) 83.51 79.46 81.43 1587
759
+ -------------------
760
+ micro avg 90.02 90.02 90.02 5761
761
+ macro avg 87.92 86.75 87.30 5761
762
+ weighted avg 89.90 90.02 89.94 5761
763
+ ```
764
+
765
+ ```
766
+ seg test report:
767
+ label precision recall f1 support
768
+ NOSTOP (label_id: 0) 99.99 99.92 99.96 428544
769
+ FULLSTOP (label_id: 1) 99.07 99.87 99.47 34500
770
+ -------------------
771
+ micro avg 99.92 99.92 99.92 463044
772
+ macro avg 99.53 99.90 99.71 463044
773
+ weighted avg 99.92 99.92 99.92 463044
774
+ ```
775
+
776
+ </details>
777
+
778
+
779
+ <details>
780
+ <summary>Hindi</summary>
781
+
782
+ ```text
783
+ punct_post test report:
784
+ label precision recall f1 support
785
+ <NULL> (label_id: 0) 99.75 99.44 99.59 560358
786
+ <ACRONYM> (label_id: 1) 0.00 0.00 0.00 0
787
+ . (label_id: 2) 0.00 0.00 0.00 0
788
+ , (label_id: 3) 69.55 78.48 73.75 8084
789
+ ? (label_id: 4) 63.30 87.07 73.31 317
790
+ ? (label_id: 5) 0.00 0.00 0.00 0
791
+ , (label_id: 6) 0.00 0.00 0.00 0
792
+ 。 (label_id: 7) 0.00 0.00 0.00 0
793
+ 、 (label_id: 8) 0.00 0.00 0.00 0
794
+ ・ (label_id: 9) 0.00 0.00 0.00 0
795
+ । (label_id: 10) 96.92 98.66 97.78 32118
796
+ ؟ (label_id: 11) 0.00 0.00 0.00 0
797
+ ، (label_id: 12) 0.00 0.00 0.00 0
798
+ ; (label_id: 13) 0.00 0.00 0.00 0
799
+ ። (label_id: 14) 0.00 0.00 0.00 0
800
+ ፣ (label_id: 15) 0.00 0.00 0.00 0
801
+ ፧ (label_id: 16) 0.00 0.00 0.00 0
802
+ -------------------
803
+ micro avg 99.11 99.11 99.11 600877
804
+ macro avg 82.38 90.91 86.11 600877
805
+ weighted avg 99.17 99.11 99.13 600877
806
+ ```
807
+
808
+ ```
809
+ cap test report:
810
+ label precision recall f1 support
811
+ LOWER (label_id: 0) 97.19 96.72 96.95 2466
812
+ UPPER (label_id: 1) 89.14 90.60 89.86 734
813
+ -------------------
814
+ micro avg 95.31 95.31 95.31 3200
815
+ macro avg 93.17 93.66 93.41 3200
816
+ weighted avg 95.34 95.31 95.33 3200
817
+ ```
818
+
819
+ ```
820
+ seg test report:
821
+ label precision recall f1 support
822
+ NOSTOP (label_id: 0) 100.00 99.99 99.99 569472
823
+ FULLSTOP (label_id: 1) 99.82 99.99 99.91 34405
824
+ -------------------
825
+ micro avg 99.99 99.99 99.99 603877
826
+ macro avg 99.91 99.99 99.95 603877
827
+ weighted avg 99.99 99.99 99.99 603877
828
+ ```
829
+
830
+ </details>
831
+
832
+
833
+ <details>
834
+ <summary>Arabic</summary>
835
+
836
+ ```text
837
+ punct_post test report:
838
+ label precision recall f1 support
839
+ <NULL> (label_id: 0) 99.30 96.94 98.10 688043
840
+ <ACRONYM> (label_id: 1) 93.33 77.78 84.85 18
841
+ . (label_id: 2) 93.31 93.78 93.54 28175
842
+ , (label_id: 3) 0.00 0.00 0.00 0
843
+ ? (label_id: 4) 0.00 0.00 0.00 0
844
+ ? (label_id: 5) 0.00 0.00 0.00 0
845
+ , (label_id: 6) 0.00 0.00 0.00 0
846
+ 。 (label_id: 7) 0.00 0.00 0.00 0
847
+ 、 (label_id: 8) 0.00 0.00 0.00 0
848
+ ・ (label_id: 9) 0.00 0.00 0.00 0
849
+ । (label_id: 10) 0.00 0.00 0.00 0
850
+ ؟ (label_id: 11) 65.93 82.79 73.40 860
851
+ ، (label_id: 12) 44.89 79.20 57.30 20941
852
+ ; (label_id: 13) 0.00 0.00 0.00 0
853
+ ። (label_id: 14) 0.00 0.00 0.00 0
854
+ ፣ (label_id: 15) 0.00 0.00 0.00 0
855
+ ፧ (label_id: 16) 0.00 0.00 0.00 0
856
+ -------------------
857
+ micro avg 96.29 96.29 96.29 738037
858
+ macro avg 79.35 86.10 81.44 738037
859
+ weighted avg 97.49 96.29 96.74 738037
860
+ ```
861
+
862
+ ```
863
+ cap test report:
864
+ label precision recall f1 support
865
+ LOWER (label_id: 0) 97.10 99.49 98.28 4137
866
+ UPPER (label_id: 1) 98.71 92.89 95.71 1729
867
+ -------------------
868
+ micro avg 97.55 97.55 97.55 5866
869
+ macro avg 97.90 96.19 96.99 5866
870
+ weighted avg 97.57 97.55 97.52 5866
871
+ ```
872
+
873
+ ```
874
+ seg test report:
875
+ label precision recall f1 support
876
+ NOSTOP (label_id: 0) 99.99 99.97 99.98 710456
877
+ FULLSTOP (label_id: 1) 99.39 99.85 99.62 30581
878
+ -------------------
879
+ micro avg 99.97 99.97 99.97 741037
880
+ macro avg 99.69 99.91 99.80 741037
881
+ weighted avg 99.97 99.97 99.97 741037
882
+ ```
883
+
884
+ </details>
885
+
886
+ &nbsp;
887
+
888
+ # Extra Stuff
889
+
890
+ ## Acronyms, abbreviations, and bi-capitalized words
891
+
892
+ This section briefly demonstrates the models behavior when presented with the following:
893
+
894
+ 1. Acronyms: "NATO"
895
+ 2. Fake acronyms: "NHTG" in place of "NATO"
896
+ 3. Ambigous term which could be an acronym or proper noun: "Tuny"
897
+ 3. Bi-capitalized words: "McDavid"
898
+ 4. Intialisms: "p.m."
899
+
900
+ <details open>
901
+
902
+ <summary>Acronyms, etc. inputs</summary>
903
+
904
+ ```python
905
+ from typing import List
906
+
907
+ from punctuators.models import PunctCapSegModelONNX
908
+
909
+ m: PunctCapSegModelONNX = PunctCapSegModelONNX.from_pretrained(
910
+ "1-800-BAD-CODE/xlm-roberta_punctuation_fullstop_truecase"
911
+ )
912
+
913
+ input_texts = [
914
+ "the us is a nato member as a nato member the country enjoys security guarantees notably article 5",
915
+ "the us is a nhtg member as a nhtg member the country enjoys security guarantees notably article 5",
916
+ "the us is a tuny member as a tuny member the country enjoys security guarantees notably article 5",
917
+ "connor andrew mcdavid is a canadian professional ice hockey centre and captain of the edmonton oilers of the national hockey league the oilers selected him first overall in the 2015 nhl entry draft mcdavid spent his childhood playing ice hockey against older children",
918
+ "please rsvp for the party asap preferably before 8 pm tonight",
919
+ ]
920
+
921
+ results: List[List[str]] = m.infer(
922
+ texts=input_texts, apply_sbd=True,
923
+ )
924
+ for input_text, output_texts in zip(input_texts, results):
925
+ print(f"Input: {input_text}")
926
+ print(f"Outputs:")
927
+ for text in output_texts:
928
+ print(f"\t{text}")
929
+ print()
930
+
931
+ ```
932
+
933
+ </details>
934
+
935
+
936
+ <details open>
937
+
938
+ <summary>Expected output</summary>
939
+
940
+ ```text
941
+ Input: the us is a nato member as a nato member the country enjoys security guarantees notably article 5
942
+ Outputs:
943
+ The U.S. is a NATO member.
944
+ As a NATO member, the country enjoys security guarantees, notably Article 5.
945
+
946
+ Input: the us is a nhtg member as a nhtg member the country enjoys security guarantees notably article 5
947
+ Outputs:
948
+ The U.S. is a NHTG member.
949
+ As a NHTG member, the country enjoys security guarantees, notably Article 5.
950
+
951
+ Input: the us is a tuny member as a tuny member the country enjoys security guarantees notably article 5
952
+ Outputs:
953
+ The U.S. is a Tuny member.
954
+ As a Tuny member, the country enjoys security guarantees, notably Article 5.
955
+
956
+ Input: connor andrew mcdavid is a canadian professional ice hockey centre and captain of the edmonton oilers of the national hockey league the oilers selected him first overall in the 2015 nhl entry draft mcdavid spent his childhood playing ice hockey against older children
957
+ Outputs:
958
+ Connor Andrew McDavid is a Canadian professional ice hockey centre and captain of the Edmonton Oilers of the National Hockey League.
959
+ The Oilers selected him first overall in the 2015 NHL entry draft.
960
+ McDavid spent his childhood playing ice hockey against older children.
961
+
962
+ Input: please rsvp for the party asap preferably before 8 pm tonight
963
+ Outputs:
964
+ Please RSVP for the party ASAP, preferably before 8 p.m. tonight.
965
+ ```
966
+
967
+ </details>
config.yaml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ languages: [
3
+ "af", "am", "ar", "bg", "bn", "de", "el", "en", "es", "et",
4
+ "fa", "fi", "fr", "gu", "hi", "hr", "hu", "id", "is", "it",
5
+ "ja", "kk", "kn", "ko", "ky", "lt", "lv", "mk", "ml", "mr",
6
+ "nl", "or", "pa", "pl", "ps", "pt", "ro", "ru", "rw", "so",
7
+ "sr", "sw", "ta", "te", "tr", "uk", "zh"
8
+ ]
9
+
10
+ max_length: 256
11
+
12
+ pre_labels: [
13
+ "<NULL>",
14
+ "¿",
15
+ ]
16
+
17
+ post_labels: [
18
+ "<NULL>",
19
+ "<ACRONYM>",
20
+ ".",
21
+ ",",
22
+ "?",
23
+ "?",
24
+ ",",
25
+ "。",
26
+ "、",
27
+ "・",
28
+ "।",
29
+ "؟",
30
+ "،",
31
+ ";",
32
+ "።",
33
+ "፣",
34
+ "፧",
35
+ ]
model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c43ca686dabc237c3b06be834b9423c07580fef7e2b1a6c09976f7d60caa5d89
3
+ size 1112481438
pcs47_1jun.nemo ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d94d08b868a35d01b0fa089775e593098b0cf233c25646b0e803a2b823248d00
3
+ size 1119815680
pipeline.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+
3
+ from punctuators.models.punc_cap_seg_model import PunctCapSegConfigONNX, PunctCapSegModelONNX
4
+
5
+
6
+ class PreTrainedPipeline():
7
+ def __init__(self, path: str):
8
+ cfg: PunctCapSegConfigONNX = PunctCapSegConfigONNX(
9
+ directory=path,
10
+ spe_filename="sp.model",
11
+ model_filename="model.onnx",
12
+ config_filename="config.yaml",
13
+ )
14
+ self._punctuator: PunctCapSegModelONNX = PunctCapSegModelONNX(cfg)
15
+
16
+ def __call__(self, data: str) -> List[Dict]:
17
+ # Use list to generate a batch of size 1
18
+ pred_texts: List[List[str]] = self._punctuator.infer([data])
19
+ # Can't figure out how to make the text gen widget print multiple lines; use a '\n' for now.
20
+ outputs: List[Dict] = [{"generated_text": " \\n ".join(pred_texts[0])}]
21
+ return outputs
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ punctuators
sp.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f944d0be93b275f62e1913fd409f378ddbba108e57fe4a9cb47e8c047f6bef1
3
+ size 5069059