Seongyun commited on
Commit
c474e00
1 Parent(s): bf6adab

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -0
README.md CHANGED
@@ -42,6 +42,42 @@ Janus is a model generalized for various system messages, allowing users to cont
42
  ```
43
  Additionally, an example of the inference code applying this is as follows:
44
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  ```
46
  # Training Details
47
  ## Training hyperparameters
 
42
  ```
43
  Additionally, an example of the inference code applying this is as follows:
44
  ```
45
+ from transformers import AutoTokenizer, AutoModelForCausalLM
46
+ import torch
47
+
48
+ model_name = "kaist-ai/janus-7b"
49
+ device = "cuda:0"
50
+
51
+ # Load the model and tokenizer
52
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
53
+
54
+ dtype = "float16"
55
+ if torch.cuda.is_bf16_supported():
56
+ dtype = "bfloat16"
57
+
58
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=getattr(torch, dtype))
59
+ model.eval()
60
+ model.to(device)
61
+
62
+ # Prepare inputs
63
+ system = "As a financial news headline writer with a flair for the dramatic, you have taken on the role of crafting compelling headlines about the integration of AI into the financial sector. Your expertise allows you to weave industry-specific terminology seamlessly into each headline, striking a balance between capturing attention and providing meaningful insights into the transformative benefits of AI in finance. With each headline, you focus on elucidating the key advantages AI brings to financial operations, making complex information accessible and immediately impactful. While your headlines are designed to engage and inform an audience of finance and technology professionals, you navigate the fine line of excitement and accuracy with care, ensuring that the promises made are grounded in reality, thus avoiding any form of sensationalism. Your mission is to distill the essence of AI's impact on finance into a single, powerful line that speaks volumes to the informed reader."
64
+ prompt = "Write a headline for an article about the benefits of using AI in the finance sector."
65
+
66
+ def apply_template_mistral_instruct(system_message, content):
67
+ prompt = f"{system_message}\n{content}".strip()
68
+ return f"[INST] {prompt} [/INST] "
69
+
70
+ input_str = apply_template_mistral_instruct(system, prompt)
71
+ input_ids = tokenizer.encode(input_str, return_tensors="pt")
72
+ print(input_str)
73
+
74
+ model_inputs = input_ids.to(device)
75
+
76
+ # Generate text
77
+ output_ids = model.generate(model_inputs, max_new_tokens=1024)
78
+ decoded = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
79
+ print(decoded[0][len(input_str):])
80
+ # Revolutionary Trends: How AI Is Redefining Efficiency and Accuracy in the Financial Realm
81
  ```
82
  # Training Details
83
  ## Training hyperparameters