multi-language-sentiment
A pipeline for sentiment analysis for texts with unknown language.
We use the lingua-language-detector to detect the language and run the text samples through an sentiment analysis appropriate pipeline for that language.
Usage
Basic usage for analysing a list of sentences:
import multi_language_sentiment
texts = ["This is a positive sentence", "Tämä on ikävä juttu"]
sentiments = multi_language_sentiment.sentiment(texts)
print(sentiments)
This should print
[{'label': 'positive', 'score': 0.89024418592453}, {'label': 'negative', 'score': 0.8899219632148743}]
Supported language
The module currently supports the following langauges by default: English, Japanese, Arabic, German, Spanish, French, Chinese, Indonesian, Hindi, Italian, Malay, Portuguese, Swedish, and Finnish.
For other languages, you must supply a path for a HuggingFace sentiment analysis pipeline. To supply a pipelien for a new language, use the models parameter:
import multi_language_sentiment
from lingua import Language
texts = ["This is a positive sentence", "Tämä on ikävä juttu"]
models = {Language.FINNISH: "fergusq/finbert-finnsentiment"}
sentiments = multi_language_sentiment.sentiment(texts, models = models)
Technical details
Note that the pipeline will split each text sample to a maximum length of 512 characters. The sentiments are aggregated by adding up the scores and taking the largest value.
Metadata
Release files for multi_language_sentiment 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| multi_language_sentiment-0.1.0.tar.gz | 5.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| multi_language_sentiment-0.1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 10.3 kB
Release files / multi_language_sentiment-0.1.0.tar.gz
| Download URL | multi_language_sentiment-0.1.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e96c417811065fc5e05e783e1fd8117a15e269a1190085f1cf1005626da5d25c
|
|
BLAKE2b-256 checksum How to use checksums |
74e3d5abd32bf27be9ea3ec1ee0e8d64b0f9cccaa3ea48fca4a06d5151a251fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Release files / multi_language_sentiment-0.1.0-py2.py3-none-any.whl
| Download URL | multi_language_sentiment-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a890212e50a15fa9d002cf262839aff08f7631277f1fdb44a0f185af3f08de18
|
|
BLAKE2b-256 checksum How to use checksums |
744f59f75bd5831d6d4e7e73f013744e662ed9898fc67f71f31249ca4bb5155c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|