Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@tensorflow/tfjs-core
Advanced tools
Hardware-accelerated JavaScript library for machine intelligence
@tensorflow/tfjs-core is a JavaScript library for developing and training machine learning models in the browser and on Node.js. It provides a flexible and efficient way to perform numerical computations using tensors, which are the core data structure for machine learning.
Tensor Operations
This feature allows you to create and manipulate tensors, which are multi-dimensional arrays. The code sample demonstrates creating two tensors and performing an element-wise addition.
const tf = require('@tensorflow/tfjs-core');
const a = tf.tensor([1, 2, 3, 4]);
const b = tf.tensor([5, 6, 7, 8]);
const c = tf.add(a, b);
c.print();
Model Training
This feature allows you to define, compile, and train machine learning models. The code sample demonstrates creating a simple linear regression model, training it with some data, and making a prediction.
const tf = require('@tensorflow/tfjs-core');
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);
model.fit(xs, ys, {epochs: 10}).then(() => {
model.predict(tf.tensor2d([5], [1, 1])).print();
});
GPU Acceleration
This feature leverages WebGL to perform computations on the GPU, which can significantly speed up numerical operations. The code sample demonstrates a simple tensor addition, which will be accelerated if a GPU is available.
const tf = require('@tensorflow/tfjs-core');
const a = tf.tensor([1, 2, 3, 4]);
const b = tf.tensor([5, 6, 7, 8]);
const c = tf.add(a, b);
c.print();
ONNX.js is a JavaScript library for running ONNX (Open Neural Network Exchange) models in the browser and Node.js. It provides similar functionalities for running pre-trained models but focuses on the ONNX model format, which is widely used for interoperability between different machine learning frameworks.
Brain.js is a JavaScript library for neural networks, which can be used in Node.js and the browser. It provides a simpler API compared to @tensorflow/tfjs-core and is more focused on ease of use for common neural network tasks, but it may not offer the same level of flexibility and performance.
A part of the TensorFlow.js ecosystem, this repo hosts @tensorflow/tfjs-core
,
the TensorFlow.js Core API, which provides low-level, hardware-accelerated
linear algebra operations and an eager API for automatic differentiation.
Check out js.tensorflow.org for more information about the library, tutorials and API docs.
To keep track of issues we use the tensorflow/tfjs Github repo.
You can install TensorFlow.js via yarn or npm. We recommend using the @tensorflow/tfjs npm package, which gives you both this Core API and the higher-level Layers API:
import * as tf from '@tensorflow/tfjs';
// You have the Core API: tf.matMul(), tf.softmax(), ...
// You also have Layers API: tf.model(), tf.layers.dense(), ...
On the other hand, if you care about the bundle size and you do not use the Layers API, you can import only the Core API:
import * as tfc from '@tensorflow/tfjs-core';
// You have the Core API: tfc.matMul(), tfc.softmax(), ...
// No Layers API.
For info about development, check out DEVELOPMENT.md.
Thanks BrowserStack for providing testing support.
FAQs
Hardware-accelerated JavaScript library for machine intelligence
We found that @tensorflow/tfjs-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.