Edit model card

falcon-40b-ft-alpaca-dolly-dutch

Model description

This model is a fine-tuned version of tiiuae/falcon-40b on the BramVanroy/alpaca-dolly-dutch dataset. See the original tiiuae/falcon-40b for more information, intended use, and biases.

Intended uses & limitations

This model is intended as a (poor) baseline for Dutch generative LLMs. It by no means aims to provide SOTA performance and is specifically intended for research purposes and experimentation.

Example usage

In the example below, you see a query Wat hoort er niet in dit rijtje thuis? Leg ook uit waarom. ("What does not belong in the list? Explain why.") with given input "aap, muis, auto, vogel" ("monkey, mouse, car, bird").

The model "replies" (cut off due to max_new_tokens):

"Auto" hoort niet in het rijtje, omdat het geen levend wezen is. Een auto is een voertuig dat wordt aangedreven door een motor en wordt gebruikt om mensen en goederen van de ene plaats naar de andere te verplaatsen. Het is een machine gemaakt door mensen, in tegenstelling tot levende wezens zoals een aap, een muis of een vogel. Auto's zijn gemaakt van metalen, plastic en andere materialen, terwijl levende organismen bestaan uit cellen en weefsels. Auto's

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer


def format_alpaca_sample(instruction: str, input_text: str):
    if len(input_text) >= 2:
        text = f'''Hieronder staat een instructie `Instruction` die een taak beschrijft, gecombineerd met een invoer `Input` die verdere context biedt. Schrijf een antwoord na `Response:` dat het verzoek op de juiste manier voltooit of beantwoordt.

### Instruction:
{instruction}

### Input:
{input_text}

### Response:

'''
    else:
        text = f'''Hieronder staat een instructie `Instruction` die een taak beschrijft. Schrijf een antwoord na `Response:` dat het verzoek op de juiste manier voltooit of beantwoordt.

### Instruction:
{instruction}

### Response:
'''
    return text


@torch.no_grad()
def generate(model, tokenizer, instruction: str, input_text: str = ""):
    input_prompt = format_alpaca_sample(instruction, input_text)
    inputs = tokenizer([input_prompt], return_tensors="pt")
    generated_ids = model.generate(
        input_ids=inputs["input_ids"].to(model.device),
        attention_mask=inputs["attention_mask"].to(model.device),
        max_new_tokens=128,
        temperature=0.4,
        num_beams=3,
        no_repeat_ngram_size=4,
        length_penalty=0.9,
        early_stopping=True,
        num_return_sequences=1,
        eos_token_id=tokenizer.eos_token_id,
    ).detach().to("cpu")[0]
    return tokenizer.decode(generated_ids)


model_name = "BramVanroy/falcon-40b-ft-alpaca-dolly-dutch"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    load_in_4bit=True,
    torch_dtype=torch.bfloat16,
    trust_remote_code=True,
    device_map="auto"
)
model.eval()

instruction = "Wat hoort er niet in dit rijtje thuis? Leg ook uit waarom."
input_text = "aap, muis, auto, vogel"
generation = generate(model, tokenizer, instruction, input_text)

Citation

If you want to refer to this model, you can cite the following:

Vanroy, B. (2023). Falcon 40B Finetuned on Dutch Translations of Alpca and Dolly. https://doi.org/10.57967/hf/0864

@misc{vanroy2023falcon40b_instruct_dutch,
    author       = { Vanroy, Bram },
    title        = { Falcon 40B Finetuned on Dutch Translations of Alpaca and Dolly},
    year         = 2023,
    url          = { https://huggingface.co/BramVanroy/falcon-40b-ft-alpaca-dolly-dutch },
    doi          = { 10.57967/hf/0864 },
    publisher    = { Hugging Face }
}

Training and evaluation data

Trained on the synthetic BramVanroy/alpaca-dolly-dutch instruction dataset. Therefore, commercial use of this model is forbidden. The model is intended for research purposes only.

Training procedure

Trained with LoRA and merged before upload. The adapters are in the adapters branch.

Prompt template (where the input is optional and can be left out):

Hieronder staat een instructie `Instruction` die een taak beschrijft, gecombineerd met een invoer `Input` die verdere context biedt. Schrijf een antwoord na `Response:` dat het verzoek op de juiste manier voltooit of beantwoordt.

### Instruction:
{instruction}

### Input:
{input}

### Response:
{response}

The loss was only calculated on the response prediction.

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 0.0002
  • train_batch_size: 8
  • eval_batch_size: 8
  • seed: 42
  • distributed_type: multi-GPU
  • num_devices: 16
  • gradient_accumulation_steps: 4
  • total_train_batch_size: 512
  • total_eval_batch_size: 128
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lr_scheduler_type: linear
  • lr_scheduler_warmup_steps: 150
  • num_epochs: 5 (but with early stopping)

Training results

Training Loss Epoch Step Validation Loss
1.1656 0.16 20 1.0107
0.9778 0.32 40 0.9711
1.0424 0.49 60 0.9512
0.9858 0.65 80 0.9415
0.9457 0.81 100 0.9341
1.0584 0.97 120 0.9277
1.0284 1.14 140 0.9372
0.8781 1.3 160 0.9295
0.9531 1.46 180 0.9267
0.9496 1.62 200 0.9226
0.9178 1.78 220 0.9192
1.0763 1.95 240 0.9154
0.9561 2.11 260 0.9423
0.7991 2.27 280 0.9368
0.8503 2.43 300 0.9363
0.8749 2.6 320 0.9299

Framework versions

  • Transformers 4.30.1
  • Pytorch 2.0.1+cu117
  • Datasets 2.13.1
  • Tokenizers 0.13.3
Downloads last month
3
Safetensors
Model size
41.3B params
Tensor type
BF16
·
Inference Examples
Inference API (serverless) has been turned off for this model.

Finetuned from

Collection including BramVanroy/falcon-40b-ft-alpaca-dolly-dutch