如何使用TensorFlow.js预测有害单词

问题描述 投票:-2回答:1

[使用TensorFlow.js预测有害单词,请提供完整示例。...

我搜索了很多东西,但有一些示例仅适用于python,而不适用于JavaScript

javascript prediction word tensorflow.js
1个回答
0
投票
[可以使用毒性模型来预测单词或短语是否有毒。这是来自docs的示例

const threshold = 0.9; // Load the model. Users optionally pass in a threshold and an array of // labels to include. toxicity.load(threshold).then(model => { const sentences = ['you suck']; model.classify(sentences).then(predictions => { // `predictions` is an array of objects, one for each prediction head, // that contains the raw probabilities for each input along with the // final prediction in `match` (either `true` or `false`). // If neither prediction exceeds the threshold, `match` is `null`. console.log(predictions); /* prints: { "label": "identity_attack", "results": [{ "probabilities": [0.9659664034843445, 0.03403361141681671], "match": false }] }, { "label": "insult", "results": [{ "probabilities": [0.08124706149101257, 0.9187529683113098], "match": true }] }, ... */ }); });
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity"></script>
© www.soinside.com 2019 - 2024. All rights reserved.