【问题标题】:How to predict harmful words using TensorFlow.js如何使用 TensorFlow.js 预测有害词
【发布时间】:2019-12-22 05:38:31
【问题描述】:

使用 TensorFlow.js 预测有害词,请给出完整示例....

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

【问题讨论】:

    标签: javascript prediction word tensorflow.js


    【解决方案1】:

    毒性模型可以直接用于预测单词或短语是否有毒。这是来自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>

    【讨论】:

    • 请给我一些使用 TensorFlow Js 进行简单单词预测的例子
    • 什么意思?如果你能展示你所做的事情会更容易提供帮助
    猜你喜欢
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    • 2018-09-19
    相关资源
    最近更新 更多