Socket
Socket
Sign inDemoInstall

sentencepiece-js

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sentencepiece-js

Sentencepiece tokenization for natural language processing, JS version.


Version published
Weekly downloads
64
decreased by-51.15%
Maintainers
1
Install size
774 kB
Created
Weekly downloads
 

Readme

Source

Javascript wrapper for the sentencepiece library

Build

Sentencepiece is compiled to webassembly using emscripten.

To rebuild this project


yarn

git clone https://github.com/google/sentencepiece.git

yarn build

Use

To use this tool


const { SentencePieceProcessor, cleanText } = require("../dist");
const ROOT = require('app-root-path')

async function main() {

    let text = "I am still waiting on my card?"
    let cleaned = cleanText(text)

    let spp = new SentencePieceProcessor()
    await spp.load(`${ROOT}/test/30k-clean.model`)
    let ids = spp.encodeIds(cleaned)
    console.log(ids)
    let str = spp.decodeIds(ids) // list ids->number
    console.log(str)

    let pieces = spp.encodePieces(cleaned) // list tokens->string
    console.log(pieces)
}
main()

Note

  • devilyouwei updated this repo to make this module support the js require keyword and added the using example.

  • 2023-1-10, devilyouwei added encodePieces.

Keywords

FAQs

Last updated on 10 Jan 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc