Large language models (LLMs) have significantly advanced natural language processing, but their progress has yet to be equal across languages. While most LLMs are trained in high-resource languages like English, multilingual models generally underperform monolingual ones. Additionally, aspects of their multilingual foundation sometimes restrict the byproducts they produce, like computational demands and licensing regimes. Hence, we developed the TeenyTinyLlama pair: two compact models for Brazilian Portuguese text generation.
The primary intended use of TeenyTinyLlama is to research the challenges related to developing language models for low-resource languages. Checkpoints saved during training are intended to provide a controlled setting for performing scientific experiments. You may also further fine-tune and adapt TeenyTinyLlama for deployment, as long as your use is following the Apache 2.0 license. If you decide to use pre-trained TeenyTinyLlama as a basis for your fine-tuned model, please conduct your own risk and bias assessment.
Out-of-scope Use
TeenyTinyLlama is not intended for deployment. It is not a product and should not be used for human-facing interactions.
TeenyTinyLlama models are Brazilian Portuguese language only and are not suitable for translation or generating text in other languages.
TeenyTinyLlama has not been fine-tuned for downstream contexts in which language models are commonly deployed.
Basic usage
Using the pipeline:
python
1from transformers import pipeline
23generator = pipeline("text-generation", model="nicholasKluge/TeenyTinyLlama-460m")45completions = generator("Astronomia é a ciência", num_return_sequences=2, max_new_tokens=100)67for comp in completions:8print(f"🤖 {comp['generated_text']}")
Using the AutoTokenizer and AutoModelForCausalLM:
python
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
34# Load model and the tokenizer5tokenizer = AutoTokenizer.from_pretrained("nicholasKluge/TeenyTinyLlama-460m", revision='main')6model = AutoModelForCausalLM.from_pretrained("nicholasKluge/TeenyTinyLlama-460m", revision='main')78# Pass the model to your device9device = torch.device("cuda"if torch.cuda.is_available()else"cpu")1011model.eval()12model.to(device)1314# Tokenize the inputs and pass them to the device15inputs = tokenizer("Astronomia é a ciência", return_tensors="pt").to(device)1617# Generate some text18completions = model.generate(**inputs, num_return_sequences=2, max_new_tokens=100)1920# Print the generated text21for i, completion inenumerate(completions):22print(f'🤖 {tokenizer.decode(completion)}')
Limitations
Like almost all other language models trained on large text datasets scraped from the web, the TTL pair exhibited behavior that does not make them an out-of-the-box solution to many real-world applications, especially those requiring factual, reliable, nontoxic text generation. Our models are all subject to the following:
Hallucinations: This model can produce content that can be mistaken for truth but is, in fact, misleading or entirely false, i.e., hallucination.
Biases and Toxicity: This model inherits the social and historical stereotypes from the data used to train it. Given these biases, the model can produce toxic content, i.e., harmful, offensive, or detrimental to individuals, groups, or communities.
Unreliable Code: The model may produce incorrect code snippets and statements. These code generations should not be treated as suggestions or accurate solutions.
Language Limitations: The model is primarily designed to understand standard Brazilian Portuguese. Other languages might challenge its comprehension, leading to potential misinterpretations or errors in response.
Repetition and Verbosity: The model may get stuck on repetition loops (especially if the repetition penalty during generations is set to a meager value) or produce verbose responses unrelated to the prompt it was given.
Hence, even though our models are released with a permissive license, we urge users to perform their risk analysis on these models if intending to use them for real-world applications and also have humans moderating the outputs of these models in applications where they will interact with an audience, guaranteeing users are always aware they are interacting with a language model.
Evaluations
During our training runs, both models showed consistent convergence. At no point did our evaluation curves show signs of overfitting or saturation. In the case of our 460m parameter model, we intentionally trained past the optimal point by approximately 75,000 steps to assess if there were any signs of saturation, but our evaluations consistently gave better results. We hypothesize that our models are under-trained but can improve if further trained to pass the Chinchilla optimal range.
To further evaluate the downstream capabilities of our models, we decided to employ a basic fine-tuning procedure for our TTL pair on a subset of tasks from the Poeta benchmark. We apply the same procedure for comparison purposes on both BERTimbau models, given that they are also LLM trained from scratch in Brazilian Portuguese and have a similar size range to our models. We used these comparisons to assess if our pre-training runs produced LLM capable of producing good results ("good" here means "close to BERTimbau") when utilized for downstream applications.
Models
IMDB
FaQuAD-NLI
HateBr
Assin2
AgNews
Average
BERTimbau-large
93.58
92.26
91.57
88.97
94.11
92.10
BERTimbau-small
92.22
93.07
91.28
87.45
94.19
91.64
TTL-460m
91.64
91.18
92.28
86.43
94.42
91.19
TTL-160m
91.14
90.00
90.71
85.78
94.05
90.34
All the shown results are the higher accuracy scores achieved on the respective task test sets after fine-tuning the models on the training sets. All fine-tuning runs used the same hyperparameters, and the code implementation can be found in the model cards of our fine-tuned models.
Cite as 🤗
latex
1@misc{correa24ttllama,
2 title = {TeenyTinyLlama: open-source tiny language models trained in Brazilian Portuguese},
3 author = {Corr{\^e}a, Nicholas Kluge and Falk, Sophia and Fatimah, Shiza and Sen, Aniket and De Oliveira, Nythamar},
4 journal={arXiv preprint arXiv:2401.16640},
5 year={2024}6}78@misc{correa24ttllama,
9 doi = {10.1016/j.mlwa.2024.100558},
10 url = {https://www.sciencedirect.com/science/article/pii/S2666827024000343},
11 title = {TeenyTinyLlama: open-source tiny language models trained in Brazilian Portuguese},
12 author = {Corr{\^e}a, Nicholas Kluge and Falk, Sophia and Fatimah, Shiza and Sen, Aniket and De Oliveira, Nythamar},
13 journal={Machine Learning With Applications},
14 publisher = {Springer},
15 year={2024}16}