Socket
Socket
Sign inDemoInstall

@tensorflow/tfjs-core

Package Overview
Dependencies
Maintainers
8
Versions
185
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tensorflow/tfjs-core

Hardware-accelerated JavaScript library for machine intelligence


Version published
Weekly downloads
255K
increased by5.71%
Maintainers
8
Weekly downloads
 
Created

What is @tensorflow/tfjs-core?

@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.

What are @tensorflow/tfjs-core's main functionalities?

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();

Other packages similar to @tensorflow/tfjs-core

FAQs

Package last updated on 06 Jun 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc