Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@christophe77/sentiment-js

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@christophe77/sentiment-js

SentimentsJS is build on to of **tensorflow js**. It allows you to add a sentiment analysis on your node or browser javascript app. With this package you'll be able to get the overall **sentiment** from a text and the **toxicity** classification.

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

sentimentJS

SentimentsJS is build on to of tensorflow js. It allows you to add a sentiment analysis on your node or browser javascript app. With this package you'll be able to get the overall sentiment from a text and the toxicity classification.

Installation

yarn add @christophe77/sentiment-js

or

npm install @christophe77/sentiment-js

How to use

the "analyse" function takes an object as parameter.

The object has 2 properties :

  • text : string
  • type : 'sentiment' | "toxicity" | "both" | "combined"

The function will return the result like this :

		{
			"sentiment": {
				"score": 0.9931357502937317,
				"result": "positive"
			},
			"toxicity": [
				{"label": "insult", "result": true},
				{"label": "toxicity","result": true},
				{.......}
			]
		}

property "label" can have those values :

  • identity_attack
  • insult
  • obscene
  • severe_toxicity
  • sexual_explicit
  • threat
  • toxicity

Exemple :

    import sjs from '@christophe77/sentiment-js';

    const checkThisText = async () => {
        // sentiment
	    const beerScore = await sjs.analyse({
		    text: 'I love cold beers',    
		    type: 'sentiment',    
	    });
	    console.log("'I love cold beers' : ", JSON.stringify(beerScore));

        // toxicity
	    const vegetableScore = await sjs.analyse({
		    text: 'I really hate those fucking vegetables',
		    type: 'toxicity',
		});
	    console.log("'I really hate those fucking vegetables' : ", JSON.stringify(vegetableScore));

        // both
	    const insultScore = await sjs.analyse({
		    text: 'You are just a fucking bitch. You just deserve to receive cum on your dirty shitty face',
		    type: 'both',
	    });
	    console.log( "'You are just a fucking bitch. You just deserve to receive cum on your dirty shitty face' : ",   JSON.stringify(insultScore) );

        // combined
	    const combinedScore = await sjs.analyse({
		    text: 'You are just a fucking bitch. You just deserve to receive cum on your dirty shitty face',
		    type: 'combined',
	    });
	    console.log( "'You are just a fucking bitch. You just deserve to receive cum on your dirty shitty face' : ",   JSON.stringify(combinedScore) );
	 };

Console output will be :

'I love cold beers' : {
	"sentiment": { score":0.8631731867790222,"result":"positive"},
	"toxicity":[]
}

'I really hate those fucking vegetables' : {
	"sentiment": {"score":0.1487867832183838,"result":"negative"},
	"toxicity":[{"label":"toxicity","result":true}]
}

'You are just a fucking bitch. You just deserve to receive cum on your 	dirty shitty face' : 
{
	"sentiment":{"score":0.9931357502937317,"result":"positive"},
	"toxicity":[
		{"label":"insult","result":true},
		{"label":"toxicity","result":true}
	]
}

'You are just a fucking bitch. You just deserve to receive cum on your 	dirty shitty face' : 
{
	"combined":"negative"
}

Has you can see on the 3rd exemple, the sentences are very vulgar but the sentiment is computed as "positive". That's why I added a "combined" classification so you can check both toxicity and sentiment result to determinate if it's a false positive.

TODO

  • add a tensorflow backend to get better speed and performance.

FAQs

Package last updated on 29 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc