pdfcoffee
Chapter 13AudioTextGeneralUtilitiesSpeechCommands(https://github.com/tensorflow/tfjs-models/tree/master/speechcommands)UniversalSentenceEncoder(https://github.com/tensorflow/tfjs-models/tree/master/universalsentenceencoder)Text ToxicityKNN Classifier(https://github.com/tensorflow/tfjs-models/tree/master/knnclassifier)Classify 1 second audio snippetsfrom the speech commandsdataset (https://github.com/tensorflow/docs/blob/master/site/en/r1/tutorials/sequences/audio_recognition.md).Encode text into a512-dimensional embeddingto be used as inputs to naturallanguage processing tasks suchas sentiment classification andtextual similarity.Score the perceived impacta comment might have on aconversation, from "Very toxic" to"Very healthy".This package provides a utilityfor creating a classifier using theK-nearest neighbors algorithm; itcan be used for transfer learning.npm i @tensorflowmodels/speechcommandsnpm i @tensorflowmodels/universalsentence-encodernpm i @tensorflowmodels/toxicitynpm i @tensorflowmodels/knnclassifierEach pretrained model can be directly used from HTML. For instance, this is anexample with the KNN Classifier:<html><head><!-- Load TensorFlow.js --><script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script><!-- Load MobileNet --><script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet"></script><!-- Load KNN Classifier --><script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/knn-[ 487 ]
TensorFlow for Mobile and IoT and TensorFlow.jsclassifier"></script></head>The next section will explain how to use pretrained models in Node.js.Node.jsIn this section we will give an overview of how to use TensorFlow with Node.js. Let'sstart:The CPU package is imported with the following line of code, which will work for allMac, Linux, and Windows platforms:import * as tf from '@tensorflow/tfjs-node'The GPU package is imported with the following line of code (as of November 2019this will work only on a GPU in a CUDA environment):import * as tf from '@tensorflow/tfjs-node-gpu'An example of Node.js code for defining and compiling a simple dense model isreported below. The code is self-explanatory:const model = tf.sequential();model.add(tf.layers.dense({ units: 1, inputShape: [400] }));model.compile({loss: 'meanSquaredError',optimizer: 'sgd',metrics: ['MAE']});Training can then start with the typical Node.js asynchronous invocation:const xs = tf.randomUniform([10000, 400]);const ys = tf.randomUniform([10000, 1]);const valXs = tf.randomUniform([1000, 400]);const valYs = tf.randomUniform([1000, 1]);async function train() {await model.fit(xs, ys, {epochs: 100,validationData: [valXs, valYs],});}train();[ 488 ]
- Page 472: Chapter 1111. Details regarding ins
- Page 475 and 476: TensorFlow and Cloud• Scalability
- Page 477 and 478: TensorFlow and Cloud• Azure DevOp
- Page 479 and 480: TensorFlow and Cloud• Lambda: The
- Page 481 and 482: TensorFlow and Cloud• Deep Learni
- Page 483 and 484: TensorFlow and CloudEC2 on AmazonTo
- Page 485 and 486: TensorFlow and CloudCompute Instanc
- Page 487 and 488: TensorFlow and CloudYou just share
- Page 489 and 490: TensorFlow and CloudIn case you req
- Page 491 and 492: TensorFlow and CloudIt starts with
- Page 493 and 494: TensorFlow and CloudTFX librariesTF
- Page 495 and 496: TensorFlow and CloudReferences1. To
- Page 497 and 498: TensorFlow for Mobile and IoT and T
- Page 499 and 500: TensorFlow for Mobile and IoT and T
- Page 501 and 502: TensorFlow for Mobile and IoT and T
- Page 503 and 504: TensorFlow for Mobile and IoT and T
- Page 505 and 506: TensorFlow for Mobile and IoT and T
- Page 507 and 508: TensorFlow for Mobile and IoT and T
- Page 509 and 510: TensorFlow for Mobile and IoT and T
- Page 511 and 512: TensorFlow for Mobile and IoT and T
- Page 513 and 514: TensorFlow for Mobile and IoT and T
- Page 515 and 516: TensorFlow for Mobile and IoT and T
- Page 517 and 518: TensorFlow for Mobile and IoT and T
- Page 519 and 520: TensorFlow for Mobile and IoT and T
- Page 521: TensorFlow for Mobile and IoT and T
- Page 525 and 526: TensorFlow for Mobile and IoT and T
- Page 527 and 528: An introduction to AutoMLThat is pr
- Page 529 and 530: An introduction to AutoMLFeature co
- Page 531 and 532: An introduction to AutoMLThis Effic
- Page 533 and 534: An introduction to AutoMLGoogle Clo
- Page 535 and 536: An introduction to AutoMLThen, we c
- Page 537 and 538: An introduction to AutoMLOnce the d
- Page 539 and 540: An introduction to AutoMLIf your mo
- Page 541 and 542: An introduction to AutoMLClicking o
- Page 543 and 544: An introduction to AutoMLFigure 16:
- Page 545 and 546: An introduction to AutoMLYou can al
- Page 547 and 548: An introduction to AutoMLPut simply
- Page 549 and 550: An introduction to AutoMLLet's star
- Page 551 and 552: An introduction to AutoMLThe token
- Page 553 and 554: An introduction to AutoMLThis will
- Page 555 and 556: An introduction to AutoMLFigure 37:
- Page 557 and 558: An introduction to AutoMLAt the end
- Page 559 and 560: An introduction to AutoMLUsing Clou
- Page 561 and 562: An introduction to AutoMLOnce the d
- Page 563 and 564: An introduction to AutoMLAt the end
- Page 565 and 566: An introduction to AutoMLAs the nex
- Page 567 and 568: An introduction to AutoMLOnce the m
- Page 569 and 570: An introduction to AutoMLFigure 65:
- Page 571 and 572: An introduction to AutoMLOnce the m
TensorFlow for Mobile and IoT and TensorFlow.js
classifier"></script>
</head>
The next section will explain how to use pretrained models in Node.js.
Node.js
In this section we will give an overview of how to use TensorFlow with Node.js. Let's
start:
The CPU package is imported with the following line of code, which will work for all
Mac, Linux, and Windows platforms:
import * as tf from '@tensorflow/tfjs-node'
The GPU package is imported with the following line of code (as of November 2019
this will work only on a GPU in a CUDA environment):
import * as tf from '@tensorflow/tfjs-node-gpu'
An example of Node.js code for defining and compiling a simple dense model is
reported below. The code is self-explanatory:
const model = tf.sequential();
model.add(tf.layers.dense({ units: 1, inputShape: [400] }));
model.compile({
loss: 'meanSquaredError',
optimizer: 'sgd',
metrics: ['MAE']
});
Training can then start with the typical Node.js asynchronous invocation:
const xs = tf.randomUniform([10000, 400]);
const ys = tf.randomUniform([10000, 1]);
const valXs = tf.randomUniform([1000, 400]);
const valYs = tf.randomUniform([1000, 1]);
async function train() {
await model.fit(xs, ys, {
epochs: 100,
validationData: [valXs, valYs],
});
}
train();
[ 488 ]