switch to v5 + han-only drop
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/span_postproc.cpython-311.pyc +0 -0
- app.py +4 -2
- span_postproc.py +13 -3
__pycache__/app.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
|
__pycache__/span_postproc.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/span_postproc.cpython-311.pyc and b/__pycache__/span_postproc.cpython-311.pyc differ
|
|
|
app.py
CHANGED
|
@@ -15,9 +15,9 @@ from pydantic import BaseModel
|
|
| 15 |
from huggingface_hub import list_repo_files
|
| 16 |
from optimum.onnxruntime import ORTModelForTokenClassification
|
| 17 |
from transformers import AutoTokenizer, pipeline
|
| 18 |
-
from span_postproc import trim_span_offsets, is_stopword, nfc
|
| 19 |
|
| 20 |
-
MODEL_REPO = "m6dd8m/wl-ko-ner-
|
| 21 |
TOK_REPO = "monologg/koelectra-base-v3-discriminator" # ν ν¬λμ΄μ (νμΈνλν΄λ λμΌ)
|
| 22 |
|
| 23 |
# 1) repo μμ .onnx μλ νμ§ β fp32 μ°μ .
|
|
@@ -46,6 +46,8 @@ def _spans(entities, text):
|
|
| 46 |
s, en = int(e["start"]), int(e["end"])
|
| 47 |
if typ in _TRIM:
|
| 48 |
s, en, surf = trim_span_offsets(text, s, en) # CHEAP-1 νμκ΄νΈ νΈλ¦¬λ° (surface+offset)
|
|
|
|
|
|
|
| 49 |
else:
|
| 50 |
surf = e["word"]
|
| 51 |
surf = (surf or "").strip()
|
|
|
|
| 15 |
from huggingface_hub import list_repo_files
|
| 16 |
from optimum.onnxruntime import ORTModelForTokenClassification
|
| 17 |
from transformers import AutoTokenizer, pipeline
|
| 18 |
+
from span_postproc import trim_span_offsets, is_stopword, nfc, has_hangul
|
| 19 |
|
| 20 |
+
MODEL_REPO = "m6dd8m/wl-ko-ner-v5" # ONNX κ°μ€μΉ (v5 λ©ν°λ΄ + Q3 νμ²λ¦¬)
|
| 21 |
TOK_REPO = "monologg/koelectra-base-v3-discriminator" # ν ν¬λμ΄μ (νμΈνλν΄λ λμΌ)
|
| 22 |
|
| 23 |
# 1) repo μμ .onnx μλ νμ§ β fp32 μ°μ .
|
|
|
|
| 46 |
s, en = int(e["start"]), int(e["end"])
|
| 47 |
if typ in _TRIM:
|
| 48 |
s, en, surf = trim_span_offsets(text, s, en) # CHEAP-1 νμκ΄νΈ νΈλ¦¬λ° (surface+offset)
|
| 49 |
+
if not has_hangul(surf): # νκΈ 0 = νμ μ£Όμ μμ¬(pipeline λΆλ¦¬) β λλ‘
|
| 50 |
+
continue
|
| 51 |
else:
|
| 52 |
surf = e["word"]
|
| 53 |
surf = (surf or "").strip()
|
span_postproc.py
CHANGED
|
@@ -31,6 +31,11 @@ def _is_hangul(c):
|
|
| 31 |
return "κ°" <= c <= "ν£"
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def _is_cjk(c):
|
| 35 |
"""CJK ν΅ν©νμ(+νμ₯ A/νΈν). νκΈ prefix λ€ νμ μ£Όμ νμ μ©."""
|
| 36 |
o = ord(c)
|
|
@@ -102,7 +107,12 @@ def postprocess(preds):
|
|
| 102 |
seen = set()
|
| 103 |
for p in preds:
|
| 104 |
surf, typ = p[0], p[1]
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
if not s:
|
| 107 |
continue
|
| 108 |
if is_stopword(s, typ):
|
|
@@ -157,8 +167,8 @@ if __name__ == "__main__":
|
|
| 157 |
|
| 158 |
# ν΅ν©: μ¬μ( κ° νΈλ¦¬λ°λμ΄ gold μ λ§€μΉλλμ§ + offset νΈλ¦¬λ°
|
| 159 |
print("\n[post] ν΅ν© νμ²λ¦¬:")
|
| 160 |
-
pp = postprocess([("μ¬μ(", "LC"), ("νλ", "PS"), ("κ·Έλ ", "DT"), ("μλ¨ ν΄", "PS")])
|
| 161 |
-
exp_pp = [("μ¬μ", "LC"), ("μλ¨ ν΄", "PS")]
|
| 162 |
flag = "OK" if pp == exp_pp else "XX"
|
| 163 |
ok += pp == exp_pp
|
| 164 |
print(f" [{flag}] postprocess(...) = {pp} (κΈ°λ {exp_pp})")
|
|
|
|
| 31 |
return "κ°" <= c <= "ν£"
|
| 32 |
|
| 33 |
|
| 34 |
+
def has_hangul(s):
|
| 35 |
+
"""λ¬Έμμ΄μ νκΈ μμ μ΄ νλλΌλ μλ β νμ-only/κ΄νΈ μμ¬(μ: pipeline μ΄ μͺΌκ° 'ιθ₯Ώ') νλ³μ©."""
|
| 36 |
+
return any(_is_hangul(c) for c in (s or ""))
|
| 37 |
+
|
| 38 |
+
|
| 39 |
def _is_cjk(c):
|
| 40 |
"""CJK ν΅ν©νμ(+νμ₯ A/νΈν). νκΈ prefix λ€ νμ μ£Όμ νμ μ©."""
|
| 41 |
o = ord(c)
|
|
|
|
| 107 |
seen = set()
|
| 108 |
for p in preds:
|
| 109 |
surf, typ = p[0], p[1]
|
| 110 |
+
if typ in _TRIM_TYPES:
|
| 111 |
+
s = trim_affix(surf)
|
| 112 |
+
if not has_hangul(s): # νΈλ¦¬λ° ν νκΈ 0 = νμ/κ΄νΈ μμ¬(pipeline μ΄ μͺΌκ° 'ιθ₯Ώ' λ±) β λλ‘
|
| 113 |
+
continue
|
| 114 |
+
else:
|
| 115 |
+
s = (surf or "").strip()
|
| 116 |
if not s:
|
| 117 |
continue
|
| 118 |
if is_stopword(s, typ):
|
|
|
|
| 167 |
|
| 168 |
# ν΅ν©: μ¬μ( κ° νΈλ¦¬λ°λμ΄ gold μ λ§€μΉλλμ§ + offset νΈλ¦¬λ°
|
| 169 |
print("\n[post] ν΅ν© νμ²λ¦¬:")
|
| 170 |
+
pp = postprocess([("μ¬μ(", "LC"), ("ιθ₯Ώ", "LC"), ("νλ", "PS"), ("κ·Έλ ", "DT"), ("μλ¨ ν΄", "PS")])
|
| 171 |
+
exp_pp = [("μ¬μ", "LC"), ("μλ¨ ν΄", "PS")] # ιθ₯Ώ(νμonly)Β·νλ(PS)Β·κ·Έλ (DT) λλ‘
|
| 172 |
flag = "OK" if pp == exp_pp else "XX"
|
| 173 |
ok += pp == exp_pp
|
| 174 |
print(f" [{flag}] postprocess(...) = {pp} (κΈ°λ {exp_pp})")
|