Upload benchmark_eval.py with huggingface_hub
Browse files- benchmark_eval.py +16 -3
benchmark_eval.py
CHANGED
|
@@ -27,7 +27,7 @@ def get_capitalized_ngrams(text, n=3):
|
|
| 27 |
"""Extract n-grams where at least one token starts with uppercase."""
|
| 28 |
tokens = text.split()
|
| 29 |
ngrams = [tuple(tokens[i:i+n]) for i in range(len(tokens)-n+1)]
|
| 30 |
-
return [ng for ng in ngrams if any(t[0].isupper() for t in ng)]
|
| 31 |
|
| 32 |
def crr3(gold_records, predictions):
|
| 33 |
"""Capitalized 3-gram survival rate."""
|
|
@@ -77,8 +77,21 @@ def main():
|
|
| 77 |
with open(args.pred, "r", encoding="utf-8") as f:
|
| 78 |
predictions = [json.loads(line) for line in f]
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
print(f"Evaluating {len(predictions)} records...")
|
| 84 |
|
|
|
|
| 27 |
"""Extract n-grams where at least one token starts with uppercase."""
|
| 28 |
tokens = text.split()
|
| 29 |
ngrams = [tuple(tokens[i:i+n]) for i in range(len(tokens)-n+1)]
|
| 30 |
+
return [ng for ng in ngrams if any(len(t) > 0 and t[0].isupper() for t in ng)]
|
| 31 |
|
| 32 |
def crr3(gold_records, predictions):
|
| 33 |
"""Capitalized 3-gram survival rate."""
|
|
|
|
| 77 |
with open(args.pred, "r", encoding="utf-8") as f:
|
| 78 |
predictions = [json.loads(line) for line in f]
|
| 79 |
|
| 80 |
+
unknown_entity_count = 0
|
| 81 |
+
total_entity_count = 0
|
| 82 |
+
|
| 83 |
+
for g, p in zip(gold_records, predictions):
|
| 84 |
+
if g.get("id") != p.get("id"):
|
| 85 |
+
raise ValueError(f"ID mismatch: {g.get('id')} vs {p.get('id')}")
|
| 86 |
+
|
| 87 |
+
for ent in g.get("entities", []):
|
| 88 |
+
total_entity_count += 1
|
| 89 |
+
if ent.get("type", "UNKNOWN") == "UNKNOWN":
|
| 90 |
+
unknown_entity_count += 1
|
| 91 |
+
|
| 92 |
+
if total_entity_count > 0 and unknown_entity_count > 0:
|
| 93 |
+
pct = (unknown_entity_count / total_entity_count) * 100
|
| 94 |
+
print(f"[NOTE] {pct:.1f}% of entities in evaluation are typed as UNKNOWN.")
|
| 95 |
|
| 96 |
print(f"Evaluating {len(predictions)} records...")
|
| 97 |
|