How to use @tensorflow-models/universal-sentence-encoder - 10 common examples

To help you get started, we’ve selected a few @tensorflow-models/universal-sentence-encoder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / 0xDeCA10B / demo / client / src / ml-models / vpa / train-classifier.js View on Github external
async function main() {
    const sentenceEncoder = await UniversalSentenceEncoder.load();
    // The code for the encoder gives too many warnings.
    tf.disableDeprecationWarnings();

    async function getCentroid(intent) {
        const filename = `train_${intent}_full.json`;
        let data = fs.readFileSync(path.join(dataPath, intent, filename), 'utf8');
        data = JSON.parse(data)[intent];

        console.log(`Found ${data.length} samples for ${intents[intent]}.`);
        if (trainSplit < 1) {
            data = data.slice(0, Math.round(trainSplit * data.length));
        }
        const queries = data.map(datum => datum.data.map(o => o.text).join(""));
        console.log(`  Training with ${queries.length} samples.`);

        const chunkSize = 128;
github tensorflow / tfjs-examples / intent-classifier / training / tokens_to_embeddings.js View on Github external
async function run(srcPath, outPath, batchSize) {
  console.log('Start');
  const use = await useLoader.load();
  console.log('Loaded Universal Sentence Encoder');

  const csvData = loadCSV(srcPath);
  const queries = csvData.map(q => q.query);

  await embedTokens(queries, use, batchSize, outPath);
  console.log('Done');
}
github tensorflow / tfjs-examples / intent-classifier / app / index.js View on Github external
async function loadUSE() {
  if (use == null) {
    use = await useLoader.load();
  }
  return use;
}
github microsoft / 0xDeCA10B / demo / client / src / components / model.js View on Github external
async setTransformInputMethod() {
    if (this.state.contractInfo.encoder === 'universal sentence encoder') {
      this.setState({ inputType: INPUT_TYPE_TEXT });
      UniversalSentenceEncoder.load().then(use => {
        this.transformInput = async (query) => {
          const embeddings = await use.embed(query);
          let embedding = tf.tidy(_ => {
            const emb = embeddings.gather(0);
            if (this.state.featureIndices !== undefined && this.state.featureIndices.length > 0) {
              return emb.gather(this.state.featureIndices).arraySync();
            }
            return emb.arraySync();
          });
          embeddings.dispose();
          return this.normalize(embedding).then(normalizedEmbedding => {
            return normalizedEmbedding.map(v => this.web3.utils.toHex(v));
          });
        };
        this.transformInput = this.transformInput.bind(this);
      });
github repetere / tensorscript / bundle / tensorscript.cjs.js View on Github external
async train() {
    const promises = [];
    if (!model) promises.push(UniversalSentenceEncoder.load());
    else promises.push(Promise.resolve(model));
    if (!tokenizer) promises.push(UniversalSentenceEncoder.loadTokenizer());
    else promises.push(Promise.resolve(tokenizer));
    const USE = await Promise.all(promises);
    if (!model) model = USE[ 0 ];
    if (!tokenizer) tokenizer = USE[ 1 ];
    this.model = model;
    this.tokenizer = tokenizer;
    return this.model;
  }
  /**
github jinglescode / demos / src / app / components / nlp-sentence-encoder / nlp-sentence-encoder.component.ts View on Github external
get_embeddings(list_sentences, callback) {
      use.load().then(model => {
        model.embed(list_sentences).then(embeddings => {
          callback(embeddings);
        });
      });
  }
github tensorflow / tfjs-examples / intent-classifier / app / tagger.js View on Github external
async function loadUSE() {
  if (use == null) {
    use = await useLoader.load();
  }
  return use;
}
github tensorflow / tfjs-models / toxicity / src / index.ts View on Github external
async loadTokenizer() {
    return use.loadTokenizer();
  }
github repetere / tensorscript / bundle / tensorscript.esm.js View on Github external
async train() {
    const promises = [];
    if (!model) promises.push(load());
    else promises.push(Promise.resolve(model));
    if (!tokenizer) promises.push(loadTokenizer());
    else promises.push(Promise.resolve(tokenizer));
    const USE = await Promise.all(promises);
    if (!model) model = USE[ 0 ];
    if (!tokenizer) tokenizer = USE[ 1 ];
    this.model = model;
    this.tokenizer = tokenizer;
    return this.model;
  }
  /**
github repetere / tensorscript / bundle / tensorscript.cjs.js View on Github external
async train() {
    const promises = [];
    if (!model) promises.push(UniversalSentenceEncoder.load());
    else promises.push(Promise.resolve(model));
    if (!tokenizer) promises.push(UniversalSentenceEncoder.loadTokenizer());
    else promises.push(Promise.resolve(tokenizer));
    const USE = await Promise.all(promises);
    if (!model) model = USE[ 0 ];
    if (!tokenizer) tokenizer = USE[ 1 ];
    this.model = model;
    this.tokenizer = tokenizer;
    return this.model;
  }
  /**

@tensorflow-models/universal-sentence-encoder

Universal Sentence Encoder lite in TensorFlow.js

Apache-2.0
Latest version published 3 years ago

Package Health Score

69 / 100
Full package analysis

Similar packages