Text Generation
PEFT
Spanish
Edit model card

BERTIN-Alpaca-LoRA 7B

This is a Spanish adapter generated by fine-tuning LLaMA-7B on a Spanish Alpaca dataset.

Usage

from peft import PeftModel
from transformers import LLaMATokenizer, LLaMAForCausalLM, GenerationConfig

base_model = "decapoda-research/llama-7b-hf"
tokenizer = LLaMATokenizer.from_pretrained(base_model)
model = LLaMAForCausalLM.from_pretrained(
    base_model,
    load_in_8bit=True,
    device_map="auto",
)
model = PeftModel.from_pretrained(model, "bertin-project/bertin-alpaca-lora-7b")

Until PEFT is fully supported in Hugginface's pipelines, for generation we can either consolidate the LoRA weights into the LLaMA model weights, or use the adapter's generate() method. Remember that the prompt still needs the English template:

# Generate responses
def generate(instruction, input=None):
    if input:
        prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.  # noqa: E501

### Instruction:
{instruction}

### Input:
{input}

### Response:
"""
    else:
        prompt = f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.  # noqa: E501

### Instruction:
{instruction}

### Response:
"""
    inputs = tokenizer(prompt, return_tensors="pt")
    input_ids = inputs["input_ids"].cuda()
    generation_output = model.generate(
        input_ids=input_ids,
        generation_config=GenerationConfig(temperature=0.2, top_p=0.75, num_beams=4),
        return_dict_in_generate=True,
        output_scores=True,
        max_new_tokens=256
    )
    for seq in generation_output.sequences:
        output = tokenizer.decode(seq)
        print(output.split("### Response:")[1].strip())

generate("Escribe un correo electrónico dando la bienvenida a un nuevo empleado llamado Manolo.")
# Estimado Manolo,
#
# ¡Bienvenido a nuestro equipo! Estamos muy contentos de que hayas decidido unirse a nosotros y estamos ansiosos por comenzar a trabajar juntos. 
#
# Nos gustaría darte las gracias por tu interés en nuestro equipo y esperamos que tengas un gran tiempo aquí. 
#
# Si tienes alguna pregunta o duda, no dudes en contactarnos. 
#
# Atentamente, 
# Equipo de [Nombre del Departamento]

Data

The dataset is a translation to Spanish of alpaca_data_cleaned.json (a clean version of the Alpaca dataset made at Stanford) using OpenAI's gpt-3.5-turbo model. We translated using a full-sample prompt instead of per strings, which resulted in more coherent tuples of (instruction, input, output) and costed around $60.0.

This dataset cannot be used to create models that compete in any way with OpenAI.

Finetuning

To fine-tune the LLaMA model we used the code available on Alpaca Lora, which provides code to finetune the LLaMA model using PEFT from Hugging Face. We run finetuning for 3 epochs using sequence length of 512 with no gradient accumulation on a single A6000 with 48GB VRAM for 12 hours on top of LLaMA-7B.

Example outputs

Stanford Alpaca:

Instruction: Inventa una excusa creativa para decir que no tengo que ir a la fiesta.
Response: I'm sorry, I can't make it to the party. I have to stay home and take care of my sick pet.

BERTIN Alpaca LoRA:

Instruction: Inventa una excusa creativa para decir que no tengo que ir a la fiesta.
Response: No puedo ir a la fiesta porque tengo que terminar un proyecto urgente.

Stanford Alpaca:

Instruction: ¿Cómo puedo comenzar una carrera como científico de datos? Responde con una lista de pasos a seguir.
Response: To begin a career as a data scientist, there are a few steps to take. First, you should have a bachelor's degree in a STEM-related field, such as computer science, mathematics, statistics, or engineering. You should also have experience with programming languages such as Python, R, or Java. Additionally, it is helpful to have knowledge of machine learning, data visualization, and data analytics. Finally, it is important to stay up to date with the latest trends and technologies in the field.

BERTIN Alpaca LoRA:

Instruction: ¿Cómo puedo comenzar una carrera como científico de datos? Responde con una lista de pasos a seguir.
Response: Para comenzar una carrera como científico de datos, hay varios pasos a seguir. Primero, obtener una licenciatura en matemáticas, informática o ciencias de la computación. Luego, obtener una maestría o doctorado en ciencias de la computación, informática o alguna otra área relacionada. Finalmente, obtener experiencia en el campo trabajando en proyectos de investigación o desarrollando aplicaciones.

You can test it using the eval notebook here.

References

Hardware Requirements

For training we have used an A6000 48GB VRAM Nvidia GPU. For eval, you can use a T4.

Downloads last month
5
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.

Dataset used to train bertin-project/bertin-alpaca-lora-7b