avans06 commited on
Commit
df97ddb
1 Parent(s): e8db960

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +23 -6
README.md CHANGED
@@ -308,11 +308,11 @@ Where to send questions or comments about the model Instructions on how to provi
308
 
309
  ## How to use
310
 
311
- This repository for use with `[CTranslate2](https://github.com/OpenNMT/CTranslate2)`.
312
 
313
  ### Use with CTranslate2
314
 
315
- This example code is obtained from [CTranslate2_transformers](https://opennmt.net/CTranslate2/guides/transformers.html#mpt).
316
  More detailed information about the `generate_batch` methon can be found at [CTranslate2_Generator.generate_batch](https://opennmt.net/CTranslate2/python/ctranslate2.Generator.html#ctranslate2.Generator.generate_batch).
317
 
318
  ```python
@@ -320,14 +320,31 @@ import ctranslate2
320
  import transformers
321
 
322
  model_id = "avans06/Meta-Llama-3-8B-Instruct-ct2-int8_float16"
323
- generator = ctranslate2.Generator(model_id, device="auto", compute_type="int8_float16")
324
  tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
325
 
326
- prompt = "What is the meaning of Large language model?"
327
- input_tokens = tokenizer.convert_ids_to_tokens(tokenizer.encode(prompt))
 
 
328
 
329
- results = generator.generate_batch([input_tokens], include_prompt_in_result=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  output = tokenizer.decode(results[0].sequences_ids[0])
 
 
331
  ```
332
 
333
  ## Hardware and Software
 
308
 
309
  ## How to use
310
 
311
+ This repository for use with [CTranslate2](https://github.com/OpenNMT/CTranslate2).
312
 
313
  ### Use with CTranslate2
314
 
315
+ This example code is obtained from [CTranslate2_transformers](https://opennmt.net/CTranslate2/guides/transformers.html#mpt) and [tokenizer AutoTokenizer](https://huggingface.co/docs/transformers/main_classes/tokenizer).
316
  More detailed information about the `generate_batch` methon can be found at [CTranslate2_Generator.generate_batch](https://opennmt.net/CTranslate2/python/ctranslate2.Generator.html#ctranslate2.Generator.generate_batch).
317
 
318
  ```python
 
320
  import transformers
321
 
322
  model_id = "avans06/Meta-Llama-3-8B-Instruct-ct2-int8_float16"
323
+ model = ctranslate2.Generator(model_id, device="auto", compute_type="int8_float16")
324
  tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
325
 
326
+ messages = [
327
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
328
+ {"role": "user", "content": "Who are you?"},
329
+ ]
330
 
331
+ input_ids = tokenizer.apply_chat_template(
332
+ messages,
333
+ tokenize=False,
334
+ add_generation_prompt=True
335
+ )
336
+
337
+ terminators = [
338
+ tokenizer.eos_token_id,
339
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
340
+ ]
341
+
342
+ input_tokens = tokenizer.convert_ids_to_tokens(tokenizer.encode(input_ids))
343
+
344
+ results = model.generate_batch([input_tokens], include_prompt_in_result=False, max_length=256, sampling_temperature=0.6, sampling_topp=0.9, end_token=terminators)
345
  output = tokenizer.decode(results[0].sequences_ids[0])
346
+
347
+ print(output)
348
  ```
349
 
350
  ## Hardware and Software