Downloads · 30 days
0
chetanpun/devanagari-english-bpe-tokenizer
devanagari-english-bpe-tokenizer is a machine learning model from chetanpun. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This repository contains a custom tokenizer built to handle both Nepali (Devanagari) and English languages, facilitating seamless tokenization for NLP tasks that involve code-switching or translation between these two…
Downloads · 30 days
0
Access
Public
Updated Oct 8, 2024
Repo size
12.4 MB
Likes
1
Public
Click a slice to open those files.
.json8.5 MB · 100%
From the Hugging Face model README
This repository contains a custom tokenizer built to handle both Nepali (Devanagari) and English languages, facilitating seamless tokenization for NLP tasks that involve code-switching or translation between these two languages.
You can easily install and use the tokenizer with Hugging Face’s transformers library.
pip install transformers
To use the tokenizer, load it directly from Hugging Face:
from transformers import PreTrainedTokenizerFast
tokenizer = PreTrainedTokenizerFast.from_pretrained('chetanpun/devanagari-english-bpe-tokenizer')
To tokenize text in either Nepali or English:
nepali_text = "मेरो नाम चेतन हो।"
english_text = "My name is Chetan."
mix_text = "Hello मेरो नाम चेतन हो।"
nepali_tokens = tokenizer(nepali_text)
english_tokens = tokenizer(english_text)
print("Nepali Tokens:", nepali_tokens)
print("English Tokens:", english_tokens)
You can encode text into token IDs and decode them back:
input_ids = tokenizer.encode(nepali_text, return_tensors="pt")
decoded_text = tokenizer.decode(input_ids[0], skip_special_tokens=True)
print("Decoded Text:", decoded_text)