npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@christophe77/sentiment-js

v1.0.10

Published

Get sentiment and toxicity of a text.

Downloads

34

Readme

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.