![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@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 healthy version release cadence and project activity because the last version was released less than 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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.