Views
No views yet
1prompt_template = """<|begin_of_text|><|start_header_id|>system<|end_header_id|>
2response_format:json_object
3<|eot_id|><|start_header_id|>user<|end_header_id|>
4TASK: create title, summary and tags (e.g. company, organization, person, catastrophic event, product, process, security vulnerability, stock ticker symbol, geographic location). title should be 10 - 20 words, summary should be 100 - 200 words and tags (entities) should a string of comma separated phrases.
5INPUT:
6{text}
7<|eot_id|><|start_header_id|>assistant<|end_header_id|>"""1{
2 "title": "some 10 - 20 words title",
3 "summary": "some 100 - 180 word summary",
4 "tags": "comma separated list of named entities"
5}1{
2 "title": "The Future of Space Missions: How 3D Printing is Revolutionizing Astronaut Logistics",
3 "summary": "The 3D printing market is poised for significant growth, with an estimated value of US$95 billion by 2032, according to BCG. While it may never replace traditional manufacturing on Earth, its potential in space is transformative. Astronauts aboard the International Space Station (ISS) manage complex logistics, relying on substantial deliveries of spare parts—over 7,000 pounds annually—with additional supplies stored on Earth and the ISS itself. However, this model is unsustainable for future manned missions to Mars and the Moon, where astronauts will face isolation and the need for adaptability. 3D printing offers a viable solution, enabling the in-situ production of parts and tools as needed, thus facilitating a new era of space exploration where self-sufficiency becomes essential for survival and success.",
4 "tags": "3D printing, space exploration, International Space Station, manufacturing, Mars, Moon, logistics, astronauts, spare parts, BCG"
5}| Model | Quality and adherence rate |
|---|---|
| Merged model or Lora adapter | High quality content generation but lower adherence rate compared to the lower precision quantized models. 7-8 out of 2500 inputs will produce non-JSON output |
| Q8_0 | Same quality as the merged model. Better adherence rate to response format (1 out of 3000 inputs are non-JSON) |
| Q5_K_M | High quality, recommended. Similar to Q4 model. No visible difference. |
| Q4_K_M | High quality, recommended. Better adherence rate to response format (1 out of ~4000 inputs are non-JSON) but smaller summary (~100 words as opposed to 128 words) |
| Q2_K | Straight up trash. Don't use it. |
1# this was the prompt template the model was trained with
2prompt_template = """<|begin_of_text|><|start_header_id|>system<|end_header_id|>
3response_format:json_object
4<|eot_id|><|start_header_id|>user<|end_header_id|>
5TASK: create title, summary and tags (e.g. company, organization, person, catastrophic event, product, process, security vulnerability, stock ticker symbol, geographic location). title should be 10 - 20 words, summary should be 100 - 200 words and tags (entities) should a string of comma separated phrases.
6INPUT:
7{text}
8<|eot_id|><|start_header_id|>assistant<|end_header_id|>"""
9
10input_text = "whatever article, blog, post or novela you want to digest" 1from unsloth import FastLanguageModel
2
3model, tokenizer = FastLanguageModel.from_pretrained(
4 model_name = "soumitsr/llama-v3p2-article-digestor-lora",
5 max_seq_length = 16384
6)
7FastLanguageModel.for_inference(model) # Enable native 2x faster inference
8
9inputs = tokenizer(prompt_template.format(text=input_text), return_tensors="pt")
10# feel free to play with the max_new_tokens and temperature
11outputs = model.generate(
12 **inputs,
13 max_new_tokens=512,
14 temperature=0.1,
15 stream=False
16)
17resp = tokenizer.decode(outputs[0], skip_special_tokens=True))
18
19response_json = json.loads(resp[resp.find('{'):resp.rfind('}')+1])1from llama_cpp import Llama
2
3model = Llama(model_path=model_file_apth, n_ctx=16384, n_threads=os.cpu_count(), embedding=False, verbose=False)
4
5resp = model.create_completion(
6 prompt=prompt_template.format(text=text),
7 max_tokens=384,
8 frequency_penalty=0.3, # feel free to play with these numbers
9 temperature=0.2
10)['choices'][0]['text']
11
12response_json = json.loads(resp[resp.find('{'):resp.rfind('}')+1])