File size: 4,582 Bytes
4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 56d2cf2 4274fc9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
---
base_model: meta-llama/Meta-Llama-3.1-8B
library_name: peft
datasets:
- barbaroo/Sprotin_parallel
language:
- en
- fo
metrics:
- bleu
- chrf
- bertscore
pipeline_tag: text-generation
---
# Model Card: English–Faroese Translation Adapter
## Model Details
**Model Description**
- **Developed by:** Barbara Scalvini
- **Model type:** Language model adapter for **English → Faroese** translation
- **Language(s):** English, Faroese
- **License:** This adapter inherits the license from the original Llama 3.1 8B model.
- **Finetuned from model:** [meta-llama/Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Llama-3.1-8B)
- **Library used:** [PEFT 0.13.0](https://github.com/huggingface/peft)
### Model Sources
- **Paper:** [COMING SOON]
---
## Uses
### Direct Use
This adapter is intended to perform **English→Faroese** translation, leveraging a **parameter-efficient fine-tuning** (PEFT) approach.
### Downstream Use [optional]
- Can be integrated into broader **multilingual** or **localization** workflows.
### Out-of-Scope Use
- Any uses that rely on languages other than **English or Faroese** will likely yield suboptimal results.
- Other tasks (e.g., summarization, classification) may be unsupported or require further fine-tuning.
---
## Bias, Risks, and Limitations
- **Biases:** The model could reflect **biases** present in the training data, such as historical or societal biases in English or Faroese texts.
- **Recommendation:** Users should **critically evaluate** outputs, especially in sensitive or high-stakes applications.
---
## How to Get Started with the Model
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load the trained model and tokenizer from the checkpoint
checkpoint_dir = "barbaroo/llama3.1_translate_8B" # The directory where your trained model and tokenizer are saved
model = AutoModelForCausalLM.from_pretrained(checkpoint_dir, device_map="auto", load_in_8bit = True)
tokenizer = AutoTokenizer.from_pretrained(checkpoint_dir)
MAX_SEQ_LENGTH = 512
sentences = ["What's your name?"]
# Define the prompt template (same as in training)
alpaca_prompt = """
### Instruction:
{}
### Input:
{}
### Response:
{}"""
# Inference loop
for sentence in sentences:
inputs = tokenizer(
[
alpaca_prompt.format(
"Translate this sentence from English to Faroese:", # Instruction
sentence, # The input sentence to translate
"", # Leave blank for generation
)
],
return_tensors="pt",
padding=True,
truncation=True, # Make sure the input is not too long
max_length=MAX_SEQ_LENGTH # Enforce the max length if necessary
).to("cuda")
# Generate the translation
outputs = model.generate(
**inputs,
max_new_tokens=512, # Limit the number of new tokens generated
eos_token_id=tokenizer.eos_token_id, # Ensure EOS token is used
pad_token_id=tokenizer.pad_token_id, # Ensure padding token is used
temperature=0.1, # Sampling temperature for diversity
top_p=1.0, # Sampling top-p for generation
use_cache=True # Use cache for efficiency
)
# Decode the generated tokens into text
output_string = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
print(f"Input: {sentence}")
print(f"Generated Translation: {output_string}")
```
## Training Details
### Training Data
We used the Sprotin parallel corpus for **English–Faroese** translation: [barbaroo/Sprotin_parallel](https://huggingface.co/datasets/barbaroo/Sprotin_parallel).
### Training Procedure
#### Preprocessing [optional]
- **Tokenization**: We used the tokenizer from the base model `meta-llama/Llama-3.1-8B`.
- The Alpaca prompt format was used, with Instruction, Input and Response.
#### Training Hyperparameters
- **Epochs**: **3** total, with an **early stopping** criterion monitoring validation loss.
- **Batch Size**: **2, with 4 Gradient accumulation steps**
- **Learning Rate**: **2e-4**
- **Optimizer**: **AdamW** with a linear learning-rate scheduler and warm-up.
---
## Evaluation
### Testing Data, Factors & Metrics
#### Testing Data
- The model was evaluated on the **[FLORES-200]** benchmark, of ~1012 English–Faroese pairs.
#### Metrics and Results
- **BLEU**: **[0.175]**
- **chrF**: **[49.5]**
- **BERTScore f1**: **[0.948]**
Human evaluation was also performed (see paper)
## Citation []
[COMING SOON]
---
## Framework versions
- PEFT 0.13.0 |