Skip to content

dalgarak/lua-sentencepiece

Repository files navigation

lua-sentencepiece

A Simple lua bindings for sentencepiece (https://github.com/google/sentencepiece) implementation

Installation

  1. download google/sentencepiece(https://github.com/google/sentencepiece)
  2. do 'configure - make - make install' well-known 3-steps to install sentencepiece
  3. download this module, and build it with luarocks

Installation Example:

git clone https://github.com/dalgarak/lua-sentencepiece.git ./tmp-lua-sentencepiece
cd tmp-lua-sentencepiece
luarocks make lua-sentencepiece-dev-1.rockspec SENTPIECE_INCDIR=[sentencepiece source directory path]

How to use

You need to build or copy a sentencepiece model before using this module. see sentencepiece - spm_train

-- load SentencePieceProcessor module
spp = require('SentencePieceProcessor')

-- load a model
spm = spp.new('./a_sentencepiece_model_file.model')

-- encode string with sentencepiece model: Normalization of string is applied automatically
encoded_str = spm:encode('How do I execute this module?')
print(encoded_str)

-- decode string
print(spm:decode(encoded_str))

-- give extra options for encoding steps and encode some string
spm:encodeExtraOptions("reverse:bos:eos")
encoded_str = spm:encode('How do I execute this module?')

-- give extra options for decoding steps and decode
spm:decodeExtraOptions("reverse")
print(spm:decode(encoded_str))

License

lua-sentencepiece is distributed under the MIT license.

lua-sentencepiece module for Lua 5.1/5.2/luajit 2.1

Copyright (C) 2017 Jong-Hun Shin(aka dalgarak, luna.jetch __AT__ gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, 
sublicense, and/or sell copies of the Software, 
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial 
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

and 

'google/sentencepiece' is distributed under the Apache 2.0 license.

About

A simple lua bindings for sentencepiece(https://github.com/google/sentencepiece) implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published