Views
No views yet
1git lfs install
2git clone https://huggingface.co/SustcZhangYX/EnvGPT-14B1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
3
4# 1. Set your local EnvGPT model path here
5model_path = "YOUR_LOCAL_MODEL_PATH"
6
7# 2. Load tokenizer and model
8tokenizer = AutoTokenizer.from_pretrained(model_path)
9model = AutoModelForCausalLM.from_pretrained(
10 model_path,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13)
14
15# 3. Build chat messages
16messages = [
17 {"role": "system", "content": "You are an expert assistant in environmental science, EnvGPT. You are a helpful assistant."},
18 {"role": "user", "content": "What is the definition of environmental science?"},
19]
20
21# 4. Format the prompt using the chat template
22# add_generation_prompt=True appends the assistant start token (e.g., <|assistant|>)
23text = tokenizer.apply_chat_template(
24 messages,
25 tokenize=False,
26 add_generation_prompt=True,
27)
28
29# 5. Initialize the text-generation pipeline
30text_gen = pipeline(
31 "text-generation",
32 model=model,
33 tokenizer=tokenizer,
34 device_map="auto",
35 torch_dtype=torch.bfloat16,
36 return_full_text=False, # Only return the newly generated text
37)
38
39# 6. Generate the response
40# do_sample=True enables sampling (stochastic decoding)
41# top_p=0.6 applies nucleus sampling
42# temperature=0.8 controls randomness
43# max_new_tokens=4096 allows up to 4096 new tokens
44outputs = text_gen(
45 text,
46 max_new_tokens=4096, # Up to 4096 new tokens
47 do_sample=True, # Enable sampling instead of greedy decoding
48 top_p=0.6, # Nucleus sampling parameter
49 temperature=0.8, # Sampling temperature
50)
51
52# 7. Print the assistant’s reply (without the original prompt)
53print(outputs[0]["generated_text"])
541@article{ZHANG2025100608,
2title = {Fine-Tuning Large Language Models for Interdisciplinary Environmental Challenges},
3journal = {Environmental Science and Ecotechnology},
4pages = {100608},
5year = {2025},
6issn = {2666-4984},
7doi = {https://doi.org/10.1016/j.ese.2025.100608},
8url = {https://www.sciencedirect.com/science/article/pii/S2666498425000869},
9author = {Yuanxin Zhang and Sijie Lin and Yaxin Xiong and Nan Li and Lijin Zhong and Longzhen Ding and Qing Hu}
10}