Install required libraries: torch and transformers
Use the following code:
# Load model directlyfrom transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Sourabh2/Chemistry_elements", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("Sourabh2/Chemistry_elements", trust_remote_code=True)
# Set up the device (GPU if available, otherwise CPU)
device = torch.device("cuda"if torch.cuda.is_available() else"cpu")
model = model.to(device)
# Example usage
messages = [
{
"role": "user",
"content": "hydrogen"
}
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors='pt', padding=True, truncation=True)
outputs = model.generate(**inputs, max_length=150, num_return_sequences=1)
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(text.split("assistant")[1])
# Decode and print output
['Symbol: H', 'Atomic_Number: 1', 'Atomic_Weight: 1.008', 'Density: 0.0899', 'Melting_Point: 14.01', 'Boiling_Point: 20.28', 'Phase: Gas', 'Absolute_Melting_Point: 14.01']
Runs of Sourabh2 Chemistry_elements on huggingface.co
4
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About Chemistry_elements huggingface.co Model
Chemistry_elements huggingface.co
Chemistry_elements huggingface.co is an AI model on huggingface.co that provides Chemistry_elements's model effect (), which can be used instantly with this Sourabh2 Chemistry_elements model. huggingface.co supports a free trial of the Chemistry_elements model, and also provides paid use of the Chemistry_elements. Support call Chemistry_elements model through api, including Node.js, Python, http.
Chemistry_elements huggingface.co is an online trial and call api platform, which integrates Chemistry_elements's modeling effects, including api services, and provides a free online trial of Chemistry_elements, you can try Chemistry_elements online for free by clicking the link below.
Sourabh2 Chemistry_elements online free url in huggingface.co:
Chemistry_elements is an open source model from GitHub that offers a free installation service, and any user can find Chemistry_elements on GitHub to install. At the same time, huggingface.co provides the effect of Chemistry_elements install, users can directly use Chemistry_elements installed effect in huggingface.co for debugging and trial. It also supports api for free installation.