Views
No views yet
1finetune_name = 'Askinkaty/llama-finance-relations'
2
3
4finetined_model = AutoPeftModelForCausalLM.from_pretrained(
5 pretrained_model_name_or_path=finetune_name,
6 torch_dtype=torch.float16,
7 low_cpu_mem_usage=True,
8 device_map="auto",
9)
10
11base_model_name = "meta-llama/Llama-3.2-1B-Instruct"
12base_model = AutoModelForCausalLM.from_pretrained(base_model_name,
13 torch_dtype=torch.float16,
14 low_cpu_mem_usage=True)
15
16tokenizer = AutoTokenizer.from_pretrained(model_name)
17
18base_model.config.pad_token_id = base_model.config.eos_token_id
19model.config.pad_token_id = model.config.eos_token_id
20
21pipeline = pipeline('text-generation', model=base_model, tokenizer=tokenizer, max_length=1024, device=device)
22pipeline.model = model.to(device) 1def batch_convert_to_messages(data):
2
3 questions = data.apply(
4 lambda x: f"Entity 1: {' '.join(x['token'][x['e1_start']:x['e1_end']])}. "
5 f"Entity 2: {' '.join(x['token'][x['e2_start']:x['e2_end']])}. "
6 f"Input sentence: {' '.join(x['token'])}",
7 axis=1
8 )
9
10 relations = data['relation'].apply(lambda relation: relation.split(':')[-1])
11
12 messages = [
13 [
14 {
15 "role": "system",
16 "content": "You are an expert in financial documentation and market analysis. Define relations between two specified entities: entity 1 [E1] and entity 2 [E2] in a sentence. Return a short response of the required format. "
17 },
18 {"role": "user", "content": question},
19 {"role": "assistant", "content": relation},
20 ]
21 for question, relation in zip(questions, relations)
22 ]
23
24 return messagesOverall Performance:
Precision: 0.77
Recall: 0.69
F1 Score: 0.71
Classification Report:
precision recall f1-score support
no_relation 0.00 0.00 0.00 0
title 0.00 0.00 0.00 0
operations_in 0.65 0.66 0.66 100
employee_of 0.00 0.00 0.00 0
agreement_with 0.58 0.88 0.70 100
formed_on 0.00 0.00 0.00 0
member_of 0.99 0.96 0.97 96
subsidiary_of 0.00 0.00 0.00 0
shares_of 0.00 0.00 0.00 0
revenue_of 0.60 0.27 0.38 95
loss_of 0.64 0.37 0.47 100
headquartered_in 0.99 0.73 0.84 100
acquired_on 0.00 0.00 0.00 0
founder_of 0.74 0.77 0.76 83
formed_in 0.96 0.91 0.93 100
accuracy 0.69 774
macro avg 0.41 0.37 0.38 774
weighted avg 0.77 0.69 0.71 774