Views
No views yet
git clone https://huggingface.co/justsomerandomdude264/SocialScience_Homework_Solver-Llama3.18B1from unsloth import FastLanguageModel
2import torch
3
4# Define Your Question
5question = "Analyze the socio-political and economic factors that contributed to the rise and fall of the Byzantine Empire from the reign of Justinian I to the fall of Constantinople in 1453. How did internal conflicts, religious controversies, and external pressures from both Islamic caliphates and Western European powers shape the trajectory of the empire over this period?" # Example Question, You can change it with one of your own
6
7# Load the model
8model, tokenizer = FastLanguageModel.from_pretrained(
9 model_name = "SocialScience_Homework_Solver_Llama318B/model_adapters", # The dir where the repo is cloned or "\\" for root
10 max_seq_length = 2048,
11 dtype = None,
12 load_in_4bit = True,
13 )
14
15# Set the model in inference model
16FastLanguageModel.for_inference(model)
17
18# QA template
19qa_template = """Question: {}
20Answer: {}"""
21
22# Tokenize inputs
23inputs = tokenizer(
24[
25 qa_template.format(
26 question, # Question
27 "", # Answer - left blank for generation
28 )
29], return_tensors = "pt").to("cuda")
30
31# Stream the answer/output of the model
32from transformers import TextStreamer
33text_streamer = TextStreamer(tokenizer)
34_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 512)1from transformers import LlamaForCausalLM, AutoTokenizer
2
3# Load the model
4model = LlamaForCausalLM.from_pretrained(
5 "justsomerandomdude264/SocialScience_Homework_Solver_Llama318B",
6 device_map="auto"
7)
8
9# Load the tokenizer
10tokenizer = AutoTokenizer.from_pretrained("justsomerandomdude264/SocialScience_Homework_Solver_Llama318B")
11
12# Set the inputs up
13qa_template = """Question: {}
14Answer: {}"""
15
16inputs = tokenizer(
17[
18 qa_template.format(
19 "Who was Akbar?", # Question
20 "", # output - leave this blank for generation!
21 )
22], return_tensors = "pt").to("cuda")
23
24# Do a forward pass
25outputs = model.generate(**inputs, max_new_tokens = 128, use_cache = True)
26raw_output = str(tokenizer.batch_decode(outputs))
27
28# Formtting the string
29# Removing the list brackets and splitting the string by newline characters
30formatted_string = raw_output.strip("[]").replace("<|begin_of_text|>", "").replace("<|eot_id|>", "").strip("''").split("\\n")
31
32# Print the lines one by one
33for line in formatted_string:
34 print(line)1@misc{paliwal2024,
2 author = {Krishna Paliwal},
3 title = {Contributions to SocialScience_Homework_Solver},
4 year = {2024},
5 email = {krishna.plwl264@gmail.com}
6}Paliwal, Krishna (2024). Contributions to SocialScience_Homework_Solver. Email: krishna.plwl264@gmail.com .