gsar78 commited on
Commit
249b7d4
·
verified ·
1 Parent(s): df49374

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +87 -0
README.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - wikimedia/wikipedia
5
+ - custom
6
+ language:
7
+ - en
8
+ pipeline_tag: text-generation
9
+ ---
10
+
11
+ ## Description
12
+ This is "Lemnos" , a new Instruction Tuned model based on the Llama 2 model architecture.
13
+
14
+ It was trained on general wikipedia corpus and then finetuned on a custom instruction dataset.
15
+
16
+ It is only for use as an experimental version prior launching a new one which also supports Greek.
17
+
18
+ ## Usage:
19
+
20
+ Prerequisites:
21
+
22
+ bitsandbytes-0.43.1
23
+
24
+ ```python
25
+ # Upgrade in case bitsandbytes already installed
26
+ pip install bitsandbytes -U
27
+ ```
28
+
29
+ ```python
30
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
31
+ import torch
32
+
33
+ # Specify the model hub
34
+ hub_model = 'gsar78/Lemnos_it_en_v2'
35
+
36
+ # Load the tokenizer
37
+ tokenizer = AutoTokenizer.from_pretrained(hub_model, trust_remote_code=True)
38
+
39
+ # Configure the BitsAndBytesConfig for 4-bit quantization
40
+ bnb_config = BitsAndBytesConfig(
41
+ load_in_4bit=True,
42
+ bnb_4bit_quant_type='nf4',
43
+ bnb_4bit_compute_dtype=torch.bfloat16,
44
+ bnb_4bit_use_double_quant=False
45
+ )
46
+
47
+ # Load the model with the specified configuration
48
+ model = AutoModelForCausalLM.from_pretrained(
49
+ hub_model,
50
+ quantization_config=bnb_config,
51
+ trust_remote_code=True,
52
+ device_map="auto"
53
+ )
54
+
55
+ # Function to generate text based on a prompt using the Alpaca format
56
+ def generate_text(prompt, max_length=512):
57
+ # Format the prompt according to the Alpaca format
58
+ alpaca_prompt = f"### Instruction:\n{prompt}\n\n### Response:\n"
59
+
60
+ # Tokenize the input prompt
61
+ inputs = tokenizer(alpaca_prompt, return_tensors="pt").to(model.device)
62
+
63
+ # Generate text using the model
64
+ outputs = model.generate(
65
+ input_ids=inputs['input_ids'],
66
+ max_length=max_length,
67
+ num_return_sequences=1,
68
+ pad_token_id=tokenizer.eos_token_id
69
+ )
70
+
71
+ # Decode the generated tokens to text
72
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
73
+
74
+ # Remove the prompt part from the output to get only the response
75
+ response = generated_text[len(alpaca_prompt):]
76
+
77
+ return response
78
+
79
+
80
+ # Example question
81
+ prompt = "What are the three basic colors?"
82
+ generated_text = generate_text(prompt)
83
+ print(generated_text)
84
+
85
+ # Output:
86
+ # Red, blue, and yellow.
87
+ ```