Created
June 23, 2022 20:20
-
-
Save pmbaumgartner/31b0968a4e800bc43b0063e29cb74928 to your computer and use it in GitHub Desktop.
dependency matcher displacy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from spacy import displacy | |
from spacy.tokens import Doc | |
from spacy.util import get_lang_class | |
from pathlib import Path | |
words = ["The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "fox"] | |
heads = [3, 3, 3, 4, 4, 4, 8, 8, 5] | |
deps = ["det", "amod", "amod", "nsubj", "ROOT", "prep", "pobj", "det", "amod"] | |
doc = Doc(get_lang_class("en")().vocab, words=words, heads=heads, deps=deps) | |
html = displacy.render(doc) | |
output_path = Path("depdendencymatchertest.html") | |
output_path.open("w", encoding="utf-8").write(html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment