Skip to content

Commit d2bd59a

Browse files
committed
Bugfix: Use \u001F (ASCII unit separator) as the separator between feature and label in model json file, instead of "|" because "|" may be part of a feature (in weird cases). Update model.
1 parent e434337 commit d2bd59a

6 files changed

Lines changed: 12 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ The model has the following accuracy on a test data set of 20% of the total data
5858
╒══════════════════════════╤══════════════════════════╕
5959
│ Sentence-level results │ Word-level results │
6060
╞══════════════════════════╪══════════════════════════╡
61-
│ Accuracy: 95.62% │ Accuracy: 98.26% │
62-
│ │ Precision (micro) 98.25% │
63-
│ │ Recall (micro) 98.26% │
64-
│ │ F1 score (micro) 98.25% │
61+
│ Accuracy: 95.59% │ Accuracy: 98.25% │
62+
│ │ Precision (micro) 98.24% │
63+
│ │ Recall (micro) 98.25% │
64+
│ │ F1 score (micro) 98.24% │
6565
╘══════════════════════════╧══════════════════════════╛
6666
```
6767

ingredient_parser/en/data/ModelCard.en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ The model has the following performance metrics:
130130

131131
| Word level accuracy | Sentence level accuracy |
132132
| ------------------- | ----------------------- |
133-
| 98.26 ± 0.22% | 95.62 ± 0.48% |
133+
| 98.25 ± 0.22% | 95.59 ± 0.48% |
134134

135135
These metrics were determined by executing 25 training/evaluation cycles and calculating the mean and standard deviation for the two metrics across all cycles. The uncertainty values provided represent the 99.7% confidence bounds (i.e. 3x standard deviation). The uncertainty is due to the randomisation of the selection of training and evaluation data whenever the model is trained.
136136

ingredient_parser/en/data/model.en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"delta": 5e-5,
1212
"linesearch": "MoreThuente",
1313
"max_linesearch": 5,
14-
"datetime": "2026-05-25T15:05:24.991451",
14+
"datetime": "2026-07-03T21:14:34.882449",
1515
"stopping_reason": "L-BFGS terminated with the stopping criteria",
1616
"quantize_bits": 16,
1717
"min_abs_weight": null,
18-
"sha256": "334f14a6a6d39c6eb1076b61091a9b2216567b2525e2991d5f8d1bd90e250bc2"
18+
"sha256": "5cb2c3d123d88611a3709eec074b146c8c04c1ea07623554e907f635a0fcf042"
1919
}
4.18 KB
Binary file not shown.

ingredient_parser/inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def __init__(
421421
# weights.
422422
self.emission_weights = np.zeros((self.n_features, self.n_labels), dtype=dtype)
423423
for feat, weight in feature_weights.items():
424-
feature, label = feat.split("|")
424+
feature, label = feat.split("\u001f")
425425
feature_idx = self.features_to_idx[feature]
426426
label_idx = self.label_to_idx[label]
427427
self.emission_weights[feature_idx, label_idx] = weight
@@ -430,7 +430,7 @@ def __init__(
430430
# weights.
431431
self.transition_weights = np.zeros((self.n_labels, self.n_labels), dtype=dtype)
432432
for feat, weight in transition_weights.items():
433-
prev_label, current_label = feat.split("|")
433+
prev_label, current_label = feat.split("\u001f")
434434
prev_label_idx = self.label_to_idx[prev_label]
435435
current_label_idx = self.label_to_idx[current_label]
436436
self.transition_weights[prev_label_idx, current_label_idx] = weight

train/export.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def export_crfsuite_to_json(
3535
Name of each label (key) and their index (value).
3636
* state_features : dict[str, float]
3737
The weights for each feature for each label.
38-
The keys are the feature name and label joined with |.
38+
The keys are the feature name and label joined with \u001f (ASCII unit separator).
3939
For example: bias:|QTY, where "bias:" is the feature name and "QTY" is the label.
4040
* transitions
4141
The weights for each label to label transition.
@@ -59,8 +59,8 @@ def export_crfsuite_to_json(
5959
params = CRFModelParameters(
6060
attributes={k: int(v) for k, v in info.attributes.items()},
6161
labels={k: int(v) for k, v in info.labels.items()},
62-
state_features={k[0] + "|" + k[1]: v for k, v in info.state_features.items()},
63-
transitions={k[0] + "|" + k[1]: v for k, v in info.transitions.items()},
62+
state_features={"\u001f".join(k): v for k, v in info.state_features.items()},
63+
transitions={"\u001f".join(k): v for k, v in info.transitions.items()},
6464
quantization_scale=1.0,
6565
quantization_zero_offset=0,
6666
)

0 commit comments

Comments
 (0)