Fix token aggregation
Browse files
app.py
CHANGED
@@ -31,8 +31,14 @@ def tag(text, lang_index):
|
|
31 |
loaded_model_id = model_id
|
32 |
pipe = pipeline("token-classification", model_id, aggregation_strategy="first")
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
return out, model_link(model_id)
|
38 |
|
|
|
31 |
loaded_model_id = model_id
|
32 |
pipe = pipeline("token-classification", model_id, aggregation_strategy="first")
|
33 |
|
34 |
+
# Aggregate words:
|
35 |
+
# split on whitespace and PUNCT, but merge other subtokens (keep first tag)
|
36 |
+
out = []
|
37 |
+
for g in pipe(text):
|
38 |
+
if g["word"][0] == "▁" or g["entity"] == "PUNCT":
|
39 |
+
out.append((g["word"].lstrip("▁"), g["entity"]))
|
40 |
+
else:
|
41 |
+
out[-1] = (out[-1][0] + g["word"], out[-1][1])
|
42 |
|
43 |
return out, model_link(model_id)
|
44 |
|