Repository navigation
spacyr 1.4.0 fixes two bugs that could affect results (input text was altered before reaching spaCy, and an error could leave the spaCy pipeline disabled), makes installation more robust, and adds spacy_installed() and a max_length argument to spacy_initialize().
Install from CRAN with install.packages("spacyr").
Changes that can affect results
spacy_parse(),spacy_tokenize(),spacy_extract_entity()andspacy_extract_nounphrases()no longer alter the input text. Previously they deleted all backslashes and converted the literal sequences\nand\tinto newlines and tabs, so that for instanceC:\Userswas tokenized asC,:,Users. Code that relied on literal\nbeing converted should now convert it in R before calling spacyr.NAdocuments are now treated as empty documents, rather than as the text"NA".spacy_tokenize(what = "sentence", remove_separators = FALSE)now keeps trailing whitespace regardless of the value ofmultithread, including a single space after a sentence, so that the sentences join back into the original text.spacy_parse(nounphrase = TRUE)now returns rows in the order of the input documents, as it does without noun phrases, instead of sorted by document name. This fixes a bug where thewhitespacecolumn and anyadditional_attributeswere assigned to the wrong tokens when the document names were not in alphabetical order.
New features
- Added
spacy_installed(), which checks without starting Python whether spaCy and, optionally, given language models are installed (#197). - Added a
max_lengthargument tospacy_initialize()to allow documents longer than spaCy's default limit of 1,000,000 characters (#218).
Installation
spacy_install()now creates its environment with a version of Python supported by the spaCy release being installed, as declared on PyPI, rather than whichever Python is found first; if none is found, it offers to install a compatible one. For an existing environment whose Python is not supported, it stops with an error explaining how to recreate the environment, instead of failing during installation.spacy_initialize()now explains how to install a language model that cannot be found.- Fixed
spacy_download_langmodel()andspacy_install()not detecting already-installed language models with recent versions of pip (#258). - Fixed a bug in
spacy_download_langmodel()that prevented installing multiple models in one function call (#249). spacy_install()andspacy_upgrade()no longer fail on Windows when installing into a different environment after Python has been initialised in the session (#258).- Updated the installation instructions: language models are installed with
spacy_download_langmodel()rather than withpip(#253), and new sections cover changing the Python version, using an existing Python or conda environment (#246), using local models (#180) and the need for git on Windows (#245). The vignette no longer describes arguments that were removed fromspacy_initialize(). - Requires reticulate >= 1.31.
Bug fixes
- Fixed a bug where an error during
spacy_tokenize(), such as a text exceeding spaCy's maximum length, left the spaCy pipeline disabled, so that later calls in the same session failed or silently returned no entities. - Fixed a
SyntaxWarningabout an invalid escape sequence on Python 3.12+ when initialising spacyr (#257, thanks to @thjbdvlt). spacy_parse()no longer warns that lemmatization "may not work properly" for models whose name does not start with "en".spacy_parse()now returns a zero-row result with the usual columns and types when no document contains any tokens (for instance when all documents areNAor empty), instead of failing withdependency = TRUEor returning malformed columns.