I am generating noun chunks using spaCy's statistical models (e.g. noun chunks based on the part-of-speech tags and dependencies) and rule-based matching to capture (user supplied) context specific noun chunks.
For other downstream tasks, I am retokenizing these noun chunks (spans), which works fine for the most part. However, the token's vector representation (token.vector) gets set to all zeros. Is there a way to retain the vector information e.g. by averaging the individual token vectors and assigning it to the retokenised token?
I tried this with the code...
def tokenise_noun_chunks(doc)
if not doc.has_annotation("DEP"):
return doc
all_noun_chunks = list(doc.noun_chunks) + doc._.custom_noun_chunks
with doc.retokenize() as retokenizer:
for span in all_noun_chunks:
# if I print(span.vector) here, I get the correctly averaged vector
attrs = {"tag": span.root.tag, "dep": span.root.dep}
retokenizer.merge(np, attrs=attrs)
return doc
...but when I check the returned vectors for the noun chunks, I get a zeros array. I've modelled this (the above code) on the built-in merge_noun_chunks component (just modified to include my own custom noun chunks), so I can confirm that the built in component gives the same results.
Is there any way to keep the word vector information? Will I need to add the term/average vector to the Vector store?