Downloads · 30 days
14
20% of all-time downloads
DjSteker/spanish-gpt2
spanish-gpt2 is a text generation model from DjSteker. Use it when you need the model to write or continue text. It is set up for transformers.
This modelcard aims to be a base template for new models. It has been generated using this raw template.
Downloads · 30 days
14
20% of all-time downloads
All-time downloads
71
Public
Parameters
124M
498 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors498 MB · 100%
From the Hugging Face model README
This modelcard aims to be a base template for new models. It has been generated using this raw template.
!pip install transformers datasets
from IPython.display import HTML
def display_df(df, max_cols=15, header=True, index=True): return display(HTML(df.to_html(header=header,index=index, max_cols=max_cols)))
import torch from transformers import AutoTokenizer, AutoModelForCausalLM
device = "cuda" if torch.cuda.is_available() else "cpu" model_name = "DjSteker/spanish-gpt2" tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, pad_token_id=tokenizer.eos_token_id).to(device)
print(str(device))
def model_size(model): return sum(t.numel() for t in model.parameters())
print(f"Tamaño del GPT español: {model_size(model)/1000**2:.1f}M parámetros")
import pandas as pd
input_txt =" Le tiro una piedra a la cabeza" # "El amor es eterno mientras dura. "
input_ids = tokenizer(input_txt, return_tensors="pt")["input_ids"].to(device) iterations = [] n_steps = 12 choices_per_step = 5
with torch.no_grad(): for _ in range(n_steps): iteration = dict() iteration["Input"] = tokenizer.decode(input_ids[0]) output = model(input_ids=input_ids) # Seleccionar los logits del primer batch y del último token y aplicar softmax next_token_logits = output.logits[0, -1, :] next_token_probs = torch.softmax(next_token_logits, dim=-1) sorted_ids = torch.argsort(next_token_probs, dim=-1, descending=True) # Almacenar las tokens con mayores probabilidades for choice_idx in range(choices_per_step): token_id = sorted_ids[choice_idx] token_prob = next_token_probs[token_id].cpu().numpy() token_choice = ( f"{tokenizer.decode(token_id)} ({100 * token_prob:.2f}%)" ) iteration[f"Choice {choice_idx+1}"] = token_choice # Añadir el siguiente token previsto a los inputs input_ids = torch.cat([input_ids, sorted_ids[None, 0, None]], dim=-1) iterations.append(iteration)
display_df(pd.DataFrame.from_records(iterations), index=None)
input_ids = tokenizer(input_txt, return_tensors="pt")["input_ids"].to(device) output = model.generate(input_ids, max_length=20) print(tokenizer.decode(output[0]))
max_length = 256
input_txt ="""En un hallazgo sorprendente, los científicos descubrieron una manada de unicornios en la Luna
que vivía en un valle remoto, hasta ahora inexplorado, en la cordillera de Mons Agnes.
Más sorprendente aún para los investigadores fue el hecho de que los unicornios hablaban
un inglés perfecto. """
input_ids = tokenizer(input_txt, return_tensors="pt")["input_ids"].to(device)
output_greedy = model.generate(input_ids, max_length=max_length, do_sample=False)
print(tokenizer.decode(output_greedy[0]))
torch.manual_seed(42) output_temp = model.generate(input_ids, max_length=max_length, do_sample=True, temperature=2.0, top_k=0) print(tokenizer.decode(output_temp[0]))
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
Use the code below to get started with the model.
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
BibTeX:
[More Information Needed]
APA:
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]