Downloads · 30 days
1
25% of all-time downloads
C00LD3R/eng2kab-TB
eng2kab-TB is a machine learning model from C00LD3R. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A transformer-based sequence-to-sequence model for machine translation task
Downloads · 30 days
1
25% of all-time downloads
All-time downloads
4
Public
Parameters
85.7M
343 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors343 MB · 99%
From the Hugging Face model README
A transformer-based sequence-to-sequence model for machine translation task
from transformers import AutoTokenizer
from model import Seq2SeqTransformer, Config
import yaml
import torch
# Load config
with open("config.yaml", "r") as f:
config_dict = yaml.safe_load(f)
config = Config(**config_dict)
token_config = {
"add_special_tokens": config.add_special_tokens,
"return_tensors": config.return_tensors,
}
# Auto-detect device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load tokenizers
source_tokenizer = AutoTokenizer.from_pretrained("C00LD3R/eng2kab-TB/source_tokenizer")
target_tokenizer = AutoTokenizer.from_pretrained("C00LD3R/eng2kab-TB/target_tokenizer")
# Initialize model
model = Seq2SeqTransformer(
num_encoder_layers=config.num_encoder_layers,
num_decoder_layers=config.num_decoder_layers,
emb_size=config.emb_size,
nhead=config.nhead,
src_vocab_size=config.source_vocab_size,
tgt_vocab_size=config.target_vocab_size,
dim_feedforward=config.ffn_hid_dim,
dropout=0.1,
token_config=token_config,
source_tokenizer=source_tokenizer,
target_tokenizer=target_tokenizer
)
# Load weights
with safe_open("model.safetensors", framework="pt", device=device.type) as f:
state_dict = {key: f.get_tensor(key) for key in f.keys()}
model.load_state_dict(state_dict)
#using greedy
translation = model.translate(model,"hi")
#using beam
translation = model.translate_with_beam_search(model,"hi",lenght_extend= 0, beam_size= 5, raw= False, length_penalty= 0.6)