BramVanroy commited on
Commit
c62ce8c
·
1 Parent(s): 6d18a4e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +75 -1
README.md CHANGED
@@ -17,11 +17,85 @@ model-index:
17
  This model is a fine-tuned version of [tiiuae/falcon-40b](https://huggingface.co/tiiuae/falcon-40b) on the [BramVanroy/alpaca-dolly-dutch](https://huggingface.co/datasets/BramVanroy/alpaca-dolly-dutch) dataset.
18
  See the original [tiiuae/falcon-40b](https://huggingface.co/tiiuae/falcon-40b) for more information, intended use, and biases.
19
 
20
-
21
  ## Intended uses & limitations
22
 
23
  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.
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ## Training and evaluation data
26
 
27
  Trained on the synthetic [BramVanroy/alpaca-dolly-dutch](https://huggingface.co/datasets/BramVanroy/alpaca-dolly-dutch) instruction dataset.
 
17
  This model is a fine-tuned version of [tiiuae/falcon-40b](https://huggingface.co/tiiuae/falcon-40b) on the [BramVanroy/alpaca-dolly-dutch](https://huggingface.co/datasets/BramVanroy/alpaca-dolly-dutch) dataset.
18
  See the original [tiiuae/falcon-40b](https://huggingface.co/tiiuae/falcon-40b) for more information, intended use, and biases.
19
 
 
20
  ## Intended uses & limitations
21
 
22
  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.
23
 
24
+ ## Example usage
25
+
26
+ 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").
27
+
28
+ The model "replies" (cut off due to `max_new_tokens`):
29
+
30
+ > "Auto" hoort niet in het rijtje, omdat het geen levend wezen is.
31
+ > 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.
32
+ > Auto's zijn gemaakt van metalen, plastic en andere materialen, terwijl levende organismen bestaan uit cellen en weefsels. Auto's
33
+
34
+ ```python
35
+ import torch
36
+ from transformers import AutoModelForCausalLM, AutoTokenizer
37
+
38
+
39
+ def format_alpaca_sample(instruction: str, input_text: str):
40
+ if len(input_text) >= 2:
41
+ 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.
42
+
43
+ ### Instruction:
44
+ {instruction}
45
+
46
+ ### Input:
47
+ {input_text}
48
+
49
+ ### Response:
50
+
51
+ '''
52
+ else:
53
+ 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.
54
+
55
+ ### Instruction:
56
+ {instruction}
57
+
58
+ ### Response:
59
+ '''
60
+ return text
61
+
62
+
63
+ @torch.no_grad()
64
+ def generate(model, tokenizer, instruction: str, input_text: str = ""):
65
+ input_prompt = format_alpaca_sample(instruction, input_text)
66
+ inputs = tokenizer([input_prompt], return_tensors="pt")
67
+ generated_ids = model.generate(
68
+ input_ids=inputs["input_ids"].to(model.device),
69
+ attention_mask=inputs["attention_mask"].to(model.device),
70
+ max_new_tokens=128,
71
+ temperature=0.4,
72
+ num_beams=3,
73
+ no_repeat_ngram_size=4,
74
+ length_penalty=0.9,
75
+ early_stopping=True,
76
+ num_return_sequences=1,
77
+ eos_token_id=tokenizer.eos_token_id,
78
+ ).detach().to("cpu")[0]
79
+ return tokenizer.decode(generated_ids)
80
+
81
+
82
+ model_name = "BramVanroy/falcon-40b-ft-alpaca-dolly-dutch"
83
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
84
+ model = AutoModelForCausalLM.from_pretrained(
85
+ model_name,
86
+ load_in_4bit=True,
87
+ torch_dtype=torch.bfloat16,
88
+ trust_remote_code=True,
89
+ device_map="auto"
90
+ )
91
+ model.eval()
92
+
93
+ instruction = "Wat hoort er niet in dit rijtje thuis? Leg ook uit waarom."
94
+ input_text = "aap, muis, auto, vogel"
95
+ generation = generate(model, tokenizer, instruction, input_text)
96
+
97
+ ```
98
+
99
  ## Training and evaluation data
100
 
101
  Trained on the synthetic [BramVanroy/alpaca-dolly-dutch](https://huggingface.co/datasets/BramVanroy/alpaca-dolly-dutch) instruction dataset.