[ENG] en_core_web_trf inaccurately identifying noun chunks #13986
SummaryI was trying to identify noun chunks from my texts. When assessing pre-trained models, en_core_web_trf performed best in most cases, which was expected due to the data size. However, some results from the model was hard to understand. I wonder whether anyone could help explain it or suggest further processing for my original data. MethodsPython version3.12 Model versions:
DataOriginal text: 'Acute cardiovascular disease (CVD) events \< 3 months ago' Workflowimport spacy
import pandas as pd
models = ["en_core_web_sm", "en_core_web_lg", "en_core_web_trf"]
sentence = 'Acute cardiovascular disease (CVD) events \\< 3 months ago'
for m in models:
print(">>>{}".format(m))
processor = spacy.load(m)
doc = processor(sentence)
decomp_df = pd.DataFrame([
{"text": token.text, "lemma": token.lemma_, "dep_tag": token.dep_}
for token in doc])
print(decomp_df)
print([chunk.text for chunk in doc.noun_chunks])The output will be >>>en_core_web_sm
text lemma dep_tag
0 Acute acute nmod
1 cardiovascular cardiovascular amod
2 disease disease nsubj
3 ( ( punct
4 CVD CVD appos
5 ) ) punct
6 events event ROOT
7 \ \ nmod
8 < < dobj
9 3 3 nummod
10 months month npadvmod
11 ago ago advmod
['Acute cardiovascular disease', 'CVD']
>>>en_core_web_lg
text lemma dep_tag
0 Acute acute amod
1 cardiovascular cardiovascular amod
2 disease disease nsubj
3 ( ( punct
4 CVD CVD appos
5 ) ) punct
6 events event ROOT
7 \ \ dobj
8 < < appos
9 3 3 nummod
10 months month npadvmod
11 ago ago advmod
['Acute cardiovascular disease', 'CVD', '\\']
>>>en_core_web_trf
text lemma dep_tag
0 Acute acute amod
1 cardiovascular cardiovascular amod
2 disease disease nmod
3 ( ( punct
4 CVD cvd appos
5 ) ) punct
6 events event ROOT
7 \ \ punct
8 < < appos
9 3 3 nummod
10 months month npadvmod
11 ago ago advmod
['(CVD']Could anyone explain why the most accurate model would suggest '(CVD' as the noun chunk, please? |
Replies: 2 comments
|
The rule (spaCy's English syntax iterator) walks every NOUN/PROPN/PRON, and for the ones whose yield word.left_edge.i, word.i + 1, np_labelIn your trf parse, Then it gets worse: chunks can't nest (there's a What actually fixes it:
|
|
Thank you, @apoorva-01, for the helpful explanation and recommendations. Cleaning the poorly formatted tokens (i.e., In my case, the dependency label of I am closing the discussion and will share updates if other solutions could be helpful generally. |
.noun_chunksisn't a separate noun-chunker, it's a fixed rule that reads off the dependency parse. So(CVDisn't the model "choosing" a bad chunk, it's a side effect of how trf parsed the fragment.The rule (spaCy's English syntax iterator) walks every NOUN/PROPN/PRON, and for the ones whose
dep_is a head label (nsubj,dobj,appos,attr,pobj,ROOT, ...) it yields the span from that token'sleft_edgeto the token itself:In your trf parse,
CVDis taggedappos(a head label), and the(got attached as a left dependent inside CVD's subtree, soCVD.left_edgeis(. Span runs(→CVD=(CVD. Checkdoc[4].left_edgeand you'll see it.Then it gets wo…