Merge LibSi(e)ve with JS++
This commit is contained in:
parent
6da0f0e6b6
commit
8b18d5d8bd
1 changed files with 28 additions and 4 deletions
32
jspp.js
32
jspp.js
|
@ -14,16 +14,40 @@ class JSPlusPlus {
|
|||
async isToxic(sentences) {
|
||||
// Load the model. Users optionally pass in a threshold and an array of
|
||||
// labels to include.
|
||||
const gen = new JSPlusPlus.General
|
||||
gen.require("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs")
|
||||
gen.require("https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity")
|
||||
const gen = new JSPlusPlus.General
|
||||
gen.require("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs")
|
||||
gen.require("https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity")
|
||||
let threshold = 0.9;
|
||||
let t = await toxicity.load(threshold).then(model => {
|
||||
return model.classify(sentences).then(predictions => {
|
||||
return predictions
|
||||
});
|
||||
});
|
||||
return t
|
||||
return t
|
||||
}
|
||||
|
||||
isPrime = num => {
|
||||
for(let i = 2, s = Math.sqrt(num); i <= s; i++) {
|
||||
if(num % i === 0) return false;
|
||||
}
|
||||
return num > 1;
|
||||
}
|
||||
|
||||
sieve(siveTo) {
|
||||
let primes = []
|
||||
siveTo = Number(siveTo)
|
||||
|
||||
for (var i = 1; i < siveTo; i++) {
|
||||
if (isPrime(i)) {
|
||||
primes.push(i)
|
||||
}
|
||||
}
|
||||
|
||||
if (isPrime(siveTo)) {
|
||||
primes.push(siveTo)
|
||||
}
|
||||
|
||||
return primes
|
||||
}
|
||||
|
||||
async asyncSleep(ms) {
|
||||
|
|
Loading…
Reference in a new issue