Apply a Model Component to Spans of a Doc as well as the Doc Itself #12699
Answered
by
rmitsch
benwebs
asked this question in
Help: Coding & Implementations
-
I am applying a HuggingFace sentiment classifier to the SpaCy Doc object using the following tutorial: https://github.com/explosion/spacy-huggingface-pipelines. This gives the sentiment for the document as a whole. My documents contain multiple sentences each and I would also like the sentiment at the sentence level, and for it to be saved as a custom attribute of the sentence in the Doc object. Can anyone assist with how this is possible? |
Beta Was this translation helpful? Give feedback.
Answered by
rmitsch
Jun 9, 2023
Replies: 1 comment 4 replies
-
Hi @benwebs, I suggest to:
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is no object that 1:1 represents a sentence in spaCy. There is information on where sentences begin, and
Span
objects that can be used to represent sentences.There are several options for this. One option, as suggested by @jkgenser, is to create
Span
objects for the sentences and using aSpan
extension to store the sentiment score for the corresponding sentence. Another one is to use aDoc
extension for a dict using sentence start/end indices as keys and the sentiment scores as values.