jais-finetuned-v1

Model Description:

This model is fine-tuned for paraphrasing Arabic sentences while preserving the original meaning of the sentence. It was trained using the Supervised Fine-Tuning (SFT) method on the Jais-13B model using the TRL library (SFTTrainer) and the PEFT/LoRA library.

To run the model on Colab with a single GPU (15 GB VRAM)

# -*- coding: utf-8 -*-

!pip install --upgrade bitsandbytes
!pip install -q datasets
!pip install -q trl
!pip install git+https://github.com/huggingface/peft.git
!pip install -q -U accelerate


from huggingface_hub import login
login()

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training, PeftModel, PeftConfig
from datasets import load_dataset
from transformers import TrainingArguments, pipeline
from trl import SFTTrainer

bnb_cfg = BitsAndBytesConfig(
    load_in_8bit=True,
#    bnb_4bit_quant_type="nf4", 
#    bnb_4bit_use_double_quant=True,
    bnb_4bit_compute_dtype="bfloat16",
)



import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_path = "3okasha/jais-finetuned-v1"

device = "cuda" if torch.cuda.is_available() else "cpu"

tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
    model_path, 
    quantization_config=bnb_cfg,
    device_map="auto", 
    trust_remote_code=True
    )

def user_prompt(human_prompt):
    prompt_template=f"input:\n{human_prompt}\n\nparaphrize:\n"
    return prompt_template


model.config.use_cache = False
if hasattr(model, "generation_config"): model.generation_config.use_cache = False

def get_response(text,tokenizer=tokenizer,model=model):
    input_ids = tokenizer(text, return_tensors="pt").input_ids
    inputs = input_ids.to(device)
    input_len = inputs.shape[-1]
    generate_ids = model.generate(
        inputs,
        top_p=0.9,
        temperature=0.3,
        max_length=50-input_len,
        min_length=input_len + 4,
        repetition_penalty=1.2,
        do_sample=True,
    )
    response = tokenizer.batch_decode(
        generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
    )[0]
    return response


text= user_prompt("أعتقد يمكننا أن نبدأ")
print(get_response(text))
## أعتقد أنه يمكننا البدأ
## أعتقد أننا يمكن أن نبدأ
Downloads last month
64
Safetensors
Model size
13B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for 3okasha/jais-finetuned-v1

Adapter
(3)
this model

Dataset used to train 3okasha/jais-finetuned-v1