Downloads · 30 days
12
6% of all-time downloads
guaran-ia/gntweets-lm
gntweets-lm is a text generation model from guaran-ia. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as gpl-3.0.
The model GNTweetsLM is intended to be used to validate the quality of Guarani text. It was trained on a publicly available corpus of tweets written in Guarani and Jopara (Góngora et al. 2021).
Downloads · 30 days
12
6% of all-time downloads
All-time downloads
185
Public
Parameters
9.2B
18.5 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors18.5 GB · 100%
From the Hugging Face model README
The model GNTweetsLM is intended to be used to validate the quality of Guarani text. It was trained on a publicly available corpus of tweets written in Guarani and Jopara (Góngora et al. 2021).
⚠️ Although the model is based on a transformer-based architecture (Gemma2-9b-it), it was not developed as a generative tool — its primary use is to compute the perplexity score of Guarani documents. Lower perplexity may indicate text that is more predictable by the model and more similar to the reference high-quality corpus.
princeton-nlp/gemma-2-9b-it-SimPOguaran-ia/gntweetsGemma2ForCausalLM42358416143362560008192 tokensfloat16tokenizer.json and tokenizer_config.jsongeneration_config.jsonchat_template.jinja112e-50.01100paged_adamw_8bitlinear6bf162048936 records (1916928 tokens)117 records (239616 tokens)117 records (239616 tokens)princeton-nlp/gemma-2-9b-it-SimPOguaran-ia/gntweetsCompute perplexity for a given Guarani text using the fine-tuned model:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
import math
model_id = 'guaran-ia/gntweets-lm'
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
model.eval()
def perplexity(text: str) -> float:
inputs = tokenizer(text, return_tensors='pt')
with torch.no_grad():
outputs = model(**inputs, labels=inputs['input_ids'])
loss = outputs.loss
return math.exp(loss.item())
text = "Your Guarani text here."
print(f"Perplexity: {perplexity(text):.4f}")
If input length exceeds the model/tokenizer maximum (8192 tokens), you can follow the next recipe to compute perplexity over sliding chunks and average per-token loss.
import torch, math
def perplexity_sliding(text: str, model, tokenizer, max_len: int = 8192, stride: int = 4096):
"""Compute perplexity over long text by slicing into overlapping chunks.
- `max_len` should be <= model.config.max_position_embeddings (8192).
- `stride` controls overlap; larger overlap gives smoother per-token averaging.
"""
enc = tokenizer(text, return_tensors='pt')['input_ids'][0]
n = enc.size(0)
if n == 0:
return float('nan')
total_nll = 0.0
total_tokens = 0
start = 0
while start < n:
end = min(start + max_len, n)
input_ids = enc[start:end].unsqueeze(0)
with torch.no_grad():
outputs = model(input_ids, labels=input_ids)
# outputs.loss is the average NLL for the chunk
loss = outputs.loss.item()
chunk_len = end - start
total_nll += loss * chunk_len
total_tokens += chunk_len
if end == n:
break
start += stride
avg_nll = total_nll / total_tokens
return math.exp(avg_nll)
# Example usage:
text = open('some_guarani.txt', encoding='utf-8').read()
tokenizer.model_max_length = 8192
print(f"Perplexity (sliding): {perplexity_sliding(text, model, tokenizer):.4f}")
This model checkpoint and accompanying files are released under the GNU General Public License v3 (GPLv3).
See the LICENSE file in this directory for the full license text.