"* Annotating text with sentiment and emotion using interoperable services\n",
"* Switching to different services (service interoperability)\n",
"* Getting results in different formats (Turtle, XML, text...)\n",
"* Asking for specific emotion models (automatic model conversion)"
"* Asking for specific emotion models (automatic model conversion)\n",
"\n",
"The tutorial is originally published as an interactive [jupyter notebook](https://jupyter.org/) (`ipynb` file) that you can download and run locally.\n",
"The on-line documentation contains a **static** version of the notebook."
]
},
{
...
...
@@ -27,9 +30,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We will use the demo server at http://senpy.gsi.upm.es abd the requests library.\n",
"We will use the demo server at http://senpy.gsi.upm.es and the requests library.\n",
"\n",
"We will use a variable for our endpoint so you can try these examples on other instances:"
"We will use a variable for our endpoint.\n",
"To try these examples on other instances simply change the value of this variable and re-run the query:"
]
},
{
...
...
%% Cell type:markdown id: tags:
# Tutorial
This short tutorial will teach you how to consume senpy services for several tasks, and how to take advantage of the features of the framework.
In particular, it covers:
* Annotating text with sentiment and emotion using interoperable services
* Switching to different services (service interoperability)
* Getting results in different formats (Turtle, XML, text...)
* Asking for specific emotion models (automatic model conversion)
The tutorial is originally published as an interactive [jupyter notebook](https://jupyter.org/)(`ipynb` file) that you can download and run locally.
The on-line documentation contains a **static** version of the notebook.
%% Cell type:markdown id: tags:
## Requirements
%% Cell type:markdown id: tags:
We will use the demo server at http://senpy.gsi.upm.es abd the requests library.
We will use the demo server at http://senpy.gsi.upm.es and the requests library.
We will use a variable for our endpoint so you can try these examples on other instances:
We will use a variable for our endpoint.
To try these examples on other instances simply change the value of this variable and re-run the query:
%% Cell type:code id: tags:
``` python
endpoint='http://senpy.gsi.upm.es/api'
```
%% Cell type:markdown id: tags:
We will also add a little helper function (`query`) to simplify our queries and pretty-print the results with syntax highlighting:
%% Cell type:code id: tags:
``` python
importrequests
fromIPython.displayimportCode
defquery(endpoint,**kwargs):
'''Query a given Senpy endpoint with specific parameters, and prettify the output'''
As you can see, the structure and annotation schema of the response is the same.
This makes it very easy to compare and migrate to different services.
Service interoperability is not only useful for users.
It is also key for other features such as [automated evaluation](http://senpy.readthedocs.io/Evaluation.html).
This is a compelling reason to adapt existing services to use the Senpy API.
In fact, the `sentiment140` senpy service is proxy to the public [Sentiment 140 service](http://www.sentiment140.com/).
%% Cell type:markdown id: tags:
## Emotion analysis
%% Cell type:markdown id: tags:
Senpy uses the `onyx` vocabulary to represent emotions, which incorporates the notion of `EmotionSet`'s, an emotion that is composed of several emotions.
In a nutshell, an `Entry` is linked to one or more `EmotionSet`, which in turn is made up of one or more `Emotion`.
Let's illustrate it with an example, using the `emotion-depechemood` plugin.
Sometimes the model used by a plugin is not right for your application. Senpy ships with emotion conversion capabilities: you can ask for a specific emotion model in your request and the service will try to automatically convert the results.
For example, the `emotion-anew` plugin uses the dimensional `pad` (or VAD, valence-arousal-dominance) model, as we can see here:
%% Cell type:code id: tags:
``` python
query(f'{endpoint}/emotion-anew',
input="Senpy is a wonderful service and I love it")
[A separate notebook](Advanced.ipynb) covers advanced topics such as listing all plugins available in an endpoint, or creating analysis pipelines that chain several analysis services.
.. note:: This page has been auto-generated from a Jupyter notebook using nbsphinx_.
.. note:: This is an `auto-generated <https://nbsphinx.readthedocs.io>`_ static view of a Jupyter notebook.
The original source is available at: https://github.com/gsi-upm/senpy/tree/master/docs//{{ env.doc2path(env.docname, base=None) }}
To run the code examples in your computer, you may download the original notebook from the repository: https://github.com/gsi-upm/senpy/tree/master/docs/{{ env.doc2path(env.docname, base=None) }}