--- library_name: transformers language: - es base_model: - Qwen/Qwen2.5-7B-Instruct pipeline_tag: text-generation license: cc-by-nc-4.0 --- # Model Card for RigoChat-7b-v2 `RigoChat-7b-v2` is a Qwen-2.5-based model specifically designed to provide accurate responses from Spanish queries. Specifically, is based on the [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) model and has been fine-tuned with Direct Preference Optimization ([DPO](https://arxiv.org/pdf/2305.18290)) for improved performance in Spanish language. ## Model Details ### Model Description This model is the second version of RigoChat, a family of Large Language Models (LLMs) designed to solve typical NLP tasks with Spanish instructions such as: Tool Use, Summarization, Math, Code, Abstractive-QA, etc. Like [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct), this model has no specific use case and can be applied to a wide range of tasks. Indeed, it offers a slight improvement for generalist tasks in Spanish, particularly in RAG (Retriever Augmented Generation) systems with Spanish databases, as its training focused on resolving questions about contexts to prevent hallucinations and ensure safety responses. Key benefits of this model include: - Improved performance on generalist tasks in Spanish. - Enhanced safety and reduced hallucinations in RAG systems with Spanish texts. - Possibility of using it in different hardware requirements, especially those with reduced computational capacity. For more information on how to use RigoChat-7b-v2 on reduced hardware, see [IIC/RigoChat-7b-v2-GGUF](https://huggingface.co/IIC/RigoChat-7b-v2-GGUF). Remarkably, this model was trained on a single A100 GPU with limited computational resources, yet achieved its current state in a relatively short time (less than 12 hours). This feat was made possible by leveraging a high-quality dataset and employing advanced techniques such as [LoRA](https://arxiv.org/pdf/2106.09685) to optimize memory usage. Further details on the training process can be found below. - **Developed by:** Instituto de Ingeniería del Conocimiento (IIC). - **Model type:** Generative Fine-tuned Transformer. - **Language(s) (NLP):** Spanish. - **License:** CC BY NC 4.0. - **Finetuned from model:** [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct). ### Model Sources - **Paper:** **Cooming soon**. ## How to Get Started with the Model As [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) or any model that uses the `chatml` template. ### To load the model and tokenizer ```python from transformers import ( AutoModelForCausalLM, AutoTokenizer, ) import torch model_name = "IIC/RigoChat-7b-v2" model = AutoModelForCausalLM.from_pretrained( model_name, torch_dtype=torch.bfloat16, device_map="cuda", trust_remote_code=True, ) tokenizer = AutoTokenizer.from_pretrained( model_name, trust_remote_code=True, ) ``` ### Sample generation ```python messages = [ {"role": "user", "content": "¿Cómo puedo transformar un diccionario de listas en una lista de diccionarios, y viceversa, en Python sin utilizar bucles for?"} ] text = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True, ) model_inputs = tokenizer([text], return_tensors="pt").to(model.device) generated_ids = model.generate( **model_inputs, max_new_tokens=1024, ) generated_ids = [ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids) ] response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0] ``` ### Tool Use ```python def get_current_weather(location: str, date: str) -> float: """ Obtener la datos del tiempo de una localización. Args: location: La locaización, con el siguiente formato: "Ciudad, País." date: La fecha, en el formato AAAA-MM-DD. Returns: El tiempo en dicha localización. """ return {"temperatura": 22, "cielo": "nublado", "probabilidad de lluvias": "60%"} messages = [ {"role": "user", "content": "Este fin de semana quiero visitar Madrid, y no se qué ropa llevarme. ¿Podrías decirme qué tal va a hacer? Es el puente del 6 de diciembre de 2024."} ] text = tokenizer.apply_chat_template( messages, tokenize=False, tools=[get_current_weather], add_generation_prompt=True ) model_inputs = tokenizer([text], return_tensors="pt").to(model.device) generated_ids = model.generate( **model_inputs, max_new_tokens=1024 ) generated_ids = [ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids) ] response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0] ``` ## Training Details ### Training Data A combination of both public and private datasets designed in the IIC. The dataset consists of 21975 conversations in Spanish, with the format `chatml` and has the same structure as the [Anthropic/hh-rlhf dataset](https://huggingface.co/datasets/Anthropic/hh-rlhf). Each conversation has two variants: `chosen` and `rejected`, where the only thing that changes is the last answer of the assistant. The last answer in the `chosen` variant is considered a better answer than the one in the `rejected` variant. Different techniques have been used to generate the dataset, which we explain in depth in the paper (**coming soon**). ### Training Procedure We use the [Transformer Reinforcement Learning](https://huggingface.co/docs/trl/index) (TRL) library. Specifically, we have applied [the script they have published](https://github.com/huggingface/trl/blob/main/examples/scripts/dpo.py) as an example for using DPO to the dataset we have generated. #### Training Hyperparameters - **Training regime:** [More Information Needed] #### Speeds, Sizes, Times [optional] [More Information Needed] ## Evaluation ### Testing Data, Factors & Metrics #### Testing Data [More Information Needed] #### Factors [More Information Needed] #### Metrics [More Information Needed] ### Results [More Information Needed] #### Summary ## Model Examination [optional] [More Information Needed] ## Environmental Impact Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700). - **Hardware Type:** [More Information Needed] - **Hours used:** [More Information Needed] - **Cloud Provider:** [More Information Needed] - **Compute Region:** [More Information Needed] - **Carbon Emitted:** [More Information Needed] ## Technical Specifications [optional] ### Model Architecture and Objective [More Information Needed] ### Compute Infrastructure [More Information Needed] #### Hardware [More Information Needed] #### Software [More Information Needed] ## Citation [optional] **BibTeX:** [More Information Needed] **APA:** [More Information Needed] ## Glossary [optional] [More Information Needed] ## More Information [optional] [More Information Needed] ## Model Card Authors [optional] [More Information Needed] ## Model Card Contact [More Information Needed]