edumunozsala's picture
Update README.md
3aced34 verified
metadata
language:
  - es
license: apache-2.0
library_name: transformers, pe
tags:
  - trl
  - sft
  - generated_from_trainer
base_model: google/gemma-7b

Model Card for Model ID

Model Details

Model Description

This model is a fine-tuned version of google/gemma-7b on the generator dataset.

This is the model card of a 馃 transformers model that has been pushed on the Hub. This model card has been automatically generated.

  • Developed by: Hacendado and QA-legal-refugees team

  • Language(s) (NLP): [Spanish]

  • Finetuned from model [optional]: google/gemma-7b

Uses

Direct Use

The primary objective of this model is to facilitate question answering (QA) tasks pertaining to Spanish refugee legislation. With its refined understanding of the nuances and intricacies of this legal domain

Out-of-Scope Use

Misuse includes any application that promotes unethical practices, misinterprets refugee law, or uses the model for malicious purposes. The model is not designed to replace professional legal advice.

Bias, Risks, and Limitations

The model, while powerful, has limitations inherent to AI, including biases present in the training data. It may not cover all nuances of refugee regulations or adapt to changes in law without updates.

Training Details

Training Data

The dataset used was instruct-legal-refugiados-es We wanted to make a conversation model so we investigated the base model prompt in order to make conversational base on chatml format

we identified the special tokens so the model could understand the different roles in the conversation

Example

<bos><|im_start|>system
You are Gemma.<|im_end|>
<|im_start|>user
Hello, how are you?<|im_end|>
<|im_start|>assistant
I'm doing great. How can I help you today?<|im_end|>\n<eos>

so we used Phil Schmid's gemma chatml tokenizer to adapt our dataset for training

Training Procedure

The training was done using RTX 4090 from Vast.ai with PeRF and Lora

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 5e-05
  • train_batch_size: 2
  • eval_batch_size: 8
  • seed: 66
  • gradient_accumulation_steps: 2
  • total_train_batch_size: 4
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lr_scheduler_type: constant
  • lr_scheduler_warmup_ratio: 0.03
  • num_epochs: 3

Inference Example

import torch

from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    BitsAndBytesConfig,
    pipeline
)

model_id = "somosnlp/gemma-7b-it-legal-refugee-v0.1.1"
tokenizer_id = "somosnlp/gemma-7b-it-legal-refugee-v0.1.1"

tokenizer = AutoTokenizer.from_pretrained(tokenizer_id)
# Cargamos el modelo en 4 bits para agilizar la inferencia
quantization_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_compute_dtype=torch.float16,
    bnb_4bit_use_double_quant=True,
)

model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    device_map="auto",
    quantization_config=quantization_config,
)

# Generamos el pipeline de generaci贸n de texto
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
# Definimos el eos token para el modelo
eos_token = tokenizer("<|im_end|>",add_special_tokens=False)["input_ids"][0]

def generate_inference(instruction, input, temperature):
    prompt = pipe.tokenizer.apply_chat_template([{"role": "user", 
                                                  "content": f"{instruction}/n{input}"}], tokenize=False, add_generation_prompt=True)
    outputs = pipe(prompt, max_new_tokens=256, do_sample=True, num_beams=1, temperature=float(temperature), top_k=50, top_p=0.95, 
                   max_time= 300, eos_token_id=eos_token)
    return outputs[0]['generated_text'][len(prompt):].strip()


instruction = "驴Podr铆as explicarme brevemente los hechos que originan el procedimiento y las posibles calificaciones, as铆 como las sanciones correspondientes, seg煤n lo expuesto en el contexto?"
input = "b) Hechos que motivan la incoaci贸n del procedimiento sucintamente expuestos, su posible calificaci贸n y las sanciones que pudieran corresponder, sin perjuicio de lo que resulte de la instrucci贸n. c) Instructor y, en su caso, secretario del procedimiento, con expresa indicaci贸n del r茅gimen de recusaci贸n de 茅stos. d) 脫rgano competente para la resoluci贸n del expediente y norma que le atribuye tal competencia. e) Indicaci贸n de la posibilidad de que el presunto responsable pueda reconocer voluntariamente su responsabilidad. f) Medidas de car谩cter provisional que se hayan acordado por el 贸rgano competente para iniciar el procedimiento sancionador, sin perjuicio de las que se puedan adoptar durante 茅ste de conformidad con los art铆culos 55 y 61 de la Ley Org谩nica 4/2000, de 11 de enero. g) Indicaci贸n del derecho a formular alegaciones y a la audiencia en el procedimiento y de los plazos para su ejercicio. 2. El acuerdo de iniciaci贸n se comunicar谩 al instructor con traslado de cuantas actuaciones existan al respecto y se notificar谩 a los interesados, entendi茅ndose en todo caso por tal al expedientado. En la notificaci贸n se advertir谩 a los interesados que, de no efectuar alegaciones sobre el contenido de la iniciaci贸n del procedimiento en el plazo previsto en el art铆culo siguiente, no realizarse propuesta de prueba o no ser admitidas, por improcedentes o innecesarias, las pruebas propuestas, la iniciaci贸n podr谩 ser considerada propuesta de resoluci贸n cuando contenga un pronunciamiento preciso acerca de la responsabilidad imputada, con los efectos previstos en los art铆culos 229 y 230."

response = test_inference(instruction, input, 0.3)
print(f"Response:\n{response}")