Update README.md
Browse files
README.md
CHANGED
|
@@ -1,58 +1,115 @@
|
|
| 1 |
-
|
| 2 |
-
base_model: NousResearch/Meta-Llama-3-8B
|
| 3 |
-
library_name: transformers
|
| 4 |
-
model_name: LLama3
|
| 5 |
-
tags:
|
| 6 |
-
- generated_from_trainer
|
| 7 |
-
- trl
|
| 8 |
-
- sft
|
| 9 |
-
licence: license
|
| 10 |
-
---
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
It has been trained using [TRL](https://github.com/huggingface/trl).
|
| 16 |
|
| 17 |
-
##
|
| 18 |
|
| 19 |
```python
|
| 20 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
```
|
| 27 |
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
-
-
|
| 38 |
-
-
|
| 39 |
-
-
|
| 40 |
-
- Datasets: 4.0.0
|
| 41 |
-
- Tokenizers: 0.21.2
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
|
|
|
| 45 |
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
```bibtex
|
| 50 |
-
@misc{vonwerra2022trl,
|
| 51 |
-
title = {{TRL: Transformer Reinforcement Learning}},
|
| 52 |
-
author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
|
| 53 |
-
year = 2020,
|
| 54 |
-
journal = {GitHub repository},
|
| 55 |
-
publisher = {GitHub},
|
| 56 |
-
howpublished = {\url{https://github.com/huggingface/trl}}
|
| 57 |
-
}
|
| 58 |
-
```
|
|
|
|
| 1 |
+
# Llama 3 Domain Name Generator (LoRA fine-tuned)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
Ce modèle est une version fine-tunée de [NousResearch/Meta-Llama-3-8B](https://huggingface.co/NousResearch/Meta-Llama-3-8B) pour la génération de noms de domaine disponibles pour des entreprises.
|
| 4 |
|
| 5 |
+
---
|
|
|
|
| 6 |
|
| 7 |
+
## 🚀 **Utilisation rapide**
|
| 8 |
|
| 9 |
```python
|
| 10 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 11 |
+
from peft import PeftModel
|
| 12 |
+
import torch
|
| 13 |
+
|
| 14 |
+
# Identifiants du modèle
|
| 15 |
+
peft_model_id = "Thehunter99/LLama3"
|
| 16 |
+
base_model_id = "NousResearch/Meta-Llama-3-8B"
|
| 17 |
+
|
| 18 |
+
# Device
|
| 19 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 20 |
+
|
| 21 |
+
# Tokenizer
|
| 22 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
| 23 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 24 |
|
| 25 |
+
# Config QLoRA (optionnel)
|
| 26 |
+
bnb_config = BitsAndBytesConfig(
|
| 27 |
+
load_in_4bit=True,
|
| 28 |
+
bnb_4bit_quant_type="nf4",
|
| 29 |
+
bnb_4bit_compute_dtype=torch.bfloat16 if device == "cuda" else torch.float32,
|
| 30 |
+
bnb_4bit_use_double_quant=True,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Charger le modèle de base
|
| 34 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 35 |
+
base_model_id,
|
| 36 |
+
quantization_config=bnb_config if device == "cuda" else None,
|
| 37 |
+
device_map="auto" if device == "cuda" else None,
|
| 38 |
+
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Charger l'adapter LoRA
|
| 42 |
+
model = PeftModel.from_pretrained(base_model, peft_model_id)
|
| 43 |
+
model.eval()
|
| 44 |
+
if device == "cpu":
|
| 45 |
+
model = model.to("cpu")
|
| 46 |
+
|
| 47 |
+
# Fonction d'inférence
|
| 48 |
+
def generate_domains(prompt, max_new_tokens=50, temperature=0.7):
|
| 49 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 50 |
+
with torch.no_grad():
|
| 51 |
+
outputs = model.generate(
|
| 52 |
+
**inputs,
|
| 53 |
+
max_new_tokens=max_new_tokens,
|
| 54 |
+
do_sample=True,
|
| 55 |
+
temperature=temperature
|
| 56 |
+
)
|
| 57 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 58 |
+
|
| 59 |
+
# Exemple de prompt (à respecter strictement)
|
| 60 |
+
prompt = """<|begin_of_text|><|start_header_id|>system<|end_header_id|>
|
| 61 |
+
Generate available domain names for businesses. Use only .com, .io, .app, .co TLDs.
|
| 62 |
+
Output format: comma-separated domains<|eot_id|>
|
| 63 |
+
<|start_header_id|>user<|end_header_id|>
|
| 64 |
+
organic bakery in berlin<|eot_id|>
|
| 65 |
+
<|start_header_id|>assistant<|end_header_id|>"""
|
| 66 |
+
|
| 67 |
+
result = generate_domains(prompt, max_new_tokens=30, temperature=0.1)
|
| 68 |
+
print(result)
|
| 69 |
```
|
| 70 |
|
| 71 |
+
---
|
| 72 |
|
| 73 |
+
## 📝 **Format du prompt d’inférence**
|
| 74 |
|
| 75 |
+
**Respectez exactement ce format :**
|
| 76 |
+
```
|
| 77 |
+
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
|
| 78 |
+
Generate available domain names for businesses. Use only .com, .io, .app, .co TLDs.
|
| 79 |
+
Output format: comma-separated domains<|eot_id|>
|
| 80 |
+
<|start_header_id|>user<|end_header_id|>
|
| 81 |
+
[description de l'entreprise]<|eot_id|>
|
| 82 |
+
<|start_header_id|>assistant<|end_header_id|>
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
**Exemple :**
|
| 86 |
+
```
|
| 87 |
+
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
|
| 88 |
+
Generate available domain names for businesses. Use only .com, .io, .app, .co TLDs.
|
| 89 |
+
Output format: comma-separated domains<|eot_id|>
|
| 90 |
+
<|start_header_id|>user<|end_header_id|>
|
| 91 |
+
eco-friendly coffee shop in Paris<|eot_id|>
|
| 92 |
+
<|start_header_id|>assistant<|end_header_id|>
|
| 93 |
+
```
|
| 94 |
|
| 95 |
+
---
|
| 96 |
|
| 97 |
+
## 📋 **Conseils**
|
| 98 |
|
| 99 |
+
- Utilisez le même prompt que ci-dessus pour de meilleurs résultats.
|
| 100 |
+
- Le modèle retourne une liste de domaines séparés par des virgules.
|
| 101 |
+
- Pour des résultats reproductibles, utilisez `temperature=0.1`.
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## 📚 **Dataset d’entraînement**
|
| 106 |
+
|
| 107 |
+
Le modèle a été fine-tuné sur un dataset synthétique de descriptions d’entreprises et de suggestions de domaines.
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
|
| 111 |
+
## ❓ **Questions**
|
| 112 |
|
| 113 |
+
Pour toute question ou suggestion, ouvrez une issue sur le repo ou contactez-moi sur Hugging Face.
|
| 114 |
|
| 115 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|