Update README.md
Browse files
README.md
CHANGED
@@ -32,22 +32,33 @@ AstroLLaMA-2-7B-Base_AIC is a specialized base language model for astronomy, dev
|
|
32 |
|
33 |
```python
|
34 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
35 |
|
|
|
36 |
tokenizer = AutoTokenizer.from_pretrained("AstroMLab/astrollama-2-7b-base_aic")
|
37 |
model = AutoModelForCausalLM.from_pretrained("AstroMLab/astrollama-2-7b-base_aic", device_map="auto")
|
38 |
|
39 |
-
|
40 |
from transformers import pipeline
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# Example prompt from an astronomy paper
|
45 |
prompt = "In this letter, we report the discovery of the highest redshift, " \
|
46 |
"heavily obscured, radio-loud QSO candidate selected using JWST NIRCam/MIRI, " \
|
47 |
"mid-IR, sub-mm, and radio imaging in the COSMOS-Web field. "
|
48 |
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
51 |
print(generated_text[0]['generated_text'])
|
52 |
```
|
53 |
|
|
|
32 |
|
33 |
```python
|
34 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
35 |
+
import torch
|
36 |
|
37 |
+
# Load the model and tokenizer
|
38 |
tokenizer = AutoTokenizer.from_pretrained("AstroMLab/astrollama-2-7b-base_aic")
|
39 |
model = AutoModelForCausalLM.from_pretrained("AstroMLab/astrollama-2-7b-base_aic", device_map="auto")
|
40 |
|
41 |
+
# Create the pipeline with explicit truncation
|
42 |
from transformers import pipeline
|
43 |
+
generator = pipeline(
|
44 |
+
"text-generation",
|
45 |
+
model=model,
|
46 |
+
tokenizer=tokenizer,
|
47 |
+
device_map="auto",
|
48 |
+
truncation=True,
|
49 |
+
max_length=512
|
50 |
+
)
|
51 |
|
52 |
# Example prompt from an astronomy paper
|
53 |
prompt = "In this letter, we report the discovery of the highest redshift, " \
|
54 |
"heavily obscured, radio-loud QSO candidate selected using JWST NIRCam/MIRI, " \
|
55 |
"mid-IR, sub-mm, and radio imaging in the COSMOS-Web field. "
|
56 |
|
57 |
+
# Set seed for reproducibility
|
58 |
+
torch.manual_seed(42)
|
59 |
+
|
60 |
+
# Generate text
|
61 |
+
generated_text = generator(prompt, do_sample=True)
|
62 |
print(generated_text[0]['generated_text'])
|
63 |
```
|
64 |
|