knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
NewsSentiment is an easy-to-use Python library that achieves state-of-the-art performance for target-dependent sentiment classification on news articles. NewsSentiment uses the currently best performing targeted sentiment classifier for news articles. In contrast to regular sentiment classification, targeted sentiment classification allows you to provide a target in a sentence. Only for this target, the sentiment is then predicted. This is more reliable in many cases, as demonstrated by the following simplistic example: "I like Bert, but I hate Robert."
We designed NewsSentiment to serve as an easy-to-use wrapper around the sophisticated GRU-TSC model, which was trained on the NewsMTSC dataset consisting of more than 10k labeled sentences sampled from political news articles. More information on the dataset and the model can be found here. The dataset, the model, and its source code can be viewed in our GitHub repository.
During the installation process. Python in the version 3.7.9 will be downloaded onto your computer. This is necessary since the python package that NewsSentiment is based on requires a virtual enviroment using python 3.7.
library(NewsSentiment)
Note that using NewsSentiment the first time will take a few minutes because it needs to download the fine-tuned language model. Please do not abort this initial download. Since this is a one-time process, future use of NewsSentiment will be much faster.
#sentiment <- infer_from_text("I like ", "Peter", " but I don't like Robert.") #print(sentiment[0])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.