Views
No views yet
indic-transliteration.1pip install pip3-autoremove
2pip-autoremove torch torchvision torchaudio -y
3pip install torch torchvision torchaudio xformers --index-url https://download.pytorch.org/whl/cu121
4pip install unsloth datasets bitsandbytes
5pip uninstall unsloth -y && pip install --upgrade --no-cache-dir --no-deps git+https://github.com/unslothai/unsloth.gitpip install --no-deps packaging ninja einops "flash-attn>=2.6.3"english_to_hindi.csv) with the following structure:1english,hindi
2"Did you see that goal? That was a beauty, eh?","क्या आपने उस गोल को देखा? वह एक सुंदर था, है ना?"list_ds = convert_csv_to_json_format("/content/english_to_hindi.csv")1[
2 {
3 "instruction": "Translate this to English",
4 "input": "क्या आपने उस गोल को देखा? वह एक सुंदर था, है ना?",
5 "output": "Did you see that goal? That was a beauty, eh?"
6 },
7 {
8 "instruction": "Translate this to Hindi",
9 "input": "Did you see that goal? That was a beauty, eh?",
10 "output": "क्या आपने उस गोल को देखा? वह एक सुंदर था, है ना?"
11 }
12]1model, tokenizer = FastLanguageModel.from_pretrained(
2 model_name="unsloth/gemma-2-9b",
3 max_seq_length=2048,
4 dtype=None,
5 load_in_4bit=True,
6)1model = FastLanguageModel.get_peft_model(
2 model,
3 r=16,
4 target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
5 lora_alpha=16,
6 lora_dropout=0,
7 bias="none",
8 use_gradient_checkpointing="unsloth",
9 random_state=3407,
10 use_rslora=False,
11 loftq_config=None,
12)1training_args = TrainingArguments(
2 output_dir="./english-hindi-colloquial",
3 per_device_train_batch_size=4,
4 num_train_epochs=10,
5 learning_rate=3e-4,
6 weight_decay=0.01,
7 logging_steps=1,
8 evaluation_strategy="steps",
9 eval_steps=2,
10 save_steps=2,
11 push_to_hub=True,
12 hub_model_id="Amrutha23345/english_to_hindi_colloquial_translator",
13 fp16=True,
14 gradient_checkpointing=True
15)1trainer = SFTTrainer(
2 model=model,
3 tokenizer=tokenizer,
4 train_dataset=dataset,
5 dataset_text_field="text",
6 args=training_args,
7)
8trainer.train()
9trainer.save_model()
10trainer.push_to_hub()1inputs = tokenizer([
2 alpaca_prompt.format("Translate to English", "क्या आपने उस गोल को देखा? वह एक सुंदर था, है ना?", "")
3], return_tensors="pt").to("cuda")
4
5text_streamer = TextStreamer(tokenizer)
6_ = model.generate(**inputs, streamer=text_streamer, max_new_tokens=128)1from indic_transliteration import sanscript
2from indic_transliteration.sanscript import transliterate
3
4hindi_response = "क्या आपने उस गोल को देखा? वह एक सुंदर था, है ना?"
5hinglish_response = transliterate(hindi_response, sanscript.DEVANAGARI, sanscript.ITRANS)
6print("Hinglish Output:", hinglish_response)Hinglish Output: kya aapne us goal ko dekha? vah ek sundar tha, hai na?1used_memory = round(torch.cuda.max_memory_reserved() / 1024 / 1024 / 1024, 3)
2print(f"Peak reserved memory = {used_memory} GB.")trainer.push_to_hub()Amrutha23345/english_to_hindi_colloquial_translator