Update README.md
Browse files
README.md
CHANGED
|
@@ -87,13 +87,56 @@ Lee el siguiente texto y hazlo m谩s claro:
|
|
| 87 |
###Texto aclarado:
|
| 88 |
"""
|
| 89 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
|
|
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
- **Developed by:** [Sergio Chic贸n](https://huggingface.co/telodigoensergio)
|
| 95 |
-
- **
|
| 96 |
-
- **Language(s) (NLP):** Python
|
| 97 |
- **Finetuned from model:** [Microsoft/phi-2](https://huggingface.co/microsoft/phi-2)
|
| 98 |
|
| 99 |
### Model Sources
|
|
|
|
| 87 |
###Texto aclarado:
|
| 88 |
"""
|
| 89 |
```
|
| 90 |
+
## Probar el modelo:
|
| 91 |
+
**Importar las librer铆as necesarias**:
|
| 92 |
+
```
|
| 93 |
+
!pip install transformers
|
| 94 |
+
!pip install bitsandbytes
|
| 95 |
+
!pip install accelerate
|
| 96 |
+
import torch
|
| 97 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
**Configuraci贸n de BitsAndBytes:**
|
| 101 |
+
```
|
| 102 |
+
bnb_config = BitsAndBytesConfig(load_in_4bit=True,
|
| 103 |
+
bnb_4bit_quant_type='nf4',
|
| 104 |
+
bnb_4bit_compute_dtype='float16',
|
| 105 |
+
bnb_4bit_use_double_quant=True)
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
**Carga del modelo y el tokenizador:**
|
| 109 |
+
```
|
| 110 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map='auto',
|
| 111 |
+
quantization_config=bnb_config,
|
| 112 |
+
trust_remote_code=True)
|
| 113 |
+
|
| 114 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id,
|
| 115 |
+
add_eos_token=True,
|
| 116 |
+
trust_remote_code=True)
|
| 117 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 118 |
+
tokenizer.truncation_side = "left"
|
| 119 |
+
```
|
| 120 |
+
**Definir prompt e iniciar inferencia:**
|
| 121 |
+
```
|
| 122 |
+
new_prompt = f"""###System:
|
| 123 |
+
Lee el siguiente texto y hazlo m谩s claro:
|
| 124 |
+
###Texto:
|
| 125 |
|
| 126 |
+
{texto}
|
| 127 |
|
| 128 |
+
###Texto aclarado:
|
| 129 |
+
"""
|
| 130 |
+
|
| 131 |
+
inputs = tokenizer(new_prompt, return_tensors="pt", return_attention_mask=False, padding=True, truncation=True)
|
| 132 |
+
outputs = model.generate(**inputs, max_length=1000)
|
| 133 |
+
text = tokenizer.batch_decode(outputs,skip_special_tokens=True)[0]
|
| 134 |
+
print(text)
|
| 135 |
+
```
|
| 136 |
|
| 137 |
|
| 138 |
- **Developed by:** [Sergio Chic贸n](https://huggingface.co/telodigoensergio)
|
| 139 |
+
- **Language(s) (NLP):** Espa帽ol(Espa帽a)
|
|
|
|
| 140 |
- **Finetuned from model:** [Microsoft/phi-2](https://huggingface.co/microsoft/phi-2)
|
| 141 |
|
| 142 |
### Model Sources
|