Angad Sandhu
Search
Browse

toxicity

Source name
toxicity.html
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity"></script>
<script>
const threshold = 0.9;
toxicity.load(threshold).then(model => {
    const sentences = ['you suck'];
    model.classify(sentences).then(predictions => {
        console.log(predictions);
        for(i=0; i<7; i++){
            if(predictions[i].results[0].match){
                console.log(predictions[i].label + 
                            " was found with probability of " + 
                            predictions[i].results[0].probabilities[1]);                
            }  
        }
    });
});
</script> 
</head>
<body></body>
</html>    

Browse the library