This repo contains GGUF format model files for
swahili LLaMA 7B v0.1.
1import os.path
2from llama_index.core import (
3 VectorStoreIndex,
4 SimpleDirectoryReader,
5 StorageContext,
6 load_index_from_storage,
7)
8from llama_index.llms.llama_cpp import LlamaCPP
9from llama_index.llms.llama_cpp.llama_utils import messages_to_prompt, completion_to_prompt
10from llama_index.embeddings.huggingface import HuggingFaceEmbedding
11from llama_index.core import Settings
12
13import torch
14import time
15import os.path
16import gradio as gr
17
18model_path = "swahili_llama-7b-v0.1.gguf"
19
20llm = LlamaCPP(
21 # You can pass in the URL to a GGML model to download it automatically
22 model_url=None,
23 # optionally, you can set the path to a pre-downloaded model instead of model_url
24 model_path=model_path,
25 temperature=0.7,
26 max_new_tokens=300,
27 # llama2 has a context window of 4096 tokens, but we set it lower to allow for some wiggle room
28 context_window=2000,
29 # kwargs to pass to __call__()
30 generate_kwargs={},
31 # kwargs to pass to __init__()
32 # set to at least 1 to use GPU
33 model_kwargs={"n_gpu_layers": 0},
34 # transform inputs into Llama2 format
35 messages_to_prompt=messages_to_prompt,
36 completion_to_prompt=completion_to_prompt,
37 verbose=True,
38)
39
40Settings.llm=llm
41
42response= llm.complete("Mfumo wa elimu Tanzania ni ")
43print(response.text)
1import os.path
2from llama_index.core import (
3 VectorStoreIndex,
4 SimpleDirectoryReader,
5 StorageContext,
6 load_index_from_storage,
7)
8from llama_index.llms.llama_cpp import LlamaCPP
9from llama_index.llms.llama_cpp.llama_utils import messages_to_prompt, completion_to_prompt
10from llama_index.embeddings.huggingface import HuggingFaceEmbedding
11from llama_index.core import Settings
12import gradio as gr
13
14llm = LlamaCPP(
15 # You can pass in the URL to a GGML model to download it automatically
16 # model_url=None,
17 # optionally, you can set the path to a pre-downloaded model instead of model_url
18 model_path = "swahili_llama-7b-v0.1.gguf",
19 temperature=0.1,
20 max_new_tokens=200,
21 # llama2 has a context window of 4096 tokens, but we set it lower to allow for some wiggle room
22 context_window=2000,
23 # kwargs to pass to __call__()
24 generate_kwargs={},
25 # kwargs to pass to __init__()
26 # set to at least 1 to use GPU
27 model_kwargs={"n_gpu_layers": -1},
28 # transform inputs into Llama2 format
29 messages_to_prompt=messages_to_prompt,
30 completion_to_prompt=completion_to_prompt,
31 verbose=True,
32)
33
34Settings.embed_model = HuggingFaceEmbedding(
35 model_name="./embeddings/bge-small-en-v1.5/"
36)
37Settings.llm = llm
38
39PERSIST_DIR = "./storage"
40if not os.path.exists(PERSIST_DIR):
41 # load the documents and create the index
42 documents = SimpleDirectoryReader("data").load_data()
43 index = VectorStoreIndex.from_documents(documents)
44 # store it for later
45 index.storage_context.persist(persist_dir=PERSIST_DIR)
46else:
47 # load the existing index
48 storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
49 index = load_index_from_storage(storage_context)
50
51query_engine = index.as_query_engine(streaming=True)
52
53def main(question):
54 response = query_engine.query(question)
55 return response
56
57# Gradio interface
58ui = gr.Interface(
59 fn=main,
60 inputs="textbox",
61 outputs="textbox"
62)
63ui.launch(share=True)
-
Generate Inaccurate Facts as the base model
-
Limited Scope for code: It performs poorly on code
-
Unreliable Responses to Instruction: The model has not undergone instruction fine-tuning. As a result, it may struggle or fail to adhere to intricate or nuanced instructions provided by users.
-
Language Limitations: The model is primarily designed to understand standard Swahili. The checkpoint of this model also leads to more inaccurate responses. Any Informal Swahili, slang, or any other language might challenge its comprehension, leading to potential misinterpretations or errors in response.
-
Potential Societal Biases: it fed with limited text it might be bias
-
Toxicity: It might be toxic; however, most of the dataset trained in Swahili comes from newspapers, which makes it less toxic.
-
Verbosity: Swahili LLaMa, being a base model, often produces irrelevant or extra text and responses following its first answer to user prompts within a single turn. This is due to its training dataset being primarily news and blogspot, which results in random response.
-
Architecture: LLaMA-2a (Transformer-based model with next-word prediction objective)
-
Context length: LLaMA-2 (2048 tokens)
-
Dataset size: 600M tokens(LLaMA-2) from C100 swahili and other craw from swahili newspaper and blogspots.
-
Training tokens: 1.4T tokens
-
GPUs: 2xA6000-48G
-
Training time: Expected 13 days