nazimali commited on
Commit
7aec795
1 Parent(s): f68d197

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -1
README.md CHANGED
@@ -56,7 +56,7 @@ llm.create_chat_completion(
56
  messages = [
57
  {
58
  "role": "user",
59
- "content": inference_prompt.format("selam alikum, tu çawa yî?")
60
  }
61
  ]
62
  )
@@ -75,8 +75,19 @@ llm.create_chat_completion(
75
  #### Transformers
76
 
77
  ```python
 
 
 
78
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
79
 
 
 
 
 
 
 
 
 
80
  model_id = "nazimali/Mistral-Nemo-Kurdish-Instruct"
81
 
82
  tokenizer = AutoTokenizer.from_pretrained(model_id)
@@ -93,6 +104,39 @@ model = AutoModelForCausalLM.from_pretrained(
93
  quantization_config=bnb_config,
94
  device_map="auto",
95
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  ```
97
 
98
  ### Training
 
56
  messages = [
57
  {
58
  "role": "user",
59
+ "content": inference_prompt.format("سڵاو ئەلیکوم، چۆنیت؟")
60
  }
61
  ]
62
  )
 
75
  #### Transformers
76
 
77
  ```python
78
+ from http.client import responses
79
+
80
+ import torch
81
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
82
 
83
+ infer_prompt = """Li jêr rêwerzek heye ku peywirek rave dike, bi têketinek ku çarçoveyek din peyda dike ve tê hev kirin. Bersivek ku daxwazê ​​bi guncan temam dike binivîsin.
84
+ ### Telîmat:
85
+ {}
86
+ ### Têketin:
87
+ {}
88
+ ### Bersiv:
89
+ """
90
+
91
  model_id = "nazimali/Mistral-Nemo-Kurdish-Instruct"
92
 
93
  tokenizer = AutoTokenizer.from_pretrained(model_id)
 
104
  quantization_config=bnb_config,
105
  device_map="auto",
106
  )
107
+
108
+ model.eval()
109
+
110
+
111
+ def call_llm(user_input, instructions=None):
112
+ instructions = instructions or "tu arîkarek alîkar î"
113
+ prompt = infer_prompt.format(instructions, user_input)
114
+
115
+ input_ids = tokenizer(
116
+ prompt,
117
+ return_tensors="pt",
118
+ add_special_tokens=False,
119
+ return_token_type_ids=False,
120
+ ).to("cuda")
121
+
122
+ with torch.inference_mode():
123
+ generated_ids = model.generate(
124
+ **input_ids,
125
+ max_new_tokens=120,
126
+ do_sample=True,
127
+ temperature=0.7,
128
+ top_p=0.7,
129
+ num_return_sequences=1,
130
+ pad_token_id=tokenizer.pad_token_id,
131
+ eos_token_id=tokenizer.eos_token_id,
132
+ )
133
+
134
+ decoded_output = tokenizer.batch_decode(generated_ids)[0]
135
+
136
+ return decoded_output.replace(prompt, "").replace("</s>", "")
137
+
138
+ response = call_llm("سڵاو ئەلیکوم، چۆنیت؟")
139
+ print(response)
140
  ```
141
 
142
  ### Training