Logo Lanfrica

kondwani0099/Bemba-LLM-Model

Domain:

natural language processing

Record type:

model
Creator:
kon
Host:
```markdown # Bemba Language Model (LLM) This project provides a Bemba language model that can generate text based on user input. The model is fine-tuned using the Hugging Face Transformers library and is capable of producing coherent sentences in Bemba. ## Requirements To run this project, you need the following dependencies: - Python 3.6 or higher - PyTorch - Transformers You can install the required packages using pip: ```bash pip install torch transformers ``` ## Setup 1. Clone this repository to your local machine: ```bash git clone cd ``` 2. Make sure you have your fine-tuned model stored in a directory named `lora_model`. This directory should contain the model and tokenizer files. ## Usage To generate text using the Bemba language model, you can use the following Python script: ```python import torch from transformers import AutoTokenizer, AutoModelForCausalLM # Path to your fine-tuned model directory model_name = "./lora_model" # Load the tokenizer and model tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name) # Set the pad token tokenizer.pad_token_id = tokenizer.eos_token_id # Set the model to evaluation mode model.eval() # Prepare your input text input_text = "ukutendeka lesa ali pangile isonde" # Example input in Bemba input_ids = tokenizer.encode(input_text, return_tensors='pt') # Create attention mask attention_mask = torch.ones(input_ids.shape, dtype=torch.long) # Generate text with sampling and temperature control with torch.no_grad(): output = model.generate( input_ids, attention_mask=attention_mask, max_length=50, num_return_sequences=1, do_sample=True, # Enable sampling top_k=50, # Use top-k sampling top_p=0.95, # Nucleus sampling temperature=0.7, # Control diversity pad_token_id=tokenizer.eos_token_id ) # Decode the output generated_text = tokenizer.decode(output[0], skip_special_tokens=True) print("Generated T …