Views
No views yet
1from vllm import LLM, SamplingParams
2from unsloth.chat_templates import get_chat_template
3from transformers import AutoTokenizer
4
5# load model
6model_name = "extreme-weather-impacts/Qwen2.5-7B-Instruct-impactdirectionality"
7llm = LLM(model=model_name)
8
9# load tokenizer with the correct chat template
10tokenizer = AutoTokenizer.from_pretrained(model_name) # "Qwen/Qwen2.5-7B"
11tokenizer = get_chat_template(tokenizer, chat_template="qwen-2.5")
12
13# prompt template
14prompt_template_impact_directionality = """You are given a TEXT of a company disclosure that discusses extreme weather exposure of the company. Your task is to determine whether the company was positively, neutrally, or negatively impacted by the extreme weather exposure or obtained a reimbursement.
15
16Here is the TEXT from the company’s disclosure:
17[begin of TEXT]
18{text}
19[end of TEXT]
20
21Answer the following question:
22- Based on the TEXT, was the impact on the company positive, neutral, or negative, or did the company obtain a reimbursement?
23
24Decision Guidelines:
25- Positive impact: The company obtained an advantage as a result of the extreme weather exposure, e.g., economic benefits like higher sales.
26- Negative impact: The company experienced an extreme weather impact or unfavorable outcomes from extreme weather exposure, e.g., economic losses. If the company reports a positive economic development that offsets the extreme weather impact, it is still a negative impact.
27- Neutral impact: The company discusses extreme weather exposure, but there is no indication of an impact on the company.
28- Reimbursement: The company discusses materialized reimbursements for a negative extreme weather impact experienced in the past, e.g., payment of hurricane costs by an insurance company.
29
30Output Format:
31Answer with a single word: "Positive", "Negative", "Neutral", or “Reimbursement”.
32
33Your Output:
34"""
35
36# some example texts
37text_1 = "Hurricane Katrina has caused severe supply chain disruptions for our business. As a consquence, we could not serve our own customers on time."
38text_2 = "During Winter Storm Uri, our sales in oil and gas products increased drastically."
39text_3 = "Our insurance covered lat year's losses suffered on our facilities due to severe floods in Alabama."
40texts = [text_1, text_2, text_3]
41prompt_1 = prompt_template_impact_directionality.format(text=text_1)
42prompt_2 = prompt_template_impact_directionality.format(text=text_2)
43prompt_3 = prompt_template_impact_directionality.format(text=text_3)
44
45# demo prompts
46raw_prompts = [
47 [{'role': 'user', 'content': prompt_1}],
48 [{'role': 'user', 'content': prompt_2}],
49 [{'role': 'user', 'content': prompt_3}]
50]
51
52# apply the correct chat template formatting
53formatted_prompts = [
54 tokenizer.apply_chat_template(convo, tokenize=False, add_generation_prompt=True)
55 for convo in raw_prompts
56]
57
58# set sampling parameters
59sampling_params = SamplingParams(temperature = 0.01, min_p = 0.1)
60
61# run inference
62outputs = llm.generate(formatted_prompts, sampling_params)
63
64# print outputs
65answers = []
66for i, output in enumerate(outputs):
67 generated_text = output.outputs[0].text
68 answers.append(generated_text)
69 print(f"Text under investigation: {texts[i]!r}\nGenerated Answer (Impact?): {generated_text!r}\n")1@article{Schimanski25extremeweatherimpacts,
2 title={{What Firms Actually Lose (and Gain) from Extreme Weather Event Impacts}},
3 author={Tobias Schimanski and Glen Gostlow and Malte Toetzke and Markus Leippold},
4 year={2025},
5 journal={Soon available on SSRN},
6}