Package: zensols.spanmatch
Unsupervised Position-Based Semantic MatchingAn API to match spans of semantically similar text across documents.  Each
match is a span of text in a source document and another span of text in a
target document that are both tied together.Table of ContentsIntroductionDocumentationUsageCitationObtainingChangelogLicenseIntroductionSpans are formed by a weighted combination of the semantic similarity of the
each document's text and the token position.  Hyperparameters are used to
control which take precedent (semantic similarity or token position for longer
contiguous token spans).This is done using position embeddings on a third (see Figure 1) axis shows
data blue word embeddings moving from cluster 1 to cluster 2. Cluster spans the
discharge summaries (orange), the note antecedent (green) and arrows connecting
the tokens to word points.Figure 1For more information, see "Hybrid Semantic Positional Token Clustering" in our
paperHospital Discharge Summarization Data Provenance.DocumentationSee thefull documentation.
TheAPI referenceis also
available.Usagefromzensols.cliimportCliHarnessfromzensols.nlpimportFeatureDocument,FeatureDocumentParserfromzensols.spanmatchimportMatch,MatchResult,Matcher,ApplicationFactorySOURCE="""\Johannes Gutenberg (1398 – 1468) was a German goldsmith and publisher whointroduced printing to Europe. His introduction of mechanical movable typeprinting to Europe started the Printing Revolution and is widely regarded as themost important event of the modern period. It played a key role in thescientific revolution and laid the basis for the modern knowledge-based economyand the spread of learning to the masses.Gutenberg many contributions to printing are: the invention of a process formass-producing movable type, the use of oil-based ink for printing books,adjustable molds, and the use of a wooden printing press. His truly epochalinvention was the combination of these elements into a practical system thatallowed the mass production of printed books and was economically viable forprinters and readers alike."""SUMMARY="""\The German Johannes Gutenberg introduced printing in Europe. His invention had adecisive contribution in spread of mass-learning and in building the basis ofthe modern society."""harness:CliHarness=ApplicationFactory.create_harness()doc_parser:FeatureDocumentParser=harness['spanmatch_doc_parser']matcher:Matcher=harness['spanmatch_matcher']source:FeatureDocument=doc_parser(SOURCE)summary:FeatureDocument=doc_parser(SUMMARY)# shorten source doc span length by scaling up positional importancematcher.hyp.source_position_scale=2.5# elongate summary doc span length by scaling up positional importancematcher.hyp.target_position_scale=0.9res:MatchResult=matcher(source,summary)match:Matchfori,matchinenumerate(res.matches[:5]):match.write(include_flow=False)Output:2023-06-1108:22:38,39224matchesfoundsource(0,55):JohannesGutenberg(1398–1468)wasaGermangoldsmithtarget(4,29):GermanJohannesGutenbergsource(524,631):type,theuseofoil-basedinkforprintingbooks,adjustablemolds,andtheuseofawoodenprintingpresstarget(4,59):GermanJohannesGutenbergintroducedprintinginEuropesource(301,421):scientificrevolutionandlaidthebasisforthemodernknowledge-basedeconomyandthespreadoflearningtothemassestarget(106,177):spreadofmass-learningandinbuildingthebasisofthemodernsocietysource(516,585):movabletype,theuseofoil-basedinkforprintingbooks,adjustabletarget(116,169):mass-learningandinbuildingthebasisofthemodernsource(168,199):startedthePrintingRevolutiontarget(106,145):spreadofmass-learningandinbuildingObtainingThe easiest way to install the command line program is via thepipinstaller:pip3install--use-deprecated=legacy-resolverzensols.spanmatchBinaries are also available onpypi.CitationIf you use this project in your research please use the following BibTeX entry:@inproceedings{landes-etal-2023-dsprov,title="{{Hospital Discharge Summarization Data Provenance}}",author="Landes, Paul  andChaise, Aaron J.  andPatel, Kunal P. andHuang, Sean S.  andDi Eugenio, Barbara",booktitle="Proceedings of the 21st {{Workshop}} on {{Biomedical Language Processing}}",month=jul,year="2023",day=9,address="Toronto, Canada",publisher="{{Association for Computational Linguistics}}"}ChangelogAn extensive changelog is availablehere.LicenseMIT LicenseCopyright (c) 2023 Paul Landes