Commit
•
f8f74cc
1
Parent(s):
5cb5b27
Update app.py
Browse files
app.py
CHANGED
@@ -3,20 +3,24 @@ import spacy
|
|
3 |
from spacy import displacy
|
4 |
from spacy.tokens import Span
|
5 |
from random import randint
|
6 |
-
|
7 |
-
|
8 |
-
model = FCoref("pythainlp/han-coref-v1.0")
|
9 |
nlp = spacy.blank("th")
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
default = "แกว่าเราเข้มแข็งมากพอที่จะเห็นแกไปน่ารักกับใครหรอ"
|
12 |
|
13 |
def corefer(text):
|
14 |
-
|
15 |
-
|
16 |
title=None
|
17 |
dic_ents = {"text":text,"ents":[],"title":title}
|
18 |
-
_tag=[str(i) for i in list(range(len(
|
19 |
-
for i,tag in enumerate(
|
20 |
for s,e in tag:
|
21 |
dic_ents["ents"].append({"start": s, "end": e, "label": _tag[i]})
|
22 |
colors={i:"#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]) for i in _tag} # thank https://stackoverflow.com/a/50218895
|
|
|
3 |
from spacy import displacy
|
4 |
from spacy.tokens import Span
|
5 |
from random import randint
|
6 |
+
import spacy
|
7 |
+
from fastcoref import spacy_component
|
|
|
8 |
nlp = spacy.blank("th")
|
9 |
|
10 |
+
nlp.add_pipe(
|
11 |
+
"fastcoref",
|
12 |
+
config={'model_architecture': 'FCoref','model_path': 'pythainlp/han-coref-v1.0'}
|
13 |
+
)
|
14 |
+
|
15 |
default = "แกว่าเราเข้มแข็งมากพอที่จะเห็นแกไปน่ารักกับใครหรอ"
|
16 |
|
17 |
def corefer(text):
|
18 |
+
doc = nlp(text)
|
19 |
+
tags = doc._.coref_clusters
|
20 |
title=None
|
21 |
dic_ents = {"text":text,"ents":[],"title":title}
|
22 |
+
_tag=[str(i) for i in list(range(len(tags)))]
|
23 |
+
for i,tag in enumerate(tags):
|
24 |
for s,e in tag:
|
25 |
dic_ents["ents"].append({"start": s, "end": e, "label": _tag[i]})
|
26 |
colors={i:"#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]) for i in _tag} # thank https://stackoverflow.com/a/50218895
|