NewsSentiment


NameNewsSentiment JSON
Version 1.2.28 PyPI version JSON
download
home_pagehttps://github.com/fhamborg/NewsMTSC
SummaryEasy-to-use, high-quality target-dependent sentiment classification for English news articles
upload_time2023-12-20 16:16:55
maintainer
docs_urlNone
authorFelix Hamborg
requires_python<3.12,>=3.8
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # NewsSentiment: easy-to-use, high-quality target-dependent sentiment classification for news articles
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](https://aclanthology.org/2021.eacl-main.142.pdf) 
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](https://aclanthology.org/2021.eacl-main.142.pdf). The
dataset, the model, and its source code can be viewed in our [GitHub repository](https://github.com/fhamborg/NewsMTSC).

# Installation
It's super easy, we promise! 

You just need a Python 3.8 environment. See [here](https://raw.githubusercontent.com/fhamborg/NewsMTSC/main/pythoninfo.md) if you 
don't have Python or a different version (run `python --version` in a terminal to see 
your version). Then run:

```bash
pip3 install NewsSentiment        # without cuda support (choose this if you don't know what cuda is)
pip3 install NewsSentiment[cuda]  # with cuda support
```

You're all set now :-)

# Target-dependent Sentiment Classification

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.

```python
from NewsSentiment import TargetSentimentClassifier
tsc = TargetSentimentClassifier()

data = [
    ("I like ", "Peter", " but I don't like Robert."),
    ("", "Mark Meadows", "'s coverup of Trump’s coup attempt is falling apart."),
]

sentiments = tsc.infer(targets=data)

for i, result in enumerate(sentiments):
    print("Sentiment: ", i, result[0])
```

This method will internally split the data into batches of size 16 for increased speed. You can adjust the
batch size using the `batch_size` parameter, e.g., `batch_size=32`.

Alternatively, you can also use the `infer_from_text` method to infer sentiment for a single target:

```python
sentiment = tsc.infer_from_text("I like " ,"Peter", " but I don't like Robert.")
print(sentiment[0])
```

# How to identify a person in a sentence?

In case your data is not separated as shown in the examples above, i.e., in three segments, you will need to identify one (or more) targets first.
How this is done best depends on your project and analysis task but you may, for example, use NER. This [example](https://github.com/fhamborg/NewsMTSC/issues/30#issuecomment-1700645679) shows a simple way of doing so.

# Acknowledgements

Thanks to [Tilman Hornung](https://github.com/t1h0) for adding the batching functionality and various other improvements.

# How to cite
If you use the dataset or model, please cite our [paper](https://www.aclweb.org/anthology/2021.eacl-main.142/) ([PDF](https://www.aclweb.org/anthology/2021.eacl-main.142.pdf)):

```
@InProceedings{Hamborg2021b,
  author    = {Hamborg, Felix and Donnay, Karsten},
  title     = {NewsMTSC: (Multi-)Target-dependent Sentiment Classification in News Articles},
  booktitle = {Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics (EACL 2021)},
  year      = {2021},
  month     = {Apr.},
  location  = {Virtual Event},
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fhamborg/NewsMTSC",
    "name": "NewsSentiment",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<3.12,>=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Felix Hamborg",
    "author_email": "felix.hamborg@uni-konstanz.de",
    "download_url": "https://files.pythonhosted.org/packages/d1/64/ae206dd6e24c0da623ec1ef6f51653361cb6d8683b980563c4fdfa92d68c/NewsSentiment-1.2.28.tar.gz",
    "platform": null,
    "description": "# NewsSentiment: easy-to-use, high-quality target-dependent sentiment classification for news articles\nNewsSentiment is an easy-to-use Python library that achieves state-of-the-art performance\nfor target-dependent sentiment classification on news articles.\nNewsSentiment uses the currently [best performing](https://aclanthology.org/2021.eacl-main.142.pdf) \ntargeted sentiment classifier for news articles. In contrast to regular sentiment\nclassification, targeted sentiment classification allows you to provide a target in a sentence. \nOnly for this target, the sentiment is then predicted. This is more reliable in many\ncases, as demonstrated by the following simplistic example: \"I like Bert, but I hate Robert.\"\n\nWe designed NewsSentiment to serve as an easy-to-use wrapper around the sophisticated\nGRU-TSC model, which was trained on the NewsMTSC dataset consisting of more than 10k \nlabeled sentences sampled from political news articles. More information on the dataset \nand the model can be found [here](https://aclanthology.org/2021.eacl-main.142.pdf). The\ndataset, the model, and its source code can be viewed in our [GitHub repository](https://github.com/fhamborg/NewsMTSC).\n\n# Installation\nIt's super easy, we promise! \n\nYou just need a Python 3.8 environment. See [here](https://raw.githubusercontent.com/fhamborg/NewsMTSC/main/pythoninfo.md) if you \ndon't have Python or a different version (run `python --version` in a terminal to see \nyour version). Then run:\n\n```bash\npip3 install NewsSentiment        # without cuda support (choose this if you don't know what cuda is)\npip3 install NewsSentiment[cuda]  # with cuda support\n```\n\nYou're all set now :-)\n\n# Target-dependent Sentiment Classification\n\nNote that using NewsSentiment the first time will take *a few minutes* because it needs\nto download the fine-tuned language model. Please do not abort this initial download. \nSince this is a one-time process, future use of NewsSentiment will be much faster.\n\n```python\nfrom NewsSentiment import TargetSentimentClassifier\ntsc = TargetSentimentClassifier()\n\ndata = [\n    (\"I like \", \"Peter\", \" but I don't like Robert.\"),\n    (\"\", \"Mark Meadows\", \"'s coverup of Trump\u2019s coup attempt is falling apart.\"),\n]\n\nsentiments = tsc.infer(targets=data)\n\nfor i, result in enumerate(sentiments):\n    print(\"Sentiment: \", i, result[0])\n```\n\nThis method will internally split the data into batches of size 16 for increased speed. You can adjust the\nbatch size using the `batch_size` parameter, e.g., `batch_size=32`.\n\nAlternatively, you can also use the `infer_from_text` method to infer sentiment for a single target:\n\n```python\nsentiment = tsc.infer_from_text(\"I like \" ,\"Peter\", \" but I don't like Robert.\")\nprint(sentiment[0])\n```\n\n# How to identify a person in a sentence?\n\nIn case your data is not separated as shown in the examples above, i.e., in three segments, you will need to identify one (or more) targets first.\nHow this is done best depends on your project and analysis task but you may, for example, use NER. This [example](https://github.com/fhamborg/NewsMTSC/issues/30#issuecomment-1700645679) shows a simple way of doing so.\n\n# Acknowledgements\n\nThanks to [Tilman Hornung](https://github.com/t1h0) for adding the batching functionality and various other improvements.\n\n# How to cite\nIf you use the dataset or model, please cite our [paper](https://www.aclweb.org/anthology/2021.eacl-main.142/) ([PDF](https://www.aclweb.org/anthology/2021.eacl-main.142.pdf)):\n\n```\n@InProceedings{Hamborg2021b,\n  author    = {Hamborg, Felix and Donnay, Karsten},\n  title     = {NewsMTSC: (Multi-)Target-dependent Sentiment Classification in News Articles},\n  booktitle = {Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics (EACL 2021)},\n  year      = {2021},\n  month     = {Apr.},\n  location  = {Virtual Event},\n}\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Easy-to-use, high-quality target-dependent sentiment classification for English news articles",
    "version": "1.2.28",
    "project_urls": {
        "Bug Tracker": "https://github.com/fhamborg/NewsMTSC/issues",
        "Homepage": "https://github.com/fhamborg/NewsMTSC"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed2da27a9b0cec5f06b0d20ea38f48c8c1948aa0d26fdbe2e4e058decea67e98",
                "md5": "54982fe29d2501371fc2b7f793649450",
                "sha256": "5a0e695a521b69a7535de7e12b06fb17a0e70d19d8afb9e49ff7a5fb783f516d"
            },
            "downloads": -1,
            "filename": "NewsSentiment-1.2.28-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "54982fe29d2501371fc2b7f793649450",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.12,>=3.8",
            "size": 919016,
            "upload_time": "2023-12-20T16:16:52",
            "upload_time_iso_8601": "2023-12-20T16:16:52.971132Z",
            "url": "https://files.pythonhosted.org/packages/ed/2d/a27a9b0cec5f06b0d20ea38f48c8c1948aa0d26fdbe2e4e058decea67e98/NewsSentiment-1.2.28-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d164ae206dd6e24c0da623ec1ef6f51653361cb6d8683b980563c4fdfa92d68c",
                "md5": "6bff3466d58976cf4e942043a06db2af",
                "sha256": "f26da590b3bad6f63225668c2eaf63e1dcae8c1923f81e4fa3082935ef5141e9"
            },
            "downloads": -1,
            "filename": "NewsSentiment-1.2.28.tar.gz",
            "has_sig": false,
            "md5_digest": "6bff3466d58976cf4e942043a06db2af",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.12,>=3.8",
            "size": 889305,
            "upload_time": "2023-12-20T16:16:55",
            "upload_time_iso_8601": "2023-12-20T16:16:55.006724Z",
            "url": "https://files.pythonhosted.org/packages/d1/64/ae206dd6e24c0da623ec1ef6f51653361cb6d8683b980563c4fdfa92d68c/NewsSentiment-1.2.28.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-20 16:16:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fhamborg",
    "github_project": "NewsMTSC",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "newssentiment"
}
        
Elapsed time: 0.14933s