使用位移可视化 NER 训练数据和实体

3 python spacy

我创建了一个用于训练 NER 数据的数据集。创建后,我想在应用于训练管道之前测试实体和数据是否匹配。使用置换,我们可以以更好的方式进行可视化。但在 spacy 3 中如何做到这一点呢?

小智 6

上述问题的代码如下

\n
import spacy\nfrom spacy import displacy\n\n\nannot_data = [('A Very SoNA Christmas\\nView SoNA\xe2\x80\x99s Covid Safety Policies\\nSkip to Content\\nAbout\\nHistory Mission\\nStaff Board\\nMusic Director\\nMusicians\\nSoNA Singers\\nAuditions\\nHire Ensembles\\nContact\\n2021-22 Season\\nSubscriber Series\\nTicketed Performances\\nSoNA Beyond Series\\nVirtual Performances\\nVirtual Performances\\nSolos from Home\\nSpecial Events\\nFireworks at the Farm\\nReimagined Celebration\\nDonate\\nGallery\\nEducation\\nBlog\\nOpen Menu\\nClose Menu\\nAbout\\nHistory Mission\\nStaff Board\\nMusic Director\\nMusicians\\nSoNA Singers\\nAuditions\\nHire Ensembles\\nContact\\n2021-22 Season\\nSubscriber Series\\nTicketed Performances\\nSoNA Beyond Series\\nVirtual Performances\\nVirtual Performances\\nSolos from Home\\nSpecial Events\\nFireworks at the Farm\\nReimagined Celebration\\nDonate\\nGallery\\nEducation\\nBlog\\nOpen Menu\\nClose Menu\\nFolder:\\nAbout\\nFolder:\\n2021-22 Season\\nSoNA Beyond Series\\nFolder:\\nVirtual Performances\\nFolder:\\nSpecial Events\\nDonate\\nGallery\\nEducation\\nBlog\\nBack\\nHistory Mission\\nStaff Board\\nMusic Director\\nMusicians\\nSoNA Singers\\nAuditions\\nHire Ensembles\\nContact\\nBack\\nSubscriber Series\\nTicketed Performances\\nBack\\nVirtual Performances\\nSolos from Home\\nBack\\nFireworks at the Farm\\nReimagined Celebration\\nA Very SoNA Christmas\\nJul 10, 2021\\nWritten By SoNA\\nSaturday, December 11, 2021 2PM 7:30PM Walton Arts Center, Fayetteville\\nA mix of sacred and secular holiday favorites with local guest soloists, The SoNA Singers, and area high school and collegiate choruses. Saturday, December 11, 2021 2PM Matinee Performance Saturday, December 11, 2021 7:30PM Evening Performance\\nBuy Tickets\\nBuy Tickets\\nSingle Tickets: 35, 45, 57 Under 18 FREE with purchase of adult ticket limited quantities Interested in a full season subscription Learn more here . Concert sponsored by Bogle Family Foundation\\nWe are committed to ensuring that audiences can experience music safely in person at our performances. Until further notice, patrons, staff, and volunteers are required to wear masks. Learn more about our safety policy here .\\nSoNA\\nPrevious\\nPrevious\\nMozart and Beethoven\\nNext\\nNext\\nSoNA Walton Arts Center present The Snowman: A Family Concert\\nReceive the latest updates\\nEmail Address\\nSign Up\\nThank you for joining our email list You should receive a verification email shortly to confirm.\\nOffice: 479.521.4166 Tickets: 479.443.5600 infosonamusic.org\\nCopyright 2021, SoNA. All rights reserved.\\nSupport SoNA',\n  {'entities': [(1958, 1962, 'organization'),\n    (1230, 1236, 'performance_starttime'),\n    (1343, 1359, 'organization'),\n    (1208, 1225, 'performance_date'),\n    (1237, 1255, 'auditorium'),\n    (0, 21, 'production_name'),\n    (1226, 1229, 'performance_starttime')]})]\n\nnlp = spacy.blank('en')\nraw_text = annot_data[0][0]\ndoc = nlp.make_doc(raw_text)\nspans = annot_data[0][1]["entities"]\nents = []\nfor span_start, span_end, label in spans:\n    ent = doc.char_span(span_start, span_end, label=label)\n    if ent is None:\n        continue\n\n    ents.append(ent)\n\ndoc.ents = ents\ndisplacy.render(doc, style="ent", jupyter=True)\n
Run Code Online (Sandbox Code Playgroud)\n