Edit model card

UAlpaca: Ukrainian instruction-tuned LLaMA

Usage

Check the Github repo with code and dataset: https://github.com/robinhad/kruk

Generation Example: Open In Colab

Requirements

pip install bitsandbytes
pip install -q datasets loralib sentencepiece
pip install -q git+https://github.com/zphang/transformers@c3dc391 # this model uses a fork of transformers that provides LLaMA tokenizer; this wasn't merged yet
pip install -q git+https://github.com/huggingface/peft.git
from peft import PeftModel
from transformers import LLaMATokenizer, LLaMAForCausalLM, GenerationConfig

tokenizer = LLaMATokenizer.from_pretrained("decapoda-research/llama-7b-hf")
model = LLaMAForCausalLM.from_pretrained(
    "decapoda-research/llama-7b-hf",
    load_in_8bit=True,
    device_map="auto",
)
model = PeftModel.from_pretrained(model, "robinhad/ualpaca-7b-llama")

# convert input to correct prompt
def generate_prompt(instruction, input=None):
    if input:
        return f"""Унизу надається інструкція, яка описує завдання разом із вхідними даними, які надають додатковий контекст. Напиши відповідь, яка правильно доповнює запит.

### Інструкція:
{instruction}

### Вхідні дані:
{input}

### Відповідь:"""
    else:
        return f"""Унизу надається інструкція, яка описує завдання. Напиши відповідь, яка правильно доповнює запит.

### Інструкція:
{instruction}

### Відповідь:"""

# config and inference
generation_config = GenerationConfig(
    temperature=0.2,
    top_p=0.75,
    num_beams=4,
)

def evaluate(instruction, input=None):
    prompt = generate_prompt(instruction, input)
    inputs = tokenizer(prompt, return_tensors="pt")
    input_ids = inputs["input_ids"].cuda()
    generation_output = model.generate(
        input_ids=input_ids,
        generation_config=generation_config,
        return_dict_in_generate=True,
        output_scores=True,
        max_new_tokens=256
    )
    for s in generation_output.sequences:
        output = tokenizer.decode(s)
        print("Відповідь:", output.split("### Відповідь:")[1].strip())

input_data = "Як звали батька Тараса Григоровича Шевченка?"
print("Інструкція:", input_data)
evaluate("Інструкція: " + input_data)
Downloads last month
0
Unable to determine this model's library. Check the docs .