Downloads · 30 days
27
100% of all-time downloads
antontuzovAI/universal-translator-ru-en
universal-translator-ru-en is a translation model from antontuzovAI. Use it when you need text moved from one language to another. The card lists the license as mit.
This is a custom autoregressive translator that converts Russian text into English using a Universal Transformer architecture with Mixture of Experts (MoE) and Multi-Head Latent Attention (MLA).
Downloads · 30 days
27
100% of all-time downloads
All-time downloads
27
Public
Repo size
184 MB
Likes
0
Public
Click a slice to open those files.
.pth184 MB · 100%
From the Hugging Face model README
This is a custom autoregressive translator that converts Russian text into English using a Universal Transformer architecture with Mixture of Experts (MoE) and Multi-Head Latent Attention (MLA).
Trained on the Helsinki-NLP/opus_books parallel corpus (Russian-English book translations).
pip install torch tiktoken huggingface_hub
You must define the model classes (RMSNorm, SwiGLU, MultiHeadLatentAttention, DeepSeekMoE, UniversalBlock, UniversalTranslator) from the training script first.
import torch, json
import tiktoken
from huggingface_hub import hf_hub_download
repo_id = 'antontuzovAI/universal-translator-ru-en'
config_path = hf_hub_download(repo_id=repo_id, filename='config.json')
weights_path = hf_hub_download(repo_id=repo_id, filename='model_weights.pth')
with open(config_path, 'r') as f:
config = json.load(f)
enc = tiktoken.get_encoding('gpt2')
model = UniversalTranslator(**config)
model.load_state_dict(torch.load(weights_path, map_location='cpu'))
model.eval()
def translate(russian_text):
prompt = f'RU: {russian_text}\nEN: '
tokens = enc.encode(prompt, allowed_special={'<|endoftext|>'})
x = torch.tensor([tokens])
with torch.no_grad():
for _ in range(100):
logits = model(x)
next_token = torch.argmax(logits[:, -1, :], dim=-1, keepdim=True)
x = torch.cat([x, next_token], dim=1)
if next_token.item() == enc.eot_token:
break
return enc.decode(x[0].tolist()).split('EN: ')[-1].replace('<|endoftext|>', '').strip()
print(translate('Привет, как дела?'))
The model was trained on autoregressive pairs formatted as:
RU: [Russian text]
EN: [English text]
For best results, keep input sentences concise (under 30 words).