Modify attributes of spacy.tokens.token.Token in place before passing doc to displacy #12432
-
Hi, I need to apply dependency parsing on list of tokens that have been assigned POS tags in advance. Since passing tokens with their tags attached to them (e.g. in the form of "take_VB") directly to the parser would not get me the correct results, I have to split tokens and tags ("take", "_VB") and then pass the stripped tokens to the parser. After I get the parsed doc, I need to visualize the dependency relation of each sentence with displaCy. The problem now is: I want to put back tokens and tags so that the original text could be shown on the page generated by displaCy. I tried to modify Token.text one by one (I want to keep Token.tag_ and Token.pos_ intact), but get: AttributeError: attribute 'text' of 'spacy.tokens.token.Token' objects is not writable. So, is there an easy way to forcibly rewrite/modify the text of each token in the generated doc? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Found displacy.parse_deps which seems to be a good option, so I can simply modify dict attributes instead of the generated HTML. |
Beta Was this translation helpful? Give feedback.
Found displacy.parse_deps which seems to be a good option, so I can simply modify dict attributes instead of the generated HTML.