Instructions to use Blankyy/needle-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use Blankyy/needle-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir needle-mlx Blankyy/needle-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
File size: 869 Bytes
3d5dbbb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | from pathlib import Path
import sentencepiece as spm
class NeedleTokenizer:
pad_token_id = 0
eos_token_id = 1
bos_token_id = 2
unk_token_id = 3
tool_call_token_id = 4
tools_token_id = 5
def __init__(self, model_path):
self.sp = spm.SentencePieceProcessor(model_file=str(model_path))
@classmethod
def from_pretrained(cls, model_dir):
return cls(Path(model_dir) / "tokenizer.model")
def encode(self, text):
return self.sp.encode(text, out_type=int)
def decode(self, tokens):
return self.sp.decode(list(tokens))
def build_encoder_input(tokenizer, query, tools="[]", max_length=1024):
query_tokens = tokenizer.encode(query)[: max_length - 2]
remaining = max_length - len(query_tokens) - 1
return query_tokens + [tokenizer.tools_token_id] + tokenizer.encode(tools)[:remaining]
|