https://github.com/elixir-nx/tokenizers
Elixir bindings for 🤗 Tokenizers
https://github.com/elixir-nx/tokenizers
elixir machine-learning rust text-processing
Last synced: 23 days ago
JSON representation
Elixir bindings for 🤗 Tokenizers
- Host: GitHub
- URL: https://github.com/elixir-nx/tokenizers
- Owner: elixir-nx
- License: apache-2.0
- Created: 2022-02-12T00:48:12.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-13T16:23:17.000Z (over 1 year ago)
- Last Synced: 2024-03-14T19:04:05.060Z (about 1 year ago)
- Topics: elixir, machine-learning, rust, text-processing
- Language: Elixir
- Homepage: https://hexdocs.pm/tokenizers
- Size: 2.32 MB
- Stars: 85
- Watchers: 11
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: CODEOWNERS.md
Awesome Lists containing this project
README
# Tokenizers

Elixir bindings for [Hugging Face Tokenizers](https://github.com/huggingface/tokenizers).
## Installation
You can add `:tokenizers` as dependency in your `mix.exs`:
```elixir
def deps do
[
{:tokenizers, "~> 0.3.0"},
]
end
```If you are using Livebook or IEx, you can instead run:
```elixir
Mix.install([
{:tokenizers, "~> 0.3.0"},
])
```## Example
You can use any pre-trained tokenizer from any model repo on Hugging Face Hub, such as [bert-base-cased](https://huggingface.co/bert-base-cased).
```elixir
{:ok, tokenizer} = Tokenizers.Tokenizer.from_pretrained("bert-base-cased")
{:ok, encoding} = Tokenizers.Tokenizer.encode(tokenizer, "Hello there!")
Tokenizers.Encoding.get_tokens(encoding)
#=> ["Hello", "there", "!"]
Tokenizers.Encoding.get_ids(encoding)
#=> [8667, 1175, 106]
```The [notebooks](./notebooks) directory has [an introductory Livebook](./notebooks/pretrained.livemd) to give you a feel for the API.
## Contributing
Tokenizers uses Rust to call functionality from the Hugging Face Tokenizers library. While
Rust is not necessary to use Tokenizers as a package, you need Rust tooling installed on
your machine if you want to compile from source, which is the case when contributing to
Tokenizers. In particular, you will need Rust Stable, which can be installed with
[Rustup](https://rust-lang.github.io/rustup/installation/index.html).## License
Copyright (c) 2022 Christopher Grainger
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.