social-tools


Namesocial-tools JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/instabaines/social_tools_lib/
SummaryThe goal is to provide a unified interface to interact with various social analysis tools
upload_time2024-10-13 02:46:02
maintainerNone
docs_urlNone
authorRidwan Amure
requires_python>=3.10.0
licenseMIT
keywords social tools sentiment analysis toxicity emotion analysis
VCS
bugtrack_url
requirements numpy transformers detoxify pytest textblob spacy spacytextblob nltk
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Social Tools

## Overview

The **Social Tools** library provides a unified interface for interacting with various social analysis tools, including sentiment analysis, toxicity detection, emotion detection, and other natural language processing (NLP) models. With this library, developers can quickly analyze social media text, chat messages, or other forms of unstructured data for toxicity, sentiment, emotions, and more.

### Key Features

- **Sentiment Analysis**: Determine whether the text expresses positive, negative, or neutral sentiment.
- **Toxicity Detection**: Identify toxic language, hate speech, offensive comments, and inappropriate content.
- **Emotion Detection**: Recognize emotions such as happiness, sadness, anger, and more.
- **Custom NLP Models**: Integrate additional NLP models for detecting bias, misinformation, and other social signals.

## Installation

To install Social Tools, run:

```bash
pip install social-tools
```

## Usage

### Import the Modules

```python
from social_tools import EmotionDetection, SentimentAnalysis, ToxicityDetection
```

## Toxicity Detection

The **ToxicityDetection** module allows you to analyze text for toxic comments using pre-trained models like HuggingFace's `unitary/toxic-bert`.

```python
# Using the unitary/toxic-bert transformer model
tox_detector = ToxicityDetection(tool='transformer', model='unitary/toxic-bert')
result = tox_detector.analyze("I hate you.")
print(result)
```

This returns:

```python
[{'label': 'toxic', 'score': 0.9475088119506836}]
```

You can also analyze multiple texts at once:

```python
tox_detector.analyze(["I hate you.", "This is harsh"])
```

Output:

```python
[
    {'label': 'toxic', 'score': 0.9475088119506836},
    {'label': 'toxic', 'score': 0.002488125581294298}
]
```

## Sentiment Analysis

The **SentimentAnalysis** module offers several options for analyzing the sentiment of text, including NLTK, SpaCy, and HuggingFace models.

```python
# Using NLTK
sa = SentimentAnalysis(tool='nltk')
result = sa.analyze("This is awesome!")
print(result)
```

Output:

```python
[{'neg': 0.0, 'neu': 0.313, 'pos': 0.687, 'compound': 0.6588}]
```

### Using SpaCy:

```python
sa = SentimentAnalysis(tool='spacy')
result = sa.analyze("This is awesome!")
print(result)
```

Output:

```python
[{
    'polarity': 1.0, 
    'subjectivity': 1.0, 
    'sentiment_assessments': [(['awesome', '!'], 1.0, 1.0, None)]
}]
```

### Using HuggingFace Transformer:

```python
sa = SentimentAnalysis(tool='huggingface')
result = sa.analyze("This is awesome!")
print(result)
```

Output:

```python
[{'label': 'POSITIVE', 'score': 0.9998669624328613}]
```

#### Custom HuggingFace Models

You can specify a custom HuggingFace transformer model by passing the model name during initialization:

```python
sa = SentimentAnalysis(tool='huggingface', transformer_model="cardiffnlp/twitter-roberta-base-sentiment-latest")
result = sa.analyze("This is awesome!")
print(result)
```

Output:

```python
[{'label': 'positive', 'score': 0.9813949465751648}]
```

## Emotion Detection

The **EmotionDetection** module allows you to detect emotions such as happiness, sadness, and anger. For example, using HuggingFace models:

```python
emotion_detector = EmotionDetection(tool='huggingface')
result = emotion_detector.analyze("I am so happy today!")
print(result)
```

This will return:

```python
[{'label': 'joy', 'score': 0.95}]
```

## Flexible Input Handling

All `analyze` functions in each module accept both single strings (`str`) and lists of strings (`List[str]`) as input:

```python
# Single input
result = sa.analyze("I love this!")

# Multiple inputs
result = sa.analyze(["I love this!", "This is terrible."])
```

