Upload eval_codeswitch_and_new_baselines.py with huggingface_hub
Browse files
eval_codeswitch_and_new_baselines.py
CHANGED
|
@@ -31,6 +31,11 @@ def segment_words(t): return _WORD_PAT.findall(t)
|
|
| 31 |
def count_graphemes(t): return len(regex.findall(r"\X", t))
|
| 32 |
def filter_sp(tokens): return [t for t in tokens if t not in _SPECIAL]
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def classify_script_detailed(t):
|
| 35 |
"""Classify as 'ar', 'az', or 'mi' (mixed)."""
|
| 36 |
ar_chars = len(_AR_PAT.findall(t))
|
|
@@ -134,13 +139,12 @@ def evaluate_with_mixed(tok, name, source, algo, arch, vsz, texts):
|
|
| 134 |
|
| 135 |
try:
|
| 136 |
dec = tok.decode(ids, script)
|
| 137 |
-
if
|
| 138 |
em_buckets[sc]["ok"] += 1
|
| 139 |
except:
|
| 140 |
pass
|
| 141 |
except:
|
| 142 |
pass
|
| 143 |
-
|
| 144 |
for sc in ("ar", "az", "mi"):
|
| 145 |
setattr(m, f"fertility_{sc}", float(np.mean(buckets[sc])) if buckets[sc] else 0)
|
| 146 |
setattr(m, f"cpt_{sc}", float(np.mean(cpt_buckets[sc])) if cpt_buckets[sc] else 0)
|
|
@@ -173,7 +177,7 @@ def evaluate_on_doda(tok, name, source, algo, arch, vsz, texts):
|
|
| 173 |
all_c.append(cpt)
|
| 174 |
try:
|
| 175 |
dec = tok.decode(ids, script)
|
| 176 |
-
if
|
| 177 |
em_ok += 1
|
| 178 |
except:
|
| 179 |
pass
|
|
@@ -238,6 +242,8 @@ def main():
|
|
| 238 |
externals_cs = [
|
| 239 |
("DarijaBERT-ar", "external_darija", "WordPiece", "shared", 80000,
|
| 240 |
"SI2M-Lab/DarijaBERT", False),
|
|
|
|
|
|
|
| 241 |
("Qwen2.5-Darija", "external_darija", "SentencePiece", "shared", 151643,
|
| 242 |
"GemMaroc/Qwen2.5-7B-Instruct-darija", False),
|
| 243 |
]
|
|
|
|
| 31 |
def count_graphemes(t): return len(regex.findall(r"\X", t))
|
| 32 |
def filter_sp(tokens): return [t for t in tokens if t not in _SPECIAL]
|
| 33 |
|
| 34 |
+
def normalize_decode(s):
|
| 35 |
+
s = s.replace("##", "")
|
| 36 |
+
s = " ".join(s.split())
|
| 37 |
+
return s
|
| 38 |
+
|
| 39 |
def classify_script_detailed(t):
|
| 40 |
"""Classify as 'ar', 'az', or 'mi' (mixed)."""
|
| 41 |
ar_chars = len(_AR_PAT.findall(t))
|
|
|
|
| 139 |
|
| 140 |
try:
|
| 141 |
dec = tok.decode(ids, script)
|
| 142 |
+
if normalize_decode(dec) == normalize_decode(text):
|
| 143 |
em_buckets[sc]["ok"] += 1
|
| 144 |
except:
|
| 145 |
pass
|
| 146 |
except:
|
| 147 |
pass
|
|
|
|
| 148 |
for sc in ("ar", "az", "mi"):
|
| 149 |
setattr(m, f"fertility_{sc}", float(np.mean(buckets[sc])) if buckets[sc] else 0)
|
| 150 |
setattr(m, f"cpt_{sc}", float(np.mean(cpt_buckets[sc])) if cpt_buckets[sc] else 0)
|
|
|
|
| 177 |
all_c.append(cpt)
|
| 178 |
try:
|
| 179 |
dec = tok.decode(ids, script)
|
| 180 |
+
if normalize_decode(dec) == normalize_decode(text):
|
| 181 |
em_ok += 1
|
| 182 |
except:
|
| 183 |
pass
|
|
|
|
| 242 |
externals_cs = [
|
| 243 |
("DarijaBERT-ar", "external_darija", "WordPiece", "shared", 80000,
|
| 244 |
"SI2M-Lab/DarijaBERT", False),
|
| 245 |
+
("DarijaBERT-mix", "external_darija", "WordPiece", "shared", 160000,
|
| 246 |
+
"SI2M-Lab/DarijaBERT-mix", False),
|
| 247 |
("Qwen2.5-Darija", "external_darija", "SentencePiece", "shared", 151643,
|
| 248 |
"GemMaroc/Qwen2.5-7B-Instruct-darija", False),
|
| 249 |
]
|