GLiNER.js
GLiNER inference in JavaScript
Install / Use
/learn @Knowledgator/GLiNER.jsREADME
👑 GLiNER.js: Generalist and Lightweight Named Entity Recognition for JavaScript
GLiNER.js is a TypeScript-based inference engine for running GLiNER (Generalist and Lightweight Named Entity Recognition) models. GLiNER can identify any entity type using a bidirectional transformer encoder, offering a practical alternative to traditional NER models and large language models.
<p align="center"> <a href="https://arxiv.org/abs/2311.08526">📄 Paper</a> <span> • </span> <a href="https://discord.gg/Y2yVxpSQnG">📢 Discord</a> <span> • </span> <a href="https://huggingface.co/spaces/urchade/gliner_mediumv2.1">🤗 Demo</a> <span> • </span> <a href="https://huggingface.co/models?library=gliner&sort=trending">🤗 Available models</a> <span> • </span> <a href="https://github.com/urchade/GLiNER">🧬 Official Repo</a> </p>🌟 Key Features
- Flexible entity recognition without predefined categories
- Lightweight and fast inference
- Easy integration with web applications
- TypeScript support for better developer experience
🚀 Getting Started
Installation
npm install gliner
Basic Usage
const gliner = new Gliner({
tokenizerPath: "onnx-community/gliner_small-v2",
onnxSettings: {
modelPath: "public/model.onnx", // Can be a string path or Uint8Array/ArrayBufferLike
executionProvider: "webgpu", // Optional: "cpu", "wasm", "webgpu", or "webgl"
wasmPaths: "path/to/wasm", // Optional: path to WASM binaries
multiThread: true, // Optional: enable multi-threading (for wasm/cpu providers)
maxThreads: 4, // Optional: specify number of threads (for wasm/cpu providers)
fetchBinary: true, // Optional: prefetch binary from wasmPaths
},
transformersSettings: {
// Optional
allowLocalModels: true,
useBrowserCache: true,
},
maxWidth: 12, // Optional
modelType: "gliner", // Optional
});
await gliner.initialize();
const texts = ["Your input text here"];
const entities = ["city", "country", "person"];
const options = {
flatNer: false, // Optional
threshold: 0.1, // Optional
multiLabel: false, // Optional
};
const results = await gliner.inference({
texts,
entities,
...options,
});
console.log(results);
Response Format
The inference results will be returned in the following format:
// For a single text input:
[
{
spanText: "New York", // The extracted entity text
start: 10, // Start character position
end: 18, // End character position
label: "city", // Entity type
score: 0.95, // Confidence score
},
// ... more entities
];
// For multiple text inputs, you'll get an array of arrays
🛠 Setup & Model Preparation
To use GLiNER models in a web environment, you need an ONNX format model. You can:
- Search for pre-converted models on HuggingFace
- Convert a model yourself using the official Python script
Converting to ONNX Format
Use the convert_to_onnx.py script with the following arguments:
model_path: Location of the GLiNER modelsave_path: Where to save the ONNX filequantize: Set to True for IntU8 quantization (optional)
Example:
python convert_to_onnx.py --model_path /path/to/your/model --save_path /path/to/save/onnx --quantize True
🌟 Use Cases
GLiNER.js offers versatile entity recognition capabilities across various domains:
- Enhanced Search Query Understanding
- Real-time PII Detection
- Intelligent Document Parsing
- Content Summarization and Insight Extraction
- Automated Content Tagging and Categorization ...
🔧 Areas for Improvement
- [ ] Further optimize inference speed
- [ ] Add support for token-based GLiNER architecture
- [ ] Implement bi-encoder GLiNER architecture for better scalability
- [ ] Enable model training capabilities
- [ ] Provide more usage examples
Creating a PR
- for any changes, remember to run
pnpm changeset, otherwise there will not be a version bump and the PR Github Action will fail.
🙏 Acknowledgements
📞 Support
For questions and support, please join our Discord community or open an issue on GitHub.
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