### HuggingFace Transformer Parameters

When using a HuggingFace transformer model, you can pass additional parameters during initialization, such as `return_all_scores`:

```python
sa = SentimentAnalysis(tool='huggingface', transformer_model="bert-base-uncased", return_all_scores=True)
result = sa.analyze("This is fantastic!")
print(result)
```

## Conclusion

The Social Tools library simplifies the process of analyzing social data by providing multiple sentiment, emotion, and toxicity detection tools in a unified interface. You can integrate popular NLP libraries like NLTK, SpaCy, and HuggingFace models into your workflow seamlessly.

For more information about the supported HuggingFace models and additional parameters, refer to the [HuggingFace documentation](https://huggingface.co/models).

## Acknowledgements

This project would not have been possible without the contributions of the following open-source projects:

- **[Detoxify](https://github.com/unitaryai/detoxify)**: For providing pre-trained models to detect toxic content in text.
- **[HuggingFace](https://huggingface.co/)**: For providing a wide variety of pre-trained transformer models and their powerful `transformers` library.
- **[NLTK (Natural Language Toolkit)](https://www.nltk.org/)**: For providing robust tools for text processing and sentiment analysis.
- **[SpaCy](https://spacy.io/)**: For offering fast and efficient NLP capabilities, along with the `spacytextblob` extension for sentiment analysis.
- **[TextBlob](https://textblob.readthedocs.io/en/dev/)**: For providing an easy-to-use interface for text processing, sentiment analysis, and other NLP tasks.

A huge thank you to these projects and their respective communities for building the foundational tools that made this library possible.

## Citation

```markdown
@misc{socialtool,
  title={socialtool},
  author={Ridwan Amure},
  howpublished={Github. https://github.com/instabaines/social_tools_lib/},
  year={2024}
}
```

if you use the detoxify  module in this tool, kindly cite

```markdown
@misc{Detoxify,
  title={Detoxify},
  author={Hanu, Laura and {Unitary team}},
  howpublished={Github. https://github.com/unitaryai/detoxify},
  year={2020}
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/instabaines/social_tools_lib/",
    "name": "social-tools",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10.0",
    "maintainer_email": null,
    "keywords": "social tools, sentiment analysis, toxicity, emotion analysis",
    "author": "Ridwan Amure",
    "author_email": "amureridwan002@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ad/cf/32b560de4e976b8eb5266726d54a17a4fe60ae7d71ff0e87031545b2ee0f/social_tools-1.0.0.tar.gz",
    "platform": null,
    "description": "\r\n# Social Tools\r\n\r\n## Overview\r\n\r\nThe **Social Tools** library provides a unified interface for interacting with various social analysis tools, including sentiment analysis, toxicity detection, emotion detection, and other natural language processing (NLP) models. With this library, developers can quickly analyze social media text, chat messages, or other forms of unstructured data for toxicity, sentiment, emotions, and more.\r\n\r\n### Key Features\r\n\r\n- **Sentiment Analysis**: Determine whether the text expresses positive, negative, or neutral sentiment.\r\n- **Toxicity Detection**: Identify toxic language, hate speech, offensive comments, and inappropriate content.\r\n- **Emotion Detection**: Recognize emotions such as happiness, sadness, anger, and more.\r\n- **Custom NLP Models**: Integrate additional NLP models for detecting bias, misinformation, and other social signals.\r\n\r\n## Installation\r\n\r\nTo install Social Tools, run:\r\n\r\n```bash\r\npip install social-tools\r\n```\r\n\r\n## Usage\r\n\r\n### Import the Modules\r\n\r\n```python\r\nfrom social_tools import EmotionDetection, SentimentAnalysis, ToxicityDetection\r\n```\r\n\r\n## Toxicity Detection\r\n\r\nThe **ToxicityDetection** module allows you to analyze text for toxic comments using pre-trained models like HuggingFace's `unitary/toxic-bert`.\r\n\r\n```python\r\n# Using the unitary/toxic-bert transformer model\r\ntox_detector = ToxicityDetection(tool='transformer', model='unitary/toxic-bert')\r\nresult = tox_detector.analyze(\"I hate you.\")\r\nprint(result)\r\n```\r\n\r\nThis returns:\r\n\r\n```python\r\n[{'label': 'toxic', 'score': 0.9475088119506836}]\r\n```\r\n\r\nYou can also analyze multiple texts at once:\r\n\r\n```python\r\ntox_detector.analyze([\"I hate you.\", \"This is harsh\"])\r\n```\r\n\r\nOutput:\r\n\r\n```python\r\n[\r\n    {'label': 'toxic', 'score': 0.9475088119506836},\r\n    {'label': 'toxic', 'score': 0.002488125581294298}\r\n]\r\n```\r\n\r\n## Sentiment Analysis\r\n\r\nThe **SentimentAnalysis** module offers several options for analyzing the sentiment of text, including NLTK, SpaCy, and HuggingFace models.\r\n\r\n```python\r\n# Using NLTK\r\nsa = SentimentAnalysis(tool='nltk')\r\nresult = sa.analyze(\"This is awesome!\")\r\nprint(result)\r\n```\r\n\r\nOutput:\r\n\r\n```python\r\n[{'neg': 0.0, 'neu': 0.313, 'pos': 0.687, 'compound': 0.6588}]\r\n```\r\n\r\n### Using SpaCy:\r\n\r\n```python\r\nsa = SentimentAnalysis(tool='spacy')\r\nresult = sa.analyze(\"This is awesome!\")\r\nprint(result)\r\n```\r\n\r\nOutput:\r\n\r\n```python\r\n[{\r\n    'polarity': 1.0, \r\n    'subjectivity': 1.0, \r\n    'sentiment_assessments': [(['awesome', '!'], 1.0, 1.0, None)]\r\n}]\r\n```\r\n\r\n### Using HuggingFace Transformer:\r\n\r\n```python\r\nsa = SentimentAnalysis(tool='huggingface')\r\nresult = sa.analyze(\"This is awesome!\")\r\nprint(result)\r\n```\r\n\r\nOutput:\r\n\r\n```python\r\n[{'label': 'POSITIVE', 'score': 0.9998669624328613}]\r\n```\r\n\r\n#### Custom HuggingFace Models\r\n\r\nYou can specify a custom HuggingFace transformer model by passing the model name during initialization:\r\n\r\n```python\r\nsa = SentimentAnalysis(tool='huggingface', transformer_model=\"cardiffnlp/twitter-roberta-base-sentiment-latest\")\r\nresult = sa.analyze(\"This is awesome!\")\r\nprint(result)\r\n```\r\n\r\nOutput:\r\n\r\n```python\r\n[{'label': 'positive', 'score': 0.9813949465751648}]\r\n```\r\n\r\n## Emotion Detection\r\n\r\nThe **EmotionDetection** module allows you to detect emotions such as happiness, sadness, and anger. For example, using HuggingFace models:\r\n\r\n```python\r\nemotion_detector = EmotionDetection(tool='huggingface')\r\nresult = emotion_detector.analyze(\"I am so happy today!\")\r\nprint(result)\r\n```\r\n\r\nThis will return:\r\n\r\n```python\r\n[{'label': 'joy', 'score': 0.95}]\r\n```\r\n\r\n## Flexible Input Handling\r\n\r\nAll `analyze` functions in each module accept both single strings (`str`) and lists of strings (`List[str]`) as input:\r\n\r\n```python\r\n# Single input\r\nresult = sa.analyze(\"I love this!\")\r\n\r\n# Multiple inputs\r\nresult = sa.analyze([\"I love this!\", \"This is terrible.\"])\r\n```\r\n\r\n### HuggingFace Transformer Parameters\r\n\r\nWhen using a HuggingFace transformer model, you can pass additional parameters during initialization, such as `return_all_scores`:\r\n\r\n```python\r\nsa = SentimentAnalysis(tool='huggingface', transformer_model=\"bert-base-uncased\", return_all_scores=True)\r\nresult = sa.analyze(\"This is fantastic!\")\r\nprint(result)\r\n```\r\n\r\n## Conclusion\r\n\r\nThe Social Tools library simplifies the process of analyzing social data by providing multiple sentiment, emotion, and toxicity detection tools in a unified interface. You can integrate popular NLP libraries like NLTK, SpaCy, and HuggingFace models into your workflow seamlessly.\r\n\r\nFor more information about the supported HuggingFace models and additional parameters, refer to the [HuggingFace documentation](https://huggingface.co/models).\r\n\r\n## Acknowledgements\r\n\r\nThis project would not have been possible without the contributions of the following open-source projects:\r\n\r\n- **[Detoxify](https://github.com/unitaryai/detoxify)**: For providing pre-trained models to detect toxic content in text.\r\n- **[HuggingFace](https://huggingface.co/)**: For providing a wide variety of pre-trained transformer models and their powerful `transformers` library.\r\n- **[NLTK (Natural Language Toolkit)](https://www.nltk.org/)**: For providing robust tools for text processing and sentiment analysis.\r\n- **[SpaCy](https://spacy.io/)**: For offering fast and efficient NLP capabilities, along with the `spacytextblob` extension for sentiment analysis.\r\n- **[TextBlob](https://textblob.readthedocs.io/en/dev/)**: For providing an easy-to-use interface for text processing, sentiment analysis, and other NLP tasks.\r\n\r\nA huge thank you to these projects and their respective communities for building the foundational tools that made this library possible.\r\n\r\n## Citation\r\n\r\n```markdown\r\n@misc{socialtool,\r\n  title={socialtool},\r\n  author={Ridwan Amure},\r\n  howpublished={Github. https://github.com/instabaines/social_tools_lib/},\r\n  year={2024}\r\n}\r\n```\r\n\r\nif you use the detoxify  module in this tool, kindly cite\r\n\r\n```markdown\r\n@misc{Detoxify,\r\n  title={Detoxify},\r\n  author={Hanu, Laura and {Unitary team}},\r\n  howpublished={Github. https://github.com/unitaryai/detoxify},\r\n  year={2020}\r\n}\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "The goal is to provide a unified interface to interact with various social analysis tools",
    "version": "1.0.0",
    "project_urls": {
        "Download": "https://github.com/instabaines/social_tools_lib/archive/refs/tags/1.0.0.tar.gz",
        "Homepage": "https://github.com/instabaines/social_tools_lib/"
    },
    "split_keywords": [
        "social tools",
        " sentiment analysis",
        " toxicity",
        " emotion analysis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "adcf32b560de4e976b8eb5266726d54a17a4fe60ae7d71ff0e87031545b2ee0f",
                "md5": "888ed48d515fd7b26062eecf30f32d25",
                "sha256": "67b717b6df6a8501c06a866c741e5c9fc19a14a8ecee22c9d46f1cd9be275e1e"
            },
            "downloads": -1,
            "filename": "social_tools-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "888ed48d515fd7b26062eecf30f32d25",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10.0",
            "size": 10835,
            "upload_time": "2024-10-13T02:46:02",
            "upload_time_iso_8601": "2024-10-13T02:46:02.076853Z",
            "url": "https://files.pythonhosted.org/packages/ad/cf/32b560de4e976b8eb5266726d54a17a4fe60ae7d71ff0e87031545b2ee0f/social_tools-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-13 02:46:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "instabaines",
    "github_project": "social_tools_lib",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "numpy",
            "specs": [
                [
                    "==",
                    "1.26.4"
                ]
            ]
        },
        {
            "name": "transformers",
            "specs": []
        },
        {
            "name": "detoxify",
            "specs": []
        },
        {
            "name": "pytest",
            "specs": [
                [
                    ">=",
                    "6.0"
                ]
            ]
        },
        {
            "name": "textblob",
            "specs": [
                [
                    ">=",
                    "0.15.3"
                ]
            ]
        },
        {
            "name": "spacy",
            "specs": [
                [
                    ">=",
                    "3.7.4"
                ]
            ]
        },
        {
            "name": "spacytextblob",
            "specs": [
                [
                    ">=",
                    "4.0.0"
                ]
            ]
        },
        {
            "name": "nltk",
            "specs": [
                [
                    ">=",
                    "3.8.1"
                ]
            ]
        }
    ],
    "lcname": "social-tools"
}
        
Elapsed time: 4.81713s