Uploaded model
- Developed by: alexneakameni
- License: apache-2.0
- Finetuned from model : unsloth/qwen2.5-0.5b-unsloth-bnb-4bit
This qwen2 model was trained 2x faster with Unsloth and Huggingface's TRL library.
Example Usage
Load model
import os
from unsloth import FastLanguageModel
max_seq_length = 8192 # Choose any! We auto support RoPE Scaling internally!
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "alexneakameni/qwen2.5-0.5b-json-chunker",
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
# token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
)
Prompt
EXPECTED_OUTPUT = """```
[
{"chunk": "Text of the first chunk...", "classification": "Brief classification of first chunk"},
{"chunk": "Text of the second chunk...", "classification": "Brief classification of second chunk"},
...
]
```""".strip()
PROMPT = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
You are an AI assistant tasked with analyzing and segmenting a given text into coherent chunks, each representing a main idea or topic. Your goal is to create a clear and structured segmentation of the text that helps readers navigate and understand the content, regardless of the subject.
Follow these steps to complete the task:
1. Read the entire text carefully to understand its content and structure.
2. Identify the main ideas or key topics discussed in the text.
3. Split the text into chunks, where each chunk corresponds to a single main idea. Aim for chunks that are typically one to two paragraphs long, ensuring they are neither too brief nor overly lengthy.
4. For each chunk you create:
a. Provide a short classification (in a few words) summarizing what the chunk is about.
b. Ensure the classification reflects the chunk's main idea accurately.
c. Keep the classification concise and informative, allowing readers to quickly grasp the chunk's topic.
5. Ensure that all parts of the text are included without overlapping ideas between chunks.
6. Make sure each chunk is self-contained and makes sense independently.
7. Return your result as a `list` of `dictionaries` (as in python language), each with two keys:
- "chunk": The text segment corresponding to the main idea.
- "classification": A brief summary of the topic covered by the chunk.
The output should follow this structure:
<output>
{EXPECTED_OUTPUT}
</output>
Additional guidelines:
- Preserve the original language of the text within the chunks; do not alter the wording.
- Ensure classifications are appropriate to the text's subject matter.
- If the text includes terms or concepts unique to its subject, include them in the classifications when relevant.
Remember, your objective is to create a clear and structured segmentation of the text that helps readers navigate and understand the content, regardless of the subject. Provide your answer in the specified JSON format inside <answer> tags.
### Input:
{TEXT}
### Response:
"""
Input Text
text = """19th Century: Military and Social Transformations in Africa
The most effective armies of the 19th century relied on local resources at every level—training, equipment, and leadership. These forces stood in contrast to those modeled after European armies, which adopted European-style uniforms, barracks life, training methods, and military ranks. In Madagascar, reforms went as far as introducing the purchase of military ranks, mirroring practices found in early 19th-century European armies.
The influence of European armies was significant, leading to the widespread adoption of European muskets. Many new African armies adopted these firearms, some for their firepower (such as Enfield rifles) and others for the psychological impact of their loud volleys, which could spread panic among enemy cavalry. Many African rulers also sought to acquire artillery, but due to the weight of cannons and the large quantities of gunpowder required, attempts to manufacture them locally were largely unsuccessful. By the 1870s, more advanced weaponry—including breech-loading rifles, repeating carbines, machine guns, and artillery—began to be imported. The Maxim gun, in particular, became the pinnacle of military technology, though European powers maintained a monopoly over it. Some African leaders, such as the Igbo chiefs, used European cannons more for their psychological impact than for actual warfare.
Even before the 19th century, African rulers sought to import European firearms. However, it was only in the second half of the century, when more effective firearms became available, that European weaponry clearly became a decisive factor in African warfare. As European arms became a critical advantage, securing access to them during wartime became essential, making arms procurement a central aspect of trade, diplomacy, and governance.
Ethiopian Military Strategies and African Arms Trade
The shift in military power brought significant changes, illustrated by the contrasting strategies of Ethiopian emperors Tewodros II and Yohannes IV. Tewodros attempted to manufacture cannons and gunpowder domestically using European technicians and proved that he could defeat better-equipped armies even without such weapons. However, Yohannes IV—and later, Menelik II—recognized that only by acquiring superior European firearms could they overcome their enemies in Tigray and the coastal plains. Likewise, North African, Saharan, and Sudanese rulers sought to stockpile European arms through trade and diplomacy, mainly via North Africa and coastal trade routes in West and East Africa. Madagascar's rulers followed a similar strategy.
In central and eastern Africa, the ivory trade was a major economic driver, further increasing the demand for firearms and contributing to the growing militarization of society. One major consequence of this increasing reliance on European weaponry was the decline of cavalry as an elite military force, with European-style infantry replacing it. In forested regions and areas influenced by Nguni military traditions, infantry had long been the dominant force. In the 19th century, these infantry units underwent more intensive training, gradually becoming professional armies equipped with European weapons.
Large-scale population movements, such as those following the Mfecane or the collapse of the Oyo Empire, further accelerated the decline of cavalry. As formerly cavalry-based societies moved into forested regions where horse warfare was impractical, cavalry forces diminished. However, in some African states directly confronting European colonial expansion, cavalry remained essential. These states began breeding small horses for mobile warfare and imported European firearms, maintaining temporary military superiority."""
Run chunk splitter
input_text = PROMPT.format(EXPECTED_OUTPUT=EXPECTED_OUTPUT, TEXT=text)
from transformers import TextStreamer
FastLanguageModel.for_inference(model)
text_streamer = TextStreamer(tokenizer)
inputs = tokenizer(
[
input_text
], return_tensors = "pt").to("cuda")
_ = model.generate(**inputs, max_new_tokens = 25000, streamer = text_streamer, use_cache = True)
Expected Output
[
{
"chunk": "19th Century: Military and Social Transformations in Africa\nThe most effective armies of the 19th century relied on local resources at every level—training, equipment, and leadership. These forces stood in contrast to those modeled after European armies, which adopted European-style uniforms, barracks life, training methods, and military ranks. In Madagascar, reforms went as far as introducing the purchase of military ranks, mirroring practices found in early 19th-century European armies.",
"classification": "Introduction to 19th century military transformations"
},
{
"chunk": "The influence of European armies was significant, leading to the widespread adoption of European muskets. Many new African armies adopted these firearms, some for their firepower (such as Enfield rifles) and others for the psychological impact of their loud volleys, which could spread panic among enemy cavalry. Many African rulers also sought to acquire artillery, but due to the weight of cannons and the large quantities of gunpowder required, attempts to manufacture them locally were largely unsuccessful. By the 1870s, more advanced weaponry—including breech-loading rifles, repeating carbines, machine guns, and artillery—began to be imported. The Maxim gun, in particular, became the pinnacle of military technology, though European powers maintained a monopoly over it. Some African leaders, such as the Igbo chiefs, used European cannons more for their psychological impact than for actual warfare.",
"classification": "Influence of European military technology on African armies"
},
{
"chunk": "Even before the 19th century, African rulers sought to import European firearms. However, it was only in the second half of the century, when more effective firearms became available, that European weaponry clearly became a decisive factor in African warfare. As European arms became a critical advantage, securing access to them during wartime became essential, making arms procurement a central aspect of trade, diplomacy, and governance. Ethiopian Military Strategies and African Arms Trade",
"classification": "Importance of European military technology in African warfare"
},
{
"chunk": "The shift in military power brought significant changes, illustrated by the contrasting strategies of Ethiopian emperors Tewodros II and Yohannes IV. Tewodros attempted to manufacture cannons and gunpowder domestically using European technicians and proved that he could defeat better-equipped armies even without such weapons. However, Yohannes IV—and later, Menelik II—recognized that only by acquiring superior European firearms could they overcome their enemies in Tigray and the coastal plains. Likewise, North African, Saharan, and Sudanese rulers sought to stockpile European arms through trade and diplomacy, mainly via North Africa and coastal trade routes in West and East Africa. Madagascar's rulers followed a similar strategy.",
"classification": "Comparative strategies of Ethiopian and Yohannes IV emperors"
},
{
"chunk": "In central and eastern Africa, the ivory trade was a major economic driver, further increasing the demand for firearms and contributing to the growing militarization of society. One major consequence of this increasing reliance on European weaponry was the decline of cavalry as an elite military force, with European-style infantry replacing it. In forested regions and areas influenced by Nguni military traditions, infantry had long been the dominant force. In the 19th century, these infantry units underwent more intensive training, gradually becoming professional armies equipped with European weapons.",
"classification": "Impact of the ivory trade on central and eastern African warfare"
},
{
"chunk": "Large-scale population movements, such as those following the Mfecane or the collapse of the Oyo Empire, further accelerated the decline of cavalry. As formerly cavalry-based societies moved into forested regions where horse warfare was impractical, cavalry forces diminished. However, in some African states directly confronting European colonial expansion, cavalry remained essential. These states began breeding small horses for mobile warfare and imported European firearms, maintaining temporary military superiority.",
"classification": "Impact of population movements on cavalry and military development"
}
]
Inference Providers
NEW
This model is not currently available via any of the supported Inference Providers.
The model cannot be deployed to the HF Inference API:
The model has no pipeline_tag.