Perform Sentiment Analysis on Sentences
·
306 words
·
2 minutes read
Sentiment analysis is an interesting technique of judging whether a sentence, word or paragraph is considered a positive or negative thing. It’s often used against datasets like tweets as it allows you to summarize a mass of small sentences into an easy to understand stat.
In our example, we’re using a package called sentiment - which was trained against IMDB comment data - to judge whether our example sentences are positive or negative. Because it was trained on short comments about films it might not be appropriate for your use case.
Example Code:
|
|
The response of the SentimentAnalysis
method returns more data then is shown in the example (struct shown below). We’re just using the ‘Score’ of the whole string, but it has analysed each word within the sentence - which can be accessed in the ‘Words’ slice.
type Analysis struct {
Language Language `json:"lang"`
Words []Score `json:"words"`
Sentences []SentenceScore `json:"sentences,omitempty"`
Score uint8 `json:"score"`
}