Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4# Load the model and tokenizer
5model = AutoModelForCausalLM.from_pretrained("AstroMLab/AstroSage-8b", device_map="auto")
6tokenizer = AutoTokenizer.from_pretrained("AstroMLab/AstroSage-8b")
7
8# Function to generate a response
9def generate_response(prompt):
10 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
11
12 outputs = model.generate(
13 **inputs,
14 max_new_tokens=128,
15 do_sample=True,
16 pad_token_id=tokenizer.eos_token_id,
17 )
18 response = outputs[0][inputs['input_ids'].shape[-1]:]
19 decoded = tokenizer.decode(response, skip_special_tokens=True)
20
21 return decoded
22
23# Example usage
24prompt = """
25You are an expert in general astrophysics. Your task is to answer the following question:
26What are the main components of a galaxy?
27"""
28response = generate_response(prompt)
29print(response)| Model | Score (%) |
|---|---|
| AstroSage-Llama-3.1-8B | 80.9 |
| GPT-4o | 80.4 |
| LLaMA-3.1-8B | 73.7 |
| Gemma-2-9B | 71.5 |
| Qwen-2.5-7B | 70.4 |
| Yi-1.5-9B | 68.4 |
| InternLM-2.5-7B | 64.5 |
| Mistral-7B-v0.3 | 63.9 |
| ChatGLM3-6B | 50.4 |
@preprint{dehaan2024astromlab3,
title={AstroMLab 3: Achieving GPT-4o Level Performance in Astronomy with a Specialized 8B-Parameter Large Language Model},
author={Tijmen de Haan and Yuan-Sen Ting and Tirthankar Ghosal and Tuan Dung Nguyen and Alberto Accomazzi and Azton Wells and Nesar Ramachandra and Rui Pan and Zechang Sun},
year={2024},
eprint={2411.09012},
archivePrefix={arXiv},
primaryClass={astro-ph.IM},
url={https://arxiv.org/abs/2411.09012},
}