npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plx.js

v1.0.2

Published

AI library for basic projects

Downloads

82

Readme

PLX.js

PLX.js is a comprehensive JavaScript library designed for various machine learning tasks, including question answering, translation, text classification, and image classification. This library leverages neural networks and provides a flexible API for training, saving, and loading models. Below is a detailed overview of the features, systems, and usage examples for each component of PLX.js.

Features

  • Question Answering: Utilize neural networks to answer questions based on provided contexts.
  • Translation: Translate text from one language to another using trained models.
  • Text Classification: Classify text into predefined categories.
  • Image Classification: Classify images into predefined categories.
  • Model Persistence: Save and load models for reuse without retraining.
  • Customizable Neural Networks: Configure network types and layers for specific tasks.

Installation

To use PLX.js, clone the repository and install the necessary dependencies:

npm install plx.js

Usage

Question Answering

The Question Answering system uses neural networks to find answers to questions based on given contexts.

Example

const { QuestionAnswer } = require("plx.js");

// Create a new network
const net = new QuestionAnswer({
    hiddenLayers: [8, 4],
    fast: false // Uses LSTM
});

// Dataset
const dataset = [
    {
        input: "What is the capital of France?",
        output: "Paris"
    },
    // Add more data as needed
];

// Train the network
net.train(dataset, {
    iterations: 100,
    error: 0.005,
    log: true,
    rate: 0.01,
    shuffle: true,
    clear: true,
    momentum: 0
});

// Save the model
net.save("model2.json");

// Test the model
async function testModel() {
    const net2 = await QuestionAnswer.load("model2.json");
    const result = net2.run("What is the capital of France?", [
        "France is a country in Western Europe. Its capital is Paris."
    ]);
    console.log("Test result:", result);
}

testModel();

Translation

Translate text from one language to another using a trained neural network.

Example

const { Translation } = require("plx.js");

// Create a new translation model
const net = new Translation({
    hiddenLayers: [16, 8],
    fast: false // Uses LSTM
});

// Dataset
const dataset = [
    {
        input: "Merhaba dünya",
        output: "Hello world"
    },
    // Add more data as needed
];

// Train the model
net.train(dataset, {
    iterations: 100,
    error: 0.005,
    log: true,
    rate: 0.01,
    shuffle: true,
    clear: true,
    momentum: 0
});

// Save the model
net.save("translation_model.json");

// Load and test the model
async function testTranslation() {
    const net2 = await Translation.load("translation_model.json");
    const result = net2.run("Merhaba dünya");
    console.log("Translation result:", result);
}

testTranslation();

Text Classification

Classify text into categories such as "Sports" or "Technology".

Example

const { TextClassification } = require("plx.js");

// Create a new text classification model
const net = new TextClassification({
    hiddenLayers: [16, 8],
    fast: false // Uses LSTM
});

// Dataset
const dataset = [
    {
        text: "Lionel Messi transferred to PSG.",
        label: "Sports"
    },
    // Add more data as needed
];

// Train the model
net.train(dataset, {
    iterations: 10,
    error: 0.005,
    log: true,
    rate: 0.01,
    shuffle: true,
    clear: true,
    momentum: 0
});

// Save the model
net.save("classification_model.json");

// Load and test the model
async function testClassification() {
    const net2 = await TextClassification.load("classification_model.json");
    const result = net2.classify("Lionel Messi transferred to PSG.");
    console.log("Classification result:", result);
}

testClassification();

Image Classification

Classify images into predefined categories using a neural network.

Example

const { ImageClassification } = require("plx.js");

// Create a new image classification model
const classifier = new ImageClassification({
    hiddenLayers: [32, 16],
    type: "Perceptron"
});

// Train the model
classifier.train('dataset', {
    iterations: 10,
    error: 0.005,
    rate: 0.01,
    shuffle: true,
    log: true,
    clear: true,
    momentum: 0
});

// Save the model
classifier.save("image_model.json");

// Load and test the model
async function testImageClassification() {
    const classifier2 = await ImageClassification.load("image_model.json");
    const result = await classifier2.classify('image.png');
    console.log('Image classification result:', result);
}

testImageClassification();

Engine.js Usage

The engine.js file provides the core functionality for creating and managing neural networks. Below is an example of how to use it to create a custom network.

Example

const { Network } = require("plx.js");

// Create a new network
const net = new Network.LSTM({
    inputSize: 10,
    hiddenLayers: [20, 10],
    outputSize: 5
});

// Example dataset
const dataset = [
    { input: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], output: [1, 0, 0, 0, 0] },
    // Add more data as needed
];

// Train the network
net.train(dataset, {
    iterations: 100,
    error: 0.005,
    log: true,
    rate: 0.01,
    shuffle: true,
    clear: true,
    momentum: 0
});

// Save the model
net.save("custom_model.json");

// Load and test the model
async function testCustomNetwork() {
    const net2 = await Network.loadModel("custom_model.json");
    const result = net2.run([0, 1, 0, 1, 0, 1, 0, 1, 0, 1]);
    console.log("Custom network result:", result);
}

testCustomNetwork();

Model Persistence

PLX.js supports saving and loading models to and from JSON files, allowing for easy model reuse without retraining.

Saving a Model

await net.save("model.json");

Loading a Model

const net2 = await Network.loadModel("model.json");

Customization

PLX.js allows customization of neural network configurations, including the number of hidden layers and the choice between GRU and LSTM networks.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.

License

This project is licensed under the Apache-2.0 License.