Vihang D
commited on
Commit
·
5242895
1
Parent(s):
16cfed1
Add bengali lora model
Browse files- README.md +90 -0
- adapter_config.json +21 -0
- adapter_model.bin +3 -0
README.md
CHANGED
@@ -1,3 +1,93 @@
|
|
1 |
---
|
2 |
license: other
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: other
|
3 |
---
|
4 |
+
# Hugging Face Model - Bengali Finetuned
|
5 |
+
|
6 |
+
This repository contains a Hugging Face model that has been fine-tuned on a Bengali dataset. The model uses the `peft` library for generating responses.
|
7 |
+
|
8 |
+
## Usage
|
9 |
+
|
10 |
+
To use the model, first import the necessary libraries:
|
11 |
+
|
12 |
+
```python
|
13 |
+
from peft import PeftModel
|
14 |
+
from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
|
15 |
+
```
|
16 |
+
|
17 |
+
Next, load the tokenizer and model:
|
18 |
+
|
19 |
+
```python
|
20 |
+
tokenizer = LlamaTokenizer.from_pretrained("yahma/llama-7b-hf")
|
21 |
+
model = LlamaForCausalLM.from_pretrained(
|
22 |
+
"yahma/llama-7b-hf",
|
23 |
+
load_in_8bit=True,
|
24 |
+
device_map="auto",
|
25 |
+
)
|
26 |
+
```
|
27 |
+
|
28 |
+
Then, load the `PeftModel` with the specified pre-trained model and path to the peft model:
|
29 |
+
|
30 |
+
```python
|
31 |
+
model = PeftModel.from_pretrained(model, "./bengali-dolly-alpaca-lora-7b")
|
32 |
+
```
|
33 |
+
|
34 |
+
Next, define a function to generate a prompt:
|
35 |
+
|
36 |
+
```python
|
37 |
+
def generate_prompt(instruction, input=None):
|
38 |
+
if input:
|
39 |
+
return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
40 |
+
|
41 |
+
### Instruction:
|
42 |
+
{instruction}
|
43 |
+
|
44 |
+
### Input:
|
45 |
+
{input}
|
46 |
+
|
47 |
+
### Response:"""
|
48 |
+
else:
|
49 |
+
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
50 |
+
|
51 |
+
### Instruction:
|
52 |
+
{instruction}
|
53 |
+
|
54 |
+
### Response:"""
|
55 |
+
```
|
56 |
+
|
57 |
+
Finally, define a function to evaluate the model:
|
58 |
+
|
59 |
+
```python
|
60 |
+
generation_config = GenerationConfig(
|
61 |
+
temperature=0.1,
|
62 |
+
top_p=0.75,
|
63 |
+
num_beams=4,
|
64 |
+
)
|
65 |
+
|
66 |
+
def evaluate(model, instruction, input=None):
|
67 |
+
prompt = generate_prompt(instruction, input)
|
68 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
69 |
+
input_ids = inputs["input_ids"].cuda()
|
70 |
+
generation_output = model.generate(
|
71 |
+
input_ids=input_ids,
|
72 |
+
generation_config=generation_config,
|
73 |
+
return_dict_in_generate=True,
|
74 |
+
output_scores=True,
|
75 |
+
max_new_tokens=256
|
76 |
+
)
|
77 |
+
for s in generation_output.sequences:
|
78 |
+
output = tokenizer.decode(s)
|
79 |
+
print("Response:", output.split("### Response:")[1].strip())
|
80 |
+
|
81 |
+
instruct =input("Instruction: ")
|
82 |
+
evaluate(model, instruct)
|
83 |
+
```
|
84 |
+
|
85 |
+
To generate a response, simply run the `evaluate` function with an instruction and optional input:
|
86 |
+
|
87 |
+
```python
|
88 |
+
instruct = "Write a response that appropriately completes the request."
|
89 |
+
input = "This is a sample input."
|
90 |
+
evaluate(model, instruct, input)
|
91 |
+
```
|
92 |
+
|
93 |
+
This will output a response that completes the request.
|
adapter_config.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"base_model_name_or_path": "yahma/llama-7b-hf",
|
3 |
+
"bias": "none",
|
4 |
+
"enable_lora": null,
|
5 |
+
"fan_in_fan_out": false,
|
6 |
+
"inference_mode": true,
|
7 |
+
"init_lora_weights": true,
|
8 |
+
"lora_alpha": 16,
|
9 |
+
"lora_dropout": 0.05,
|
10 |
+
"merge_weights": false,
|
11 |
+
"modules_to_save": null,
|
12 |
+
"peft_type": "LORA",
|
13 |
+
"r": 16,
|
14 |
+
"target_modules": [
|
15 |
+
"q_proj",
|
16 |
+
"k_proj",
|
17 |
+
"v_proj",
|
18 |
+
"o_proj"
|
19 |
+
],
|
20 |
+
"task_type": "CAUSAL_LM"
|
21 |
+
}
|
adapter_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d348d189011539f0e36e32503fb33fb62283b8800bd54462d859e1eef6c1ff0f
|
3 |
+
size 67201357
|