Sentiment analysis plugins can also be evaluated on a series of pre-defined datasets. This can be done in three ways: through the Web UI (playground), through the web API and programmatically.
Regardless of the way you perform the evaluation, you will need to specify a plugin (service) that you want to evaluate, and a series of datasets on which it should be evaluated.
to evaluate a plugin on a dataset, senpy use the plugin to predict the sentiment in each entry in the dataset. These predictions are compared with the expected values to produce several metrics, such as: accuracy, precision and f1-score.
note: the evaluation process might take long for plugins that use external services, such as sentiment140
.
note: plugins are assumed to be pre-trained and invariant. i.e., the prediction for an entry should
The playground should contain a tab for Evaluation, where you can select any plugin that can be evaluated, and the set of datasets that you want to test the plugin on.
For example, the image below shows the results of the sentiment-vader
plugin on the vader
and sts
datasets:
The api exposes an endpoint (/evaluate
), which accents the plugin and the set of datasets on which it should be evaluated.
The following code is not necessary, but it will display the results better:
Here is a simple call using the requests library:
In [2]:
import requests
from IPython.display import Code
endpoint = 'http://senpy.gsi.upm.es/api'
res = requests.get(f'{endpoint}/evaluate',
params={"algo": "sentiment-vader",
"dataset": "vader,sts",
'outformat': 'json-ld'
})
Code(res.text, language='json')
Out[2]:
A third option is to evaluate plugins manually without launching the server.
This option is particularly interesting for advanced users that want faster iterations and evaluation results, and for automation.
We would first need an instance of a plugin. In this example we will use the Sentiment140 plugin that is included in every senpy installation:
In [22]:
from senpy.plugins.sentiment import sentiment140_plugin
In [23]:
s140 = sentiment140_plugin.Sentiment140()
Then, we need to know what datasets are available. We can list all datasets and basic stats (e.g., number of instances and labels used) like this:
In [32]:
from senpy.gsitk_compat import datasets
for k, d in datasets.items():
print(k, d['stats'])
Now, we will evaluate our plugin in one of the smallest datasets, sts
:
In [37]:
s140.evaluate(['sts', ])
Out[37]:
In [ ]: