tfjs入门之toxicity
教程:【吴恩达团队Tensorflow2.0数据和部署第一课】基于浏览器的模型与TensorFlow.js
toxicity.html
<html> <head> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.1.0"></script> <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity@1.2.0"></script> <script> // The minimum prediction confidence. 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 => {
console.log(predictions); for(i=0;i<7;i++){
if(predictions[i].results[0].match){
console.log(predictions[i].label *" was found with a probability of " * predictions[i].results[0].probabilities[1]); } } }); }); </script> </head> <body></body> </html>
讯享网
在浏览器打开,按F12

讯享网
则成功
说一说遇到的坑:
(1)指定tfjs和toxicity版本问题,此处分别为2.1.0,1.2.0,否则可能会遇到找不到函数等各种bug

(2)警告信息可以忽略,或者脚本标签改为

讯享网<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.1.0/dist/tf.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity@1.2.0/dist/toxicity.js"></script>

注:具体tfjs、toxicity版本等信息可以参见
https://cdn.jsdelivr.net/


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/26277.html