
Product
Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
@moveyourdigital/nlp
Advanced tools
NLP (natural language processing) for server and the browser in TypeScript. All lightweight and super-fast.
Natural Language Processing (NLP) written in TypeScript for both server and browser environments. Lightweight and ultra-fast.
The goal of this package is to provide a lightweight and super-fast solution for natural language processing tasks.
It aims to be the go-to choice for developers seeking a powerful yet easy-to-use NLP solution in TypeScript. Whether working on the server-side or in the browser, this is optimized for performance and simplicity.
This package was inspired in the good but old apparatus
package.
BayesClassifier
class)natural
npm package for stemming and the stopword
npm package for managing stopword lists.npm i @moveyourdigital/nlp
This is a minimal usage of the Naive Bayes classifier using sentences.
import { BayesClassifier, Tokenizer, WordsEnTokenizer } from '@moveyourdigital/nlp'
const tokenizer = new WordsEnTokenizer()
// or WordsPtTokenizer
const classifier = new BayesClassifier<string, string>()
.set('smoothing', 0.1)
.addDocument({
observation: tokenizer.tokenize(
'you are a beautiful person'
),
label: 'good',
})
.addDocument({
observation: tokenizer.tokenize(
'he is an evil person'
),
label: 'bad',
})
.train()
const classification = classifier.classify(
tokenizer.tokenize('i am a beautiful person')
)
Classification should output
[
{ label: 'good', score: 4.6305 }, // ordered by highiest score
{ label: 'bad', score: 1.2705000000000002 }
]
The classifier supports flexible serialization and deserialization, making it easy to save, share, and deploy trained models.
One can serialize the classifier to a JSON string, enabling to store or transfer the model. This is especially useful for deploying models to different environments or saving the state of a model for future use.
const jsonString = classifier.toJSON();
// Standard JSON string representation of the model
For scenarios where the model is only needed for text classification (i.e., no further training is required), you can use the compact serialization option. This removes the corpus from the serialization output, significantly reducing the model's size for efficient distribution.
const jsonString = classifier.toJSON({ compact: true });
// JSON string representation of the model for distribution
To restore the model for further training or usage, deserialize the JSON string back into the classifier. If you intend to continue training the model, do not use the compact flag during serialization.
classifier.restore(jsonString); // Accepts both stringified or already parsed JSON
This flexible serialization and deserialization process ensures that NLP models can be managed efficiently, whether a lightweight distribution is needed or the full model for ongoing development.
To watch for changes in src
directory.
npm start
To bundle for production
npm run build
Unit tests are located in
npm t
FAQs
NLP (natural language processing) for server and the browser in TypeScript. All lightweight and super-fast.
We found that @moveyourdigital/nlp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 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.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.