我正在尝试在我的 Laravel 项目中实现一个毒性 js 我正在使用这个库 https://www.npmjs.com/package/@tensorflow-models/toxicity但是当我运行它时,我会在控制台中收到此错误Uncaught ReferenceError: toxicity is not defined我的代码看起来像这个 atm看法<div id="result"></div>myjs.js//import * as toxicity from '../../node_modules/@tensorflow-models/toxicity'; //doesnt work//import * as toxicity from '@tensorflow-models/toxicity'; //doesnt work$(document).ready(function() { 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 }] }, ... */ }); });});我认为问题是我不知道我应该在 Laravel 中的何处包含这一行import * as toxicity from '@tensorflow-models/toxicity';如果我将它包含在 js 文件中,它会给出一个错误:Uncaught SyntaxError: Unexpected token *
添加回答
举报
0/150
提交
取消