【发布时间】:2021-05-12 15:59:21
【问题描述】:
我正在尝试通过关注these instructions 在 React Native 应用程序中使用 tfjs-models/universal-sentence-encoder。但是,当我尝试加载模型时出现以下错误:
ERROR: TypeError: undefined is not an object (evaluating '_universalSentenceEncoder.default.load'
代码:
import React, { useEffect, useState } from 'react';
require('@tensorflow/tfjs');
const use = require('@tensorflow-models/universal-sentence-encoder');
export default function App() {
useEffect(() => {
console.log("App is starting...")
const init = async () => {
// initialize state variables
// console.log("App is initializing services...")
// Load the model.
try {
use.load().then((model: any) => {
// Embed an array of sentences.
const sentences = [
'Hello.',
'How are you?'
];
model.embed(sentences).then((embeddings: any) => {
// `embeddings` is a 2D tensor consisting of the 512-dimensional embeddings for each sentence.
// So in this example `embeddings` has the shape [2, 512].
embeddings.print(true /* verbose */);
});
});
}
catch (err) {
console.log(`ERROR: ${err}`);
}
};
}, []);
软件包版本:
- react-native@0.63.3
- @tensorflow-models/universal-sentence-encoder@1.3.2
- @tensorflow/tfjs@3.6.0
- @tensorflow/tfjs-react-native@0.5.0
【问题讨论】:
标签: typescript react-native tensorflow tensorflow.js