Views
No views yet

1from unsloth import FastLanguageModel
2
3
4max_seq_length = 2048
5dtype = None
6load_in_4bit = False
7
8
9alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
10
11### Instruction:
12{}
13
14### Input:
15{}
16
17### Response:
18{}"""
19
20
21model, tokenizer = FastLanguageModel.from_pretrained(
22 model_name = "sujet-ai/Sujet-Finance-8B-v0.1",
23 max_seq_length = max_seq_length,
24 dtype = dtype,
25 load_in_4bit = load_in_4bit,
26 token = "your hf token here",
27)
28
29
30example = {
31'system_prompt': 'You are a financial sentiment analysis expert. Your task is to analyze the sentiment expressed in the given financial text.Only reply with bearish, neutral, or bullish.',
32'user_prompt': "Expedia's Problems Run Deeper Than SEO Headwinds",
33'answer': 'bearish',
34}
35
36
37inputs = tokenizer(
38 [alpaca_prompt.format(
39 example['system_prompt'], # instruction
40 example['user_prompt'], # input
41 "", # output - leave this blank for generation!
42 )],
43 return_tensors="pt"
44 ).to("cuda")
45
46outputs = model.generate(**inputs, max_new_tokens=2048, use_cache=True, pad_token_id=tokenizer.eos_token_id)
47output = tokenizer.batch_decode(outputs)[0]
48response = output.split("### Response:")[1].strip()
49print(response)