Instructions to use SlayerLab/NERGAL with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SlayerLab/NERGAL with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="SlayerLab/NERGAL")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("SlayerLab/NERGAL") model = AutoModelForTokenClassification.from_pretrained("SlayerLab/NERGAL", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Fix public tokenizer batch shape before 1.0.2 release
Browse files- CHANGELOG.md +2 -0
- nergal.py +1 -1
- test_nergal.py +11 -0
CHANGELOG.md
CHANGED
|
@@ -10,6 +10,8 @@ Accuracy is 841-dev, union at 0.95, 354 gold spans. A version that changes those
|
|
| 10 |
|
| 11 |
## 1.0.2
|
| 12 |
|
|
|
|
|
|
|
| 13 |
Fix immediately labelled hyphenated country-area phones with one-digit country codes or wider area codes. Numeric continuations, slash lists, weak contact cues, and nearby title prose still abstain. Same weights, threshold, and API.
|
| 14 |
|
| 15 |
841-dev: rules recover 14 more whole spans; the union recovers one (323 → 324), reducing residual passages 25 → 24. Rules FP remain 98; union FP remain 123. Lost gold, new false characters, and new clean-passage damage are all zero. Rules SHA `3016ae5b…`.
|
|
|
|
| 10 |
|
| 11 |
## 1.0.2
|
| 12 |
|
| 13 |
+
Fix the public wrapper’s tokenizer batch shape so local model inference works. The packed tokenizer regression and an end-to-end local inference check cover this path.
|
| 14 |
+
|
| 15 |
Fix immediately labelled hyphenated country-area phones with one-digit country codes or wider area codes. Numeric continuations, slash lists, weak contact cues, and nearby title prose still abstain. Same weights, threshold, and API.
|
| 16 |
|
| 17 |
841-dev: rules recover 14 more whole spans; the union recovers one (323 → 324), reducing residual passages 25 → 24. Rules FP remain 98; union FP remain 123. Lost gold, new false characters, and new clean-passage damage are all zero. Rules SHA `3016ae5b…`.
|
nergal.py
CHANGED
|
@@ -142,7 +142,7 @@ class Encoding:
|
|
| 142 |
self.pieces = lru_cache(maxsize=16384)(lambda s: tuple(tokenizer.encode(s, add_special_tokens=False)))
|
| 143 |
|
| 144 |
def encode(self, words):
|
| 145 |
-
encoded = self.tokenizer(words, is_split_into_words=True, truncation=False, padding=False)
|
| 146 |
ids = encoded['input_ids'][0]
|
| 147 |
mapping = encoded.word_ids(0)
|
| 148 |
first, actual = {}, {}
|
|
|
|
| 142 |
self.pieces = lru_cache(maxsize=16384)(lambda s: tuple(tokenizer.encode(s, add_special_tokens=False)))
|
| 143 |
|
| 144 |
def encode(self, words):
|
| 145 |
+
encoded = self.tokenizer([words], is_split_into_words=True, truncation=False, padding=False)
|
| 146 |
ids = encoded['input_ids'][0]
|
| 147 |
mapping = encoded.word_ids(0)
|
| 148 |
first, actual = {}, {}
|
test_nergal.py
CHANGED
|
@@ -24,6 +24,17 @@ class NergalTests(unittest.TestCase):
|
|
| 24 |
digest = hashlib.sha256((HERE / 'scrub_pii.py').read_bytes()).hexdigest()
|
| 25 |
self.assertEqual(digest, RULES_SHA)
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def test_union_keeps_regex_and_adds_model_spans(self):
|
| 28 |
from nergal import apply_union, scrub_spans
|
| 29 |
text = 'Ring 000000000 then extra.'
|
|
|
|
| 24 |
digest = hashlib.sha256((HERE / 'scrub_pii.py').read_bytes()).hexdigest()
|
| 25 |
self.assertEqual(digest, RULES_SHA)
|
| 26 |
|
| 27 |
+
def test_real_tokenizer_preserves_batch_and_unit_alignment(self):
|
| 28 |
+
from transformers import AutoTokenizer
|
| 29 |
+
from nergal import Encoding
|
| 30 |
+
tokenizer = AutoTokenizer.from_pretrained(str(HERE), local_files_only=True, fix_mistral_regex=False)
|
| 31 |
+
encoding = Encoding(tokenizer)
|
| 32 |
+
words = ['A', '[PII_SPACE]', '1']
|
| 33 |
+
encoded, first = encoding.encode(words)
|
| 34 |
+
self.assertIsInstance(encoded['input_ids'][0], list)
|
| 35 |
+
self.assertEqual(len(first), len(words))
|
| 36 |
+
self.assertEqual([encoded.word_ids(0)[i] for i in first], [0, 1, 2])
|
| 37 |
+
|
| 38 |
def test_union_keeps_regex_and_adds_model_spans(self):
|
| 39 |
from nergal import apply_union, scrub_spans
|
| 40 |
text = 'Ring 000000000 then extra.'
|