mrm8488 commited on
Commit
238fc40
1 Parent(s): ebcd5cd

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +96 -0
README.md ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ model-index:
3
+ - name: lince-zero
4
+ results: []
5
+ license: apache-2.0
6
+ language:
7
+ - es
8
+ pipeline_tag: text-generation
9
+ datasets:
10
+ - tatsu-lab/alpaca
11
+ - databricks/databricks-dolly-15k
12
+ library_name: transformers
13
+ inference: false
14
+ ---
15
+
16
+ # Llama-2-ft-instruct-es
17
+
18
+ [Llama 2 (7B)](https://huggingface.co/meta-llama/Llama-2-7b) fine-tuned on [Clibrain](https://huggingface.co/clibrain)'s Spanish instructions dataset.
19
+
20
+
21
+ # Model Details
22
+
23
+ Llama 2 is a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 70 billion parameters. This is the repository for the 7B pretrained model. Links to other models can be found in the index at the bottom.
24
+
25
+
26
+ # Example of Usage
27
+
28
+ ```py
29
+ import torch
30
+ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoTokenizer, GenerationConfig
31
+
32
+ model_id = "clibrain/Llama-2-ft-instruct-es"
33
+
34
+ model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True).to("cuda")
35
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
36
+
37
+ def create_instruction(instruction, input_data=None, context=None):
38
+ sections = {
39
+ "Instrucci贸n": instruction,
40
+ "Entrada": input_data,
41
+ "Contexto": context,
42
+ }
43
+
44
+ system_prompt = "A continuaci贸n hay una instrucci贸n que describe una tarea, junto con una entrada que proporciona m谩s contexto. Escriba una respuesta que complete adecuadamente la solicitud.\n\n"
45
+ prompt = system_prompt
46
+
47
+ for title, content in sections.items():
48
+ if content is not None:
49
+ prompt += f"### {title}:\n{content}\n\n"
50
+
51
+ prompt += "### Respuesta:\n"
52
+
53
+ return prompt
54
+
55
+
56
+ def generate(
57
+ instruction,
58
+ input=None,
59
+ context=None,
60
+ max_new_tokens=128,
61
+ temperature=0.1,
62
+ top_p=0.75,
63
+ top_k=40,
64
+ num_beams=4,
65
+ **kwargs
66
+ ):
67
+
68
+ prompt = create_instruction(instruction, input, context)
69
+ print(prompt.replace("### Respuesta:\n", ""))
70
+ inputs = tokenizer(prompt, return_tensors="pt")
71
+ input_ids = inputs["input_ids"].to("cuda")
72
+ attention_mask = inputs["attention_mask"].to("cuda")
73
+ generation_config = GenerationConfig(
74
+ temperature=temperature,
75
+ top_p=top_p,
76
+ top_k=top_k,
77
+ num_beams=num_beams,
78
+ **kwargs,
79
+ )
80
+ with torch.no_grad():
81
+ generation_output = model.generate(
82
+ input_ids=input_ids,
83
+ attention_mask=attention_mask,
84
+ generation_config=generation_config,
85
+ return_dict_in_generate=True,
86
+ output_scores=True,
87
+ max_new_tokens=max_new_tokens,
88
+ early_stopping=True
89
+ )
90
+ s = generation_output.sequences[0]
91
+ output = tokenizer.decode(s)
92
+ return output.split("### Respuesta:")[1].lstrip("\n")
93
+
94
+ instruction = "Dame una lista de lugares a visitar en Espa帽a."
95
+ print(generate(instruction))
96
+ ```