Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React Native with TypeScript tfjs-models/universal-sentence-encoder error on model load

$
0
0

I'm trying to use tfjs-models/universal-sentence-encoder within a React Native app by following these instructions. However, I get the following error when I try to load the model:

ERROR: TypeError: undefined is not an object (evaluating '_universalSentenceEncoder.default.load'

Code:

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}`);      }    };  }, []);

Package versions:

  • 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

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>