Text Generation
Transformers
Safetensors
Serbian
qwen3_5
image-text-to-text
srpski
generativni
model
qa
summarization
translation
reasoning
conversational
Instructions to use procesaur/Vrabac2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use procesaur/Vrabac2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="procesaur/Vrabac2") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("procesaur/Vrabac2") model = AutoModelForMultimodalLM.from_pretrained("procesaur/Vrabac2", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use procesaur/Vrabac2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "procesaur/Vrabac2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "procesaur/Vrabac2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/procesaur/Vrabac2
- SGLang
How to use procesaur/Vrabac2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "procesaur/Vrabac2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "procesaur/Vrabac2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "procesaur/Vrabac2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "procesaur/Vrabac2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use procesaur/Vrabac2 with Docker Model Runner:
docker model run hf.co/procesaur/Vrabac2
Upload 8 files
Browse files- .gitattributes +1 -0
- chat_template.jinja +154 -0
- config.json +105 -0
- generation_config.json +6 -0
- model.safetensors +3 -0
- tokenization_srna.py +332 -0
- tokenizer.json +3 -0
- tokenizer_config.json +33 -0
- vrabac-cover.svg +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- set image_count = namespace(value=0) %}
|
| 2 |
+
{%- set video_count = namespace(value=0) %}
|
| 3 |
+
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 4 |
+
{%- if content is string %}
|
| 5 |
+
{{- content }}
|
| 6 |
+
{%- elif content is iterable and content is not mapping %}
|
| 7 |
+
{%- for item in content %}
|
| 8 |
+
{%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
|
| 9 |
+
{%- if is_system_content %}
|
| 10 |
+
{{- raise_exception('System message cannot contain images.') }}
|
| 11 |
+
{%- endif %}
|
| 12 |
+
{%- if do_vision_count %}
|
| 13 |
+
{%- set image_count.value = image_count.value + 1 %}
|
| 14 |
+
{%- endif %}
|
| 15 |
+
{%- if add_vision_id %}
|
| 16 |
+
{{- 'Picture ' ~ image_count.value ~ ': ' }}
|
| 17 |
+
{%- endif %}
|
| 18 |
+
{{- '<|vision_start|><|image_pad|><|vision_end|>' }}
|
| 19 |
+
{%- elif 'video' in item or item.type == 'video' %}
|
| 20 |
+
{%- if is_system_content %}
|
| 21 |
+
{{- raise_exception('System message cannot contain videos.') }}
|
| 22 |
+
{%- endif %}
|
| 23 |
+
{%- if do_vision_count %}
|
| 24 |
+
{%- set video_count.value = video_count.value + 1 %}
|
| 25 |
+
{%- endif %}
|
| 26 |
+
{%- if add_vision_id %}
|
| 27 |
+
{{- 'Video ' ~ video_count.value ~ ': ' }}
|
| 28 |
+
{%- endif %}
|
| 29 |
+
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
|
| 30 |
+
{%- elif 'text' in item %}
|
| 31 |
+
{{- item.text }}
|
| 32 |
+
{%- else %}
|
| 33 |
+
{{- raise_exception('Unexpected item type in content.') }}
|
| 34 |
+
{%- endif %}
|
| 35 |
+
{%- endfor %}
|
| 36 |
+
{%- elif content is none or content is undefined %}
|
| 37 |
+
{{- '' }}
|
| 38 |
+
{%- else %}
|
| 39 |
+
{{- raise_exception('Unexpected content type.') }}
|
| 40 |
+
{%- endif %}
|
| 41 |
+
{%- endmacro %}
|
| 42 |
+
{%- if not messages %}
|
| 43 |
+
{{- raise_exception('No messages provided.') }}
|
| 44 |
+
{%- endif %}
|
| 45 |
+
{%- if tools and tools is iterable and tools is not mapping %}
|
| 46 |
+
{{- '<|im_start|>system\n' }}
|
| 47 |
+
{{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
|
| 48 |
+
{%- for tool in tools %}
|
| 49 |
+
{{- "\n" }}
|
| 50 |
+
{{- tool | tojson }}
|
| 51 |
+
{%- endfor %}
|
| 52 |
+
{{- "\n</tools>" }}
|
| 53 |
+
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
|
| 54 |
+
{%- if messages[0].role == 'system' %}
|
| 55 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 56 |
+
{%- if content %}
|
| 57 |
+
{{- '\n\n' + content }}
|
| 58 |
+
{%- endif %}
|
| 59 |
+
{%- endif %}
|
| 60 |
+
{{- '<|im_end|>\n' }}
|
| 61 |
+
{%- else %}
|
| 62 |
+
{%- if messages[0].role == 'system' %}
|
| 63 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 64 |
+
{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
|
| 65 |
+
{%- endif %}
|
| 66 |
+
{%- endif %}
|
| 67 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 68 |
+
{%- for message in messages[::-1] %}
|
| 69 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 70 |
+
{%- if ns.multi_step_tool and message.role == "user" %}
|
| 71 |
+
{%- set content = render_content(message.content, false)|trim %}
|
| 72 |
+
{%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
|
| 73 |
+
{%- set ns.multi_step_tool = false %}
|
| 74 |
+
{%- set ns.last_query_index = index %}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{%- endif %}
|
| 77 |
+
{%- endfor %}
|
| 78 |
+
{%- if ns.multi_step_tool %}
|
| 79 |
+
{{- raise_exception('No user query found in messages.') }}
|
| 80 |
+
{%- endif %}
|
| 81 |
+
{%- for message in messages %}
|
| 82 |
+
{%- set content = render_content(message.content, true)|trim %}
|
| 83 |
+
{%- if message.role == "system" %}
|
| 84 |
+
{%- if not loop.first %}
|
| 85 |
+
{{- raise_exception('System message must be at the beginning.') }}
|
| 86 |
+
{%- endif %}
|
| 87 |
+
{%- elif message.role == "user" %}
|
| 88 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 89 |
+
{%- elif message.role == "assistant" %}
|
| 90 |
+
{%- set reasoning_content = '' %}
|
| 91 |
+
{%- if message.reasoning_content is string %}
|
| 92 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 93 |
+
{%- else %}
|
| 94 |
+
{%- if '</think>' in content %}
|
| 95 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 96 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 97 |
+
{%- endif %}
|
| 98 |
+
{%- endif %}
|
| 99 |
+
{%- set reasoning_content = reasoning_content|trim %}
|
| 100 |
+
{%- if loop.index0 > ns.last_query_index %}
|
| 101 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
|
| 102 |
+
{%- else %}
|
| 103 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 104 |
+
{%- endif %}
|
| 105 |
+
{%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
|
| 106 |
+
{%- for tool_call in message.tool_calls %}
|
| 107 |
+
{%- if tool_call.function is defined %}
|
| 108 |
+
{%- set tool_call = tool_call.function %}
|
| 109 |
+
{%- endif %}
|
| 110 |
+
{%- if loop.first %}
|
| 111 |
+
{%- if content|trim %}
|
| 112 |
+
{{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 113 |
+
{%- else %}
|
| 114 |
+
{{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 115 |
+
{%- endif %}
|
| 116 |
+
{%- else %}
|
| 117 |
+
{{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 118 |
+
{%- endif %}
|
| 119 |
+
{%- if tool_call.arguments is defined %}
|
| 120 |
+
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 121 |
+
{{- '<parameter=' + args_name + '>\n' }}
|
| 122 |
+
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
|
| 123 |
+
{{- args_value }}
|
| 124 |
+
{{- '\n</parameter>\n' }}
|
| 125 |
+
{%- endfor %}
|
| 126 |
+
{%- endif %}
|
| 127 |
+
{{- '</function>\n</tool_call>' }}
|
| 128 |
+
{%- endfor %}
|
| 129 |
+
{%- endif %}
|
| 130 |
+
{{- '<|im_end|>\n' }}
|
| 131 |
+
{%- elif message.role == "tool" %}
|
| 132 |
+
{%- if loop.previtem and loop.previtem.role != "tool" %}
|
| 133 |
+
{{- '<|im_start|>user' }}
|
| 134 |
+
{%- endif %}
|
| 135 |
+
{{- '\n<tool_response>\n' }}
|
| 136 |
+
{{- content }}
|
| 137 |
+
{{- '\n</tool_response>' }}
|
| 138 |
+
{%- if not loop.last and loop.nextitem.role != "tool" %}
|
| 139 |
+
{{- '<|im_end|>\n' }}
|
| 140 |
+
{%- elif loop.last %}
|
| 141 |
+
{{- '<|im_end|>\n' }}
|
| 142 |
+
{%- endif %}
|
| 143 |
+
{%- else %}
|
| 144 |
+
{{- raise_exception('Unexpected message role.') }}
|
| 145 |
+
{%- endif %}
|
| 146 |
+
{%- endfor %}
|
| 147 |
+
{%- if add_generation_prompt %}
|
| 148 |
+
{{- '<|im_start|>assistant\n' }}
|
| 149 |
+
{%- if enable_thinking is defined and enable_thinking is true %}
|
| 150 |
+
{{- '<think>\n' }}
|
| 151 |
+
{%- else %}
|
| 152 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 153 |
+
{%- endif %}
|
| 154 |
+
{%- endif %}
|
config.json
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Qwen3_5ForConditionalGeneration"
|
| 4 |
+
],
|
| 5 |
+
"dtype": "bfloat16",
|
| 6 |
+
"image_token_id": 248056,
|
| 7 |
+
"model_type": "qwen3_5",
|
| 8 |
+
"text_config": {
|
| 9 |
+
"attention_bias": false,
|
| 10 |
+
"attention_dropout": 0.0,
|
| 11 |
+
"attn_output_gate": true,
|
| 12 |
+
"bos_token_id": null,
|
| 13 |
+
"dtype": "bfloat16",
|
| 14 |
+
"eos_token_id": 248044,
|
| 15 |
+
"full_attention_interval": 4,
|
| 16 |
+
"head_dim": 256,
|
| 17 |
+
"hidden_act": "silu",
|
| 18 |
+
"hidden_size": 1024,
|
| 19 |
+
"initializer_range": 0.02,
|
| 20 |
+
"intermediate_size": 3584,
|
| 21 |
+
"layer_types": [
|
| 22 |
+
"linear_attention",
|
| 23 |
+
"linear_attention",
|
| 24 |
+
"linear_attention",
|
| 25 |
+
"full_attention",
|
| 26 |
+
"linear_attention",
|
| 27 |
+
"linear_attention",
|
| 28 |
+
"linear_attention",
|
| 29 |
+
"full_attention",
|
| 30 |
+
"linear_attention",
|
| 31 |
+
"linear_attention",
|
| 32 |
+
"linear_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"linear_attention",
|
| 35 |
+
"linear_attention",
|
| 36 |
+
"linear_attention",
|
| 37 |
+
"full_attention",
|
| 38 |
+
"linear_attention",
|
| 39 |
+
"linear_attention",
|
| 40 |
+
"linear_attention",
|
| 41 |
+
"full_attention",
|
| 42 |
+
"linear_attention",
|
| 43 |
+
"linear_attention",
|
| 44 |
+
"linear_attention",
|
| 45 |
+
"full_attention"
|
| 46 |
+
],
|
| 47 |
+
"linear_conv_kernel_dim": 4,
|
| 48 |
+
"linear_key_head_dim": 128,
|
| 49 |
+
"linear_num_key_heads": 16,
|
| 50 |
+
"linear_num_value_heads": 16,
|
| 51 |
+
"linear_value_head_dim": 128,
|
| 52 |
+
"mamba_ssm_dtype": "float32",
|
| 53 |
+
"max_position_embeddings": 262144,
|
| 54 |
+
"mlp_only_layers": [],
|
| 55 |
+
"model_type": "qwen3_5_text",
|
| 56 |
+
"mtp_num_hidden_layers": 1,
|
| 57 |
+
"mtp_use_dedicated_embeddings": false,
|
| 58 |
+
"num_attention_heads": 8,
|
| 59 |
+
"num_hidden_layers": 24,
|
| 60 |
+
"num_key_value_heads": 2,
|
| 61 |
+
"pad_token_id": null,
|
| 62 |
+
"rms_norm_eps": 1e-06,
|
| 63 |
+
"rope_parameters": {
|
| 64 |
+
"mrope_interleaved": true,
|
| 65 |
+
"mrope_section": [
|
| 66 |
+
11,
|
| 67 |
+
11,
|
| 68 |
+
10
|
| 69 |
+
],
|
| 70 |
+
"partial_rotary_factor": 0.25,
|
| 71 |
+
"rope_theta": 10000000,
|
| 72 |
+
"rope_type": "default"
|
| 73 |
+
},
|
| 74 |
+
"tie_word_embeddings": true,
|
| 75 |
+
"use_cache": false,
|
| 76 |
+
"vocab_size": 248320
|
| 77 |
+
},
|
| 78 |
+
"tie_word_embeddings": true,
|
| 79 |
+
"transformers_version": "5.20.2",
|
| 80 |
+
"use_cache": false,
|
| 81 |
+
"video_token_id": 248057,
|
| 82 |
+
"vision_config": {
|
| 83 |
+
"deepstack_visual_indexes": [],
|
| 84 |
+
"depth": 12,
|
| 85 |
+
"dtype": "bfloat16",
|
| 86 |
+
"hidden_act": "gelu_pytorch_tanh",
|
| 87 |
+
"hidden_size": 768,
|
| 88 |
+
"in_channels": 3,
|
| 89 |
+
"initializer_range": 0.02,
|
| 90 |
+
"intermediate_size": 3072,
|
| 91 |
+
"model_type": "qwen3_5_vision",
|
| 92 |
+
"num_heads": 12,
|
| 93 |
+
"num_position_embeddings": 2304,
|
| 94 |
+
"out_hidden_size": 1024,
|
| 95 |
+
"patch_size": 16,
|
| 96 |
+
"rope_parameters": {
|
| 97 |
+
"rope_theta": 10000.0,
|
| 98 |
+
"rope_type": "axial"
|
| 99 |
+
},
|
| 100 |
+
"spatial_merge_size": 2,
|
| 101 |
+
"temporal_patch_size": 2
|
| 102 |
+
},
|
| 103 |
+
"vision_end_token_id": 248054,
|
| 104 |
+
"vision_start_token_id": 248053
|
| 105 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"eos_token_id": [248044, 248046],
|
| 4 |
+
"transformers_version": "5.20.2",
|
| 5 |
+
"use_cache": true
|
| 6 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4a57bab398b11cf17320825be957ef3fcfb277f2c5cfdc7ba32eb85dee22dc80
|
| 3 |
+
size 1706030528
|
tokenization_srna.py
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2026 Mihailo Škorić.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Tokenization classes for Serbian and Serbo-Croatian models."""
|
| 15 |
+
from transformers import PreTrainedTokenizerFast #
|
| 16 |
+
from tokenizers import Regex, Tokenizer, decoders, normalizers, pre_tokenizers
|
| 17 |
+
from tokenizers.models import BPE
|
| 18 |
+
|
| 19 |
+
#from ...tokenization_utils_tokenizers import TokenizersBackend
|
| 20 |
+
#from ...utils import logging
|
| 21 |
+
|
| 22 |
+
import regex
|
| 23 |
+
|
| 24 |
+
#logger = logging.get_logger(__name__)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
mapping = {
|
| 29 |
+
"Љ": "Lj", "љ": "lj", "Њ": "Nj", "њ": "nj", "Џ": "Dž", "џ": "dž",
|
| 30 |
+
"А": "A", "а": "a", "Б": "B", "б": "b", "В": "V", "в": "v",
|
| 31 |
+
"Г": "G", "г": "g", "Д": "D", "д": "d", "Ђ": "Đ", "ђ": "đ",
|
| 32 |
+
"Е": "E", "е": "e", "Ж": "Ž", "ж": "ž", "З": "Z", "з": "z",
|
| 33 |
+
"И": "I", "и": "i", "Ј": "J", "ј": "j", "К": "K", "к": "k",
|
| 34 |
+
"Л": "L", "л": "l", "М": "M", "м": "m", "Н": "N", "н": "n",
|
| 35 |
+
"О": "O", "о": "o", "П": "P", "п": "p", "Р": "R", "р": "r",
|
| 36 |
+
"С": "S", "с": "s", "Т": "T", "т": "t", "Ћ": "Ć", "ћ": "ć",
|
| 37 |
+
"У": "U", "у": "u", "Ф": "F", "ф": "f", "Х": "H", "х": "h",
|
| 38 |
+
"Ц": "C", "ц": "c", "Ч": "Č", "ч": "č", "Ш": "Š", "ш": "š",
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
reverse_mapping = {v: k for k, v in mapping.items()}
|
| 42 |
+
reverse_mapping["dj"] = "ђ"
|
| 43 |
+
|
| 44 |
+
digraphExceptions = {
|
| 45 |
+
"dj": ["adjektiv", "adjon", "adjunkt", "adjuvat", "adjudik", "adjung", "adjunk", "adjutant", "autodjel", "bazdje", "bdje",
|
| 46 |
+
"bezdje", "blijedje", "bludje", "bordje", "bridjе", "burdje", "vidjel", "vidjet", "vindjakn", "višedjel", "višenedje",
|
| 47 |
+
"vrijedje", "vododjelni", "vodosnabdje", "gdje", "gudje", "gdjir", "daladje", "daždje", "dvodjel", "dvonedje", "devetonedje",
|
| 48 |
+
"depardje", "desetonedje", "didje", "djb", "djeva", "djevi", "djevo", "djevstv", "djed", "djejstv", "djel", "djenem", "djeneš",
|
| 49 |
+
"djenu", "djet", "djec", "dječ", "djuar", "djubison", "djubouz", "djuer", "djui", "djuks", "djulej", "djumars", "djupont",
|
| 50 |
+
"djurant", "djusenberi", "djuharst", "djuherst", "dovdje", "dogrdje", "dodjel", "dosmrdj", "dugodjelujuć", "drvodje",
|
| 51 |
+
"drugdje", "elektrosnabdje", "endjurans", "žudje", "zabludje", "zavidje", "zavrijedje", "zagudje", "zadjev", "zadjen",
|
| 52 |
+
"zalebdje", "zaludje", "zaodje", "zapodje", "zaprdj", "zarudje", "zasjedje", "zasmrdje", "zastidje", "zaštedje", "zdje",
|
| 53 |
+
"zemljedjel", "zlodje", "igdje", "izbledje", "izblijedje", "izvidje", "izdjejst", "izdjelj", "izludje", "isprdje",
|
| 54 |
+
"jednodjel", "jednonedje", "koadjutor", "kojegdje", "kudjelj", "lebdje", "ludjel", "ludjet", "makfadjen", "marmadjuk",
|
| 55 |
+
"međudjel", "najdjelatn", "najdjelotvornij", "nadjaha", "nadjača", "nadjeb", "nadjev", "nadježd", "nadjezik", "nadjezič",
|
| 56 |
+
"nadjenul", "nadjenuo", "nadjenut", "nasmrdj", "neadjuvantne", "negdje", "nedjel", "nadjunač", "nenadjača", "nenadjebi",
|
| 57 |
+
"nenavidje", "neoadjuvant", "neodje", "nepodjarm", "neopredjel", "nepodjeljenoj", "nerazdje", "nigdje", "obdjel",
|
| 58 |
+
"obnevidje", "ovdje", "odjav", "odjad", "odjah", "odjaš", "odjeb", "odjev", "odjed", "odjezd", "odjek", "odjel",
|
| 59 |
+
"odjen", "odjeć", "odjec", "odjur", "odsjedje", "odjesen", "odječ", "ondje", "opredje", "oskudje", "osijedje",
|
| 60 |
+
"osmonedje", "otprdjeti", "pardju", "perdju", "petodjel", "petonedje", "poblijedje", "povidje", "pogdjegdje", "pogdje",
|
| 61 |
+
"podjaz", "podjakn", "podjamč", "podjastrebačk", "podjastu", "podjemč", "podjar", "podjeb", "podjed", "podjezer",
|
| 62 |
+
"podjezik", "podjezic", "podjezič", "podjel", "podjen", "podjesen", "podjet", "podjužnoslovenski", "podjurisdikcije",
|
| 63 |
+
"podjurne", "podjurnu", "podjuhorskom", "pododjel", "podrazdjel", "pozavidje", "poludje", "poljodjel", "ponegdje",
|
| 64 |
+
"ponedjelj", "poodjača", "poodjezdi", "poodjeknu", "poodjutri", "popridjevljen", "porazdje", "posijedje", "posjedje",
|
| 65 |
+
"postadjektiv", "postidje", "potpodjel", "poštedje", "pradjed", "prdje", "preblijedje", "previdje", "predvidje",
|
| 66 |
+
"preadjektiv", "predjel", "preodjen", "preraspodje", "presjedje", "pridjev", "pridjen", "predjugosl", "predjulijansk",
|
| 67 |
+
"predjustinijansk", "predjutar", "predjutr", "presmrdje", "prisnodjev", "prismrdje", "prištedje", "probdje",
|
| 68 |
+
"problijedje", "prodjen", "prolebdje", "prosijedje", "prosjedje", "prosmrdje", "protivdjel", "prošlonedje", "radjard",
|
| 69 |
+
"razvidje", "razdjev", "razdjel", "razodje", "raspodje", "rasprdje", "remekdjel", "rudjen", "rudjet", "samoadjungovan",
|
| 70 |
+
"samodjel", "samoopredjelje", "sadje", "svagdadjev", "svagdje", "svidje", "svugdje", "sedmonedjelj", "sijedje",
|
| 71 |
+
"sjedje", "smrdje", "snabdje", "snovidje", "sredjužnoslovensk", "starosjedje", "stidje", "studje", "sudjel", "transdjus",
|
| 72 |
+
"trejdjunion", "trodjeln", "tronedje", "ublijedje", "uvidje", "udjel", "udjen", "uprdje", "usidjel", "usjedje", "usmrdje",
|
| 73 |
+
"uštedje", "cjelonedje", "četverodjel", "četvoronedje", "čukundjed", "šestonedjelj", "štedje", "štogdje", "šukundjed"],
|
| 74 |
+
|
| 75 |
+
"dž": ["feldžandarm", "nadžanj", "nadžanr", "nadždrel", "nadžel", "nadžeo", "nadžet", "nadživ", "nadžinj", "nadžnj",
|
| 76 |
+
"nadžrec", "nadžup", "odžali", "odžari", "odžel", "odživ", "odžubor", "odžvaka", "odžval", "odžvać", "podžanr",
|
| 77 |
+
"podžargon", "podžel", "podže", "podžig", "podžiz", "podžil", "podžnje", "podžupan", "predželu", "predžetven", "predživot"],
|
| 78 |
+
|
| 79 |
+
"nj": ["anjon", "benjamin", "vanjezičk", "vanjezičn", "guanju", "dianjon", "injaric", "injekc", "injekt", "injicira",
|
| 80 |
+
"injurecesij", "injurij", "izvanjezičk", "izopolianjon", "kenjon", "konjug", "konjunk", "monoanjon", "nekonjug",
|
| 81 |
+
"nekonjunk", "netanjahu", "oksianjon", "panjevrej", "panjelinsk", "panjeremen", "panjugosl", "panjudej", "panjuridizacij",
|
| 82 |
+
"pinjin", "polianjon", "ssrnj", "subkonjunkt", "tanjug", "čanjol", "šenjang"],
|
| 83 |
+
|
| 84 |
+
"lj": ["dablju", "epljard", "hiljemark", "metiljodid", "teljurajd"]
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def cyr2lat(text: str) -> str:
|
| 89 |
+
return "".join(mapping.get(ch, ch) for ch in text)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def lat2cyr(text: str) -> str:
|
| 93 |
+
result = []
|
| 94 |
+
word_buffer = ""
|
| 95 |
+
i = 0
|
| 96 |
+
while i < len(text):
|
| 97 |
+
ch = text[i]
|
| 98 |
+
|
| 99 |
+
# If character not in any mapping key (single or digraph start), flush buffer
|
| 100 |
+
if not any(ch.lower() == k[0] for k in reverse_mapping.keys()):
|
| 101 |
+
if word_buffer:
|
| 102 |
+
result.append(_convert_word(word_buffer))
|
| 103 |
+
word_buffer = ""
|
| 104 |
+
result.append(ch) # keep the non‑mapped char (space, number, punctuation)
|
| 105 |
+
i += 1
|
| 106 |
+
continue
|
| 107 |
+
|
| 108 |
+
# Otherwise accumulate into buffer
|
| 109 |
+
word_buffer += ch
|
| 110 |
+
i += 1
|
| 111 |
+
|
| 112 |
+
# Flush last buffer
|
| 113 |
+
if word_buffer:
|
| 114 |
+
result.append(_convert_word(word_buffer))
|
| 115 |
+
|
| 116 |
+
return "".join(result)
|
| 117 |
+
|
| 118 |
+
def _convert_word(word: str) -> str:
|
| 119 |
+
i = 0
|
| 120 |
+
out = []
|
| 121 |
+
word_lower = word.lower() # compute once
|
| 122 |
+
while i < len(word):
|
| 123 |
+
matched = False
|
| 124 |
+
for digraph in ["dž", "lj", "nj", "dj"]:
|
| 125 |
+
if word_lower[i:i+len(digraph)] == digraph:
|
| 126 |
+
# check exceptions for this digraph
|
| 127 |
+
if any(word_lower.startswith(exc) for exc in digraphExceptions[digraph]):
|
| 128 |
+
# expand into individual letters
|
| 129 |
+
for ch in digraph:
|
| 130 |
+
out.append(reverse_mapping.get(ch, ch))
|
| 131 |
+
i += len(digraph)
|
| 132 |
+
else:
|
| 133 |
+
out.append(reverse_mapping[word[i:i+len(digraph)]])
|
| 134 |
+
i += len(digraph)
|
| 135 |
+
matched = True
|
| 136 |
+
break
|
| 137 |
+
if not matched:
|
| 138 |
+
out.append(reverse_mapping.get(word[i], word[i]))
|
| 139 |
+
i += 1
|
| 140 |
+
return "".join(out)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
class SrnaTokenizer(PreTrainedTokenizerFast): #
|
| 144 |
+
model_input_names = ["input_ids", "attention_mask"]
|
| 145 |
+
model = BPE
|
| 146 |
+
|
| 147 |
+
def __init__(
|
| 148 |
+
self,
|
| 149 |
+
tokenizer_file=None,
|
| 150 |
+
vocab: str | dict[str, int] | None = None,
|
| 151 |
+
merges: str | list[str] | None = None,
|
| 152 |
+
vocab_file=None,
|
| 153 |
+
merges_file=None,
|
| 154 |
+
unk_token: str = "<|endoftext|>",
|
| 155 |
+
bos_token=None,
|
| 156 |
+
eos_token: str = "<|endoftext|>",
|
| 157 |
+
pad_token: str = "<|endoftext|>",
|
| 158 |
+
add_prefix_space=None,
|
| 159 |
+
boc_token = "<csta>",
|
| 160 |
+
eoc_token = "<cend>",
|
| 161 |
+
cap_token = "<capi>",
|
| 162 |
+
up_token = "<uppe>",
|
| 163 |
+
case_compression = False,
|
| 164 |
+
script_compression = True,
|
| 165 |
+
omit_tags = False,
|
| 166 |
+
**kwargs,
|
| 167 |
+
):
|
| 168 |
+
self.add_prefix_space = add_prefix_space if add_prefix_space is not None else False
|
| 169 |
+
self.boc_token = boc_token
|
| 170 |
+
self.eoc_token = eoc_token
|
| 171 |
+
self.cap_token = cap_token
|
| 172 |
+
self.up_token = up_token
|
| 173 |
+
self.case_compression = case_compression
|
| 174 |
+
self.script_compression = script_compression
|
| 175 |
+
self.omit_tags = omit_tags
|
| 176 |
+
|
| 177 |
+
self._vocab = vocab
|
| 178 |
+
self._merges = merges
|
| 179 |
+
|
| 180 |
+
self.PRETOKENIZE_REGEX = r"""(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?[\p{L}\p{M}]+|\p{N}| ?[^\s\p{L}\p{M}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"""
|
| 181 |
+
self.CYRILLIC_REGEX = r"\s?\p{Cyrillic}[^\p{Latin}<\[|{}]*"
|
| 182 |
+
self.CLEANUP_FIND = rf"(\s+){regex.escape(self.eoc_token)}"
|
| 183 |
+
self.CLEANUP_REPLACE = rf"{regex.escape(self.eoc_token)}\1"
|
| 184 |
+
self.CAPITAL_REGEX = r"\s?\b\p{Lu}\p{Ll}+\b"
|
| 185 |
+
self.UPPER_REGEX = r"\s?\b\p{Lu}{2,}\b"
|
| 186 |
+
self.UP_FIND = rf"{regex.escape(self.up_token)}(\s?\w+)"
|
| 187 |
+
self.CAP_FIND = rf"{regex.escape(self.cap_token)}(\s?\w+)"
|
| 188 |
+
self.CYR_FIND = rf"{regex.escape(self.boc_token)}([\s\S]*?)({regex.escape(self.eoc_token)}|$)"
|
| 189 |
+
self._merges = merges or []
|
| 190 |
+
self._tokenizer = Tokenizer(
|
| 191 |
+
BPE(
|
| 192 |
+
vocab=self._vocab,
|
| 193 |
+
merges=self._merges,
|
| 194 |
+
dropout=None,
|
| 195 |
+
unk_token=None,
|
| 196 |
+
continuing_subword_prefix="",
|
| 197 |
+
end_of_word_suffix="",
|
| 198 |
+
fuse_unk=False,
|
| 199 |
+
byte_fallback=False,
|
| 200 |
+
)
|
| 201 |
+
)
|
| 202 |
+
self._tokenizer.decoder = decoders.ByteLevel()
|
| 203 |
+
self._tokenizer.normalizer = normalizers.NFC()
|
| 204 |
+
self._tokenizer.pre_tokenizer = pre_tokenizers.Sequence(
|
| 205 |
+
[
|
| 206 |
+
pre_tokenizers.Split(
|
| 207 |
+
Regex(self.PRETOKENIZE_REGEX),
|
| 208 |
+
behavior="isolated",
|
| 209 |
+
invert=False,
|
| 210 |
+
),
|
| 211 |
+
pre_tokenizers.ByteLevel(
|
| 212 |
+
add_prefix_space=self.add_prefix_space,
|
| 213 |
+
use_regex=False,
|
| 214 |
+
),
|
| 215 |
+
]
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
super().__init__(
|
| 219 |
+
tokenizer_file=tokenizer_file,
|
| 220 |
+
vocab_file=vocab_file,
|
| 221 |
+
merges_file=merges_file,
|
| 222 |
+
unk_token=unk_token,
|
| 223 |
+
bos_token=bos_token,
|
| 224 |
+
eos_token=eos_token,
|
| 225 |
+
pad_token=pad_token,
|
| 226 |
+
add_prefix_space=add_prefix_space,
|
| 227 |
+
**kwargs,
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
def prepare_for_tokenization(self, text, is_split_into_words=False, **kwargs):
|
| 231 |
+
# Handle None or non-string types gracefully
|
| 232 |
+
if text is None:
|
| 233 |
+
return ""
|
| 234 |
+
if isinstance(text, list):
|
| 235 |
+
# If a list is passed, recursively process each element
|
| 236 |
+
return [self.prepare_for_tokenization(t, is_split_into_words=is_split_into_words, **kwargs) for t in text]
|
| 237 |
+
if not isinstance(text, str):
|
| 238 |
+
text = str(text)
|
| 239 |
+
|
| 240 |
+
def mark_cap(match):
|
| 241 |
+
if self.omit_tags:
|
| 242 |
+
return match.group(0).lower()
|
| 243 |
+
return f"{self.cap_token}{match.group(0).lower()}"
|
| 244 |
+
|
| 245 |
+
def mark_up(match):
|
| 246 |
+
if self.omit_tags:
|
| 247 |
+
return match.group(0).lower()
|
| 248 |
+
return f"{self.up_token}{match.group(0).lower()}"
|
| 249 |
+
|
| 250 |
+
def wrap_and_transliterate(match):
|
| 251 |
+
cyr_text = match.group(0)
|
| 252 |
+
latin_text = cyr2lat(cyr_text)
|
| 253 |
+
if self.omit_tags:
|
| 254 |
+
return latin_text
|
| 255 |
+
return f"{self.boc_token}{latin_text}{self.eoc_token}"
|
| 256 |
+
|
| 257 |
+
if self.script_compression:
|
| 258 |
+
text = regex.sub(self.CYRILLIC_REGEX, wrap_and_transliterate, text)
|
| 259 |
+
if text.endswith(self.eoc_token):
|
| 260 |
+
text = text[: -len(self.eoc_token)]
|
| 261 |
+
text = regex.sub(self.CLEANUP_FIND, self.CLEANUP_REPLACE, text)
|
| 262 |
+
if self.case_compression:
|
| 263 |
+
text = regex.sub(self.CAPITAL_REGEX, mark_cap, text)
|
| 264 |
+
text = regex.sub(self.UPPER_REGEX, mark_up, text)
|
| 265 |
+
return text
|
| 266 |
+
|
| 267 |
+
def encode(self, text: str, *args, **kwargs):
|
| 268 |
+
text = self.prepare_for_tokenization(text)
|
| 269 |
+
return super().encode(text, *args, **kwargs)
|
| 270 |
+
|
| 271 |
+
def _encode_plus(self, text, *args, **kwargs):
|
| 272 |
+
if text is None:
|
| 273 |
+
text = ""
|
| 274 |
+
elif isinstance(text, list):
|
| 275 |
+
text = [str(t) if t is not None else "" for t in text]
|
| 276 |
+
elif not isinstance(text, str):
|
| 277 |
+
text = str(text)
|
| 278 |
+
|
| 279 |
+
if isinstance(text, str) and self.add_prefix_space:
|
| 280 |
+
text = text.lstrip("\n\t")
|
| 281 |
+
if not text.startswith(" "):
|
| 282 |
+
text = " " + text
|
| 283 |
+
|
| 284 |
+
# apply preprocessing hook safely
|
| 285 |
+
text = self.prepare_for_tokenization(text, **kwargs)
|
| 286 |
+
return super()._encode_plus(text, *args, **kwargs)
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
def decode(self, token_ids, *args, **kwargs):
|
| 290 |
+
text = super().decode(token_ids, *args, **kwargs)
|
| 291 |
+
|
| 292 |
+
# Helper function to apply regex decoding logic to a single string safely
|
| 293 |
+
def _decode_text_string(s: str) -> str:
|
| 294 |
+
if not isinstance(s, str):
|
| 295 |
+
s = str(s) if s is not None else ""
|
| 296 |
+
|
| 297 |
+
def decode_cyr(match):
|
| 298 |
+
return lat2cyr(match.group(1))
|
| 299 |
+
|
| 300 |
+
def decode_cap(match):
|
| 301 |
+
inner = match.group(1)
|
| 302 |
+
if not inner:
|
| 303 |
+
return inner
|
| 304 |
+
|
| 305 |
+
ws_match = regex.match(r"^\s*", inner)
|
| 306 |
+
leading_ws = ws_match.group(0) if ws_match else ""
|
| 307 |
+
|
| 308 |
+
if not leading_ws:
|
| 309 |
+
return inner[0].upper() + inner[1:] if len(inner) > 0 else inner
|
| 310 |
+
|
| 311 |
+
core = inner.lstrip()
|
| 312 |
+
if core:
|
| 313 |
+
core = core[0].upper() + core[1:]
|
| 314 |
+
return leading_ws + core
|
| 315 |
+
|
| 316 |
+
def decode_allcaps(match):
|
| 317 |
+
return match.group(1).upper()
|
| 318 |
+
|
| 319 |
+
if self.case_compression:
|
| 320 |
+
s = regex.sub(self.UP_FIND, decode_allcaps, s)
|
| 321 |
+
s = regex.sub(self.CAP_FIND, decode_cap, s)
|
| 322 |
+
if self.script_compression:
|
| 323 |
+
s = regex.sub(self.CYR_FIND, decode_cyr, s)
|
| 324 |
+
return s
|
| 325 |
+
|
| 326 |
+
# Safely process both single strings and list/batch returns
|
| 327 |
+
if isinstance(text, list):
|
| 328 |
+
return [_decode_text_string(t) for t in text]
|
| 329 |
+
return _decode_text_string(text)
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
__all__ = ["SrnaTokenizer"]
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:13c98d2f8a6dfb342bce22caea7938c0bf0754e628bc03b2d421525a16ee7180
|
| 3 |
+
size 19386093
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"auto_map": {
|
| 4 |
+
"AutoTokenizer": [
|
| 5 |
+
"tokenization_srna.SrnaTokenizer",
|
| 6 |
+
null
|
| 7 |
+
]
|
| 8 |
+
},
|
| 9 |
+
"backend": "tokenizers",
|
| 10 |
+
"boc_token": "<csta>",
|
| 11 |
+
"bos_token": null,
|
| 12 |
+
"cap_token": "<capi>",
|
| 13 |
+
"clean_up_tokenization_spaces": false,
|
| 14 |
+
"eoc_token": "<cend>",
|
| 15 |
+
"eos_token": "<|im_end|>",
|
| 16 |
+
"errors": "replace",
|
| 17 |
+
"is_local": true,
|
| 18 |
+
"local_files_only": false,
|
| 19 |
+
"merges_file": null,
|
| 20 |
+
"model_max_length": 262144,
|
| 21 |
+
"model_specific_special_tokens": {
|
| 22 |
+
"boc_token": "<csta>",
|
| 23 |
+
"cap_token": "<capi>",
|
| 24 |
+
"eoc_token": "<cend>",
|
| 25 |
+
"up_token": "<uppe>"
|
| 26 |
+
},
|
| 27 |
+
"pad_token": "<|endoftext|>",
|
| 28 |
+
"pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
|
| 29 |
+
"split_special_tokens": false,
|
| 30 |
+
"tokenizer_class": "SrnaTokenizer",
|
| 31 |
+
"unk_token": null,
|
| 32 |
+
"up_token": "<uppe>"
|
| 33 |
+
}
|
vrabac-cover.svg
ADDED
|
|