Spaces:
Sleeping
Sleeping
Commit
·
0bb16d9
1
Parent(s):
1eeeaf5
add app.py and requirements.txt
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ def update_knowledge_graph(entities, relations):
|
|
42 |
def visualize_kg_text():
|
43 |
nodes = [f"{ent[0]} ({ent[1]})" for ent in knowledge_graph["entities"]]
|
44 |
edges = [f"{h} --[{r}]-> {t}" for h, t, r in knowledge_graph["relations"]]
|
45 |
-
return "📌
|
46 |
|
47 |
# ======================== 实体识别(NER) ========================
|
48 |
def ner(text, model_type="bert"):
|
@@ -113,7 +113,8 @@ def process_file(file, model_type="bert"):
|
|
113 |
|
114 |
# ======================== 模型评估与自动标注 ========================
|
115 |
def convert_telegram_json_to_eval_format(path):
|
116 |
-
|
|
|
117 |
result = []
|
118 |
for m in data.get("messages", []):
|
119 |
if isinstance(m.get("text"), str):
|
@@ -132,7 +133,7 @@ def evaluate_ner_model(data, model_type):
|
|
132 |
for ent in gold.union(pred):
|
133 |
y_true.append(1 if ent in gold else 0)
|
134 |
y_pred.append(1 if ent in pred else 0)
|
135 |
-
return f"Precision: {precision_score(y_true,y_pred):.2f}\nRecall: {recall_score(y_true,y_pred):.2f}\nF1: {f1_score(y_true,y_pred):.2f}"
|
136 |
|
137 |
def auto_annotate(file, model_type):
|
138 |
data = convert_telegram_json_to_eval_format(file.name)
|
|
|
42 |
def visualize_kg_text():
|
43 |
nodes = [f"{ent[0]} ({ent[1]})" for ent in knowledge_graph["entities"]]
|
44 |
edges = [f"{h} --[{r}]-> {t}" for h, t, r in knowledge_graph["relations"]]
|
45 |
+
return "\n".join(["📌 实体:"] + nodes + ["", "📎 关系:"] + edges)
|
46 |
|
47 |
# ======================== 实体识别(NER) ========================
|
48 |
def ner(text, model_type="bert"):
|
|
|
113 |
|
114 |
# ======================== 模型评估与自动标注 ========================
|
115 |
def convert_telegram_json_to_eval_format(path):
|
116 |
+
with open(path, encoding="utf-8") as f:
|
117 |
+
data = json.load(f)
|
118 |
result = []
|
119 |
for m in data.get("messages", []):
|
120 |
if isinstance(m.get("text"), str):
|
|
|
133 |
for ent in gold.union(pred):
|
134 |
y_true.append(1 if ent in gold else 0)
|
135 |
y_pred.append(1 if ent in pred else 0)
|
136 |
+
return f"Precision: {precision_score(y_true, y_pred):.2f}\nRecall: {recall_score(y_true, y_pred):.2f}\nF1: {f1_score(y_true, y_pred):.2f}"
|
137 |
|
138 |
def auto_annotate(file, model_type):
|
139 |
data = convert_telegram_json_to_eval_format(file.name)
|