Kumar955 commited on
Commit
7433e6a
·
verified ·
1 Parent(s): 871325c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -6
README.md CHANGED
@@ -46,25 +46,35 @@ from transformers import AutoTokenizer
46
  import transformers
47
  import torch
48
 
 
49
  model = "Kumar955/Hemanth-llm"
 
 
 
50
  messages = [{"role": "user", "content": "What is a large language model?"}]
51
 
52
- tokenizer = AutoTokenizer.from_pretrained(model)
 
53
 
54
- # Define a chat template
55
- chat_template = """<s><|user|>{{ user_message }}<|assistant|>"""
56
 
57
- # Use the chat template in apply_chat_template
58
- prompt = tokenizer.apply_chat_template(messages, chat_template=chat_template, tokenize=False, add_generation_prompt=True)
59
 
60
- pipeline = transformers.pipeline(
 
61
  "text-generation",
62
  model=model,
63
  torch_dtype=torch.float16,
64
  device_map="auto",
65
  )
66
 
 
67
  outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
 
 
68
  print(outputs[0]["generated_text"])
69
 
 
70
  ```
 
46
  import transformers
47
  import torch
48
 
49
+ # Load tokenizer and model
50
  model = "Kumar955/Hemanth-llm"
51
+ tokenizer = AutoTokenizer.from_pretrained(model)
52
+
53
+ # Define the messages from the conversation
54
  messages = [{"role": "user", "content": "What is a large language model?"}]
55
 
56
+ # Define the chat template for formatting the conversation
57
+ chat_template = """<s><|user|>{{ user_message }}<|assistant|>"""
58
 
59
+ # Extract the user message content
60
+ user_message = messages[0]["content"]
61
 
62
+ # Format the prompt using the chat template
63
+ prompt = chat_template.replace("{{ user_message }}", user_message)
64
 
65
+ # Load the pipeline with the specified model
66
+ pipeline = pipeline(
67
  "text-generation",
68
  model=model,
69
  torch_dtype=torch.float16,
70
  device_map="auto",
71
  )
72
 
73
+ # Generate output with the model
74
  outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
75
+
76
+ # Print the generated response
77
  print(outputs[0]["generated_text"])
78
 
79
+
80
  ```