
## Mistral 7b Reverse Instruct

This model is sft (LoRA) fine tuned to reverse engineer the original prompt of a given LLM output/response.    
Use Case: The generation of synthetic instruct datasets for developing chatbots and domain specific fine tuning (e.g. "Summarization" & "Roleplay").  It is useful for labelling unlabeled datasets. 


- base_model: mistralai/Mistral-7B-v0.1 (=checkpoint-v1)
- base_model: mistralai/Mistral-7B-v0.2 (>=checkpoint-v2)

For convinience the latest model export is provided under [/latest_model_export](https://huggingface.co/Philipp-Sc/mistral-7b-reverse-instruct/tree/main/latest_model_export) as well as gguf quantized versions under [/latest_ggml_models](https://huggingface.co/Philipp-Sc/mistral-7b-reverse-instruct/tree/main/latest_ggml_models)

## Response Format

"[INST]\n### System:\n{system}\n### Instruction:\n{instruction}\n[/INST]\n"

- Grammar File: [inst_format.gbnf](https://huggingface.co/Philipp-Sc/mistral-7b-reverse-instruct/blob/main/inst_format.gbnf)


## Prompt Template

"\n### System:\nYou craft instructions for generating the given output through reverse engineering.\n### Instruction:\nDecipher the steps used to produce the given output and articulate a refined set of instructions (System & Instruction).\n### OUTPUT:\n {output}"

(use the template without the " ")

## Example Completions

Prompt 1:
```bash
### System:
You craft instructions for generating the given output through reverse engineering.
### Instruction:
Decipher the steps used to produce the given output and articulate a refined set of instructions (System & Instruction).
### OUTPUT:
SE3 Condenser Microphone from SE Electronics Sonic Distribution is now handling the SE Electronics line of imported studio condensers. The SE3 caught my eye at the Summer NAMM Show in Nashville and is their flagship pencil microphone with a fixed cardioid pattern and 48V phantom powering. This mic uses Class A FET amplifier electronics and has both low cut filter and -10dB pad switches. I had the opportunity to try this mic out on several sources while recording a band and was impressed by its natural sound and all around usefulness. I used it for acoustic guitar overdubs where the low cut filter helped to tame a jumbo bodied guitar's boomy sound. The gentle presence lift added a sparkle without using EQ. I also tried it on drums and cymbals and it (using the pad) didn't fold up (overload) at all. I even tried it on vocals with good results although it does 'pop' easily and required a couple of pop screens. Housed in an elegantly finished new body design, it comes with a sturdy shock mount and packaged in a deluxe wooden travel case. Significant specifications are: frequency response rated at 20Hz-20khz; sensitivity is 10mV/Pa +/- 2dB; noise level is 17dB (A weighted); and Max SPL for 0.5% THD @ 1kHz is 135dB. I certainly found a 'Swiss army knife' of a condenser with the SE3 and I completely recommend it for any studio task especially acoustic instruments such as guitar, violin, cello or string bass.
### RESPONSE:
```
(example from [vikp/reverse_instruct](https://huggingface.co/vikp/reverse_instruct))


Response 1:
```bash
[INST]
### System:
You are a professional musician and sound engineer who specializes in mixing live music. You have recently reviewed the SE Electronics SE3 Condenser Microphone and want to share your experience with your followers on social media.
### Instruction:
Write a short review of the SE Electronics SE3 Condenser Microphone for your social media followers.
[/INST]
```

Prompt 2:
```bash
### System:
You craft instructions for generating the given output through reverse engineering.
### Instruction:
Decipher the steps used to produce the given output and articulate a refined set of instructions (System & Instruction).
### OUTPUT:
**Lesson: Introduction to Sales** **Objective:** To introduce students to the concept of sales and its importance in business. **Introduction:** Sales is the process of persuading someone to buy a product or service. It is an essential part of any business, as it helps generate revenue and grow the company. In this lesson, we will learn about the basics of sales and how it can benefit businesses. **Section 1: What is Sales?** **Topic 1: Definition of Sales** Sales is the process of persuading someone to buy a product or service. It involves identifying the needs of potential customers, presenting solutions that meet those needs, and closing the deal by making the sale. **Topic 2: Importance of Sales** Sales is crucial to the success of a business because it generates revenue and helps the company grow. Without sales, businesses would not be able to make profits, expand their operations, or reach new customers. **Topic 3: Types of Sales** There are several types of sales, including direct sales, indirect sales, and online sales. Direct sales involve selling products or services directly to customers, while indirect sales involve selling through intermediaries such as distributors or retailers. Online sales involve selling products or services over the internet. **Section 2: Skills Required for Sales** **Topic 1: Communication Skills** Effective communication is essential for sales success. Salespeople must be able to communicate clearly and persuasively to potential customers, negotiate deals, and close sales. **Topic 2: Interpersonal Skills** Salespeople must also have strong interpersonal skills, including active listening, empathy, and building relationships with customers. These skills help salespeople understand customer needs and build trust with them. **Topic 3: Time Management Skills** Sales can be a time-consuming process, so salespeople must be skilled at managing their time effectively. They must prioritize tasks, set goals, and stay organized to be successful. **Section 3: Benefits of Sales** **Topic 1: Financial Benefits** Sales generate revenue for businesses, which can be used to fund growth and expansion. Sales also help businesses increase their profits by generating more income than expenses. **Topic 2: Customer Benefits** Sales can also benefit customers by providing them with products or services that meet their needs and improve their lives. Sales help businesses introduce new products and services to the market, which can improve customers' lives and create new opportunities for them. **Conclusion:** In conclusion, sales is an essential part of any business, as it helps generate revenue and grow the company. By understanding the basics of sales, developing essential skills, and recognizing the benefits of sales, individuals can become successful salespeople and contribute to the growth of their businesses. **Glossary:** - Sales: The process of persuading someone to buy a product or service - Interpersonal Skills: The ability to communicate and build relationships with others - Time Management Skills: The ability to prioritize tasks, set goals, and stay organized - Revenue: The income generated by a business from its sales - Profit: The difference between a business's income and expenses - Intermediaries: Companies that sell products or services on behalf of another company``
```
(source [nampdn-ai/tiny-textbooks](https://huggingface.co/nampdn-ai/tiny-textbooks))


Response 2:
```bash
[INST]
### System:
You are an AI assistant. You should describe the task and explain your answer. While answering a multiple choice question, first output the correct answer(s). Then explain why other answers are wrong. You might need to use additional information to answer the question.
### Instruction:
Create a detailed lesson plan with a specific focus on teaching the concept of sales, including the various aspects of the sales process such as lead generation, prospecting, qualification, presentation, objection handling, closing techniques, and post-sales activities. The lesson should also cover the key skills required for successful sales professionals, such as communication, interpersonal skills, time management, and product knowledge. Additionally, the plan should include examples of real-life sales scenarios and role-plays to help students develop practical skills and gain a deeper understanding of the sales industry. Finally, the lesson plan should be designed to meet the needs of different learning styles, incorporating visual aids, interactive activities, and assessments to ensure maximum engagement and effectiveness for all learners.
[/INST]
```

## Training Dataset

About 21k items of the following datasets were used. (mostly coding-like tasks were removed)

- v1 & v2: [reverse-instruct_v1.json](https://huggingface.co/Philipp-Sc/mistral-7b-reverse-instruct/blob/main/reverse-instruct_v1.json)
- v3: [reverse-instruct_v2.json](https://huggingface.co/Philipp-Sc/mistral-7b-reverse-instruct/blob/main/reverse-instruct_v2.json)

The reverse instruct dataset has been compiled with entries from the following datasets:

- [alpaca_gpt4_data](https://raw.githubusercontent.com/Instruction-Tuning-with-GPT-4/GPT-4-LLM/main/data/alpaca_gpt4_data.json)
- [roleplay-instruct-v2.1](https://raw.githubusercontent.com/teknium1/GPTeacher/main/Roleplay%20Supplemental/roleplay-instruct-v2.1.json)
- [wizardlm_orca](https://huggingface.co/datasets/pankajmathur/WizardLM_Orca/resolve/main/wizardlm_orca.json)
- [toxic-dpo-v0.1](https://huggingface.co/datasets/unalignment/toxic-dpo-v0.1/resolve/main/toxic-dpo.parquet)
- [orca_dpo_pairs](https://huggingface.co/datasets/Intel/orca_dpo_pairs/resolve/main/orca_rlhf.jsonl)
- [occultexpert](https://huggingface.co/datasets/teknium/trismegistus-project/resolve/main/occultexpert.json)

## Training Procedure

```bash
!cd LLaMA-Factory && WANDB_DISABLED=True PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:256 accelerate launch \
    --multi_gpu \
    --mixed_precision fp16 \
    --num_processes 2 \
    --num_machines 1 \
    --rdzv_backend static \
    --same_network \
    --gpu_ids all \
    --machine_rank 0 \
    --main_training_function main \
    --  src/train_bash.py  \
    --stage sft \
    --model_name_or_path mistralai/Mistral-7B-Instruct-v0.2 \
    --adapter_name_or_path path_to_checkpoint \
    --flash_attn \
    --neftune_noise_alpha 5 \
    --do_train \
    --dataset default \
    --template vanilla \
    --finetuning_type lora \
    --lora_target q_proj,v_proj \
    --output_dir path_to_sft_checkpoint \
    --overwrite_cache \
    --per_device_train_batch_size 1 \
    --gradient_accumulation_steps 1 \
    --lr_scheduler_type cosine \
    --logging_steps 10 \
    --save_steps 10 \
    --save_total_limit 3 \
    --learning_rate 5e-5 \
    --num_train_epochs 9.0 \
    --plot_loss \
    --fp16 \
    --overwrite_output_dir \
    --cutoff_len 4096 \
    --quantization_bit 4
```

## Training Time

- v1: ~12h on Kaggle's P100 GPU
- v2: >30h on Kaggle's T4 x2
- v3: >40h on Kaggle's T4 x2

## Loss

- v3:
```bash 
{'loss': 0.4424, 'learning_rate': 4.8398000023144565e-05, 'epoch': 1.03}
```

### Framework versions

- LLaMA-Factory
{"language": ["en"], "license": "apache-2.0", "datasets": ["pankajmathur/WizardLM_Orca", "teknium/trismegistus-project", "unalignment/toxic-dpo-v0.1", "Intel/orca_dpo_pairs"], "pipeline_tag": "text-generation"}
safetensors gguf text-generation en dataset:pankajmathur/WizardLM_Orca dataset:teknium/trismegistus-project dataset:unalignment/toxic-dpo-v0.1 dataset:Intel/orca_dpo_pairs license:apache-2.0 region:us