NLP
Collection
Dhivehi Natural Language Processing: Text analysis, translation, sentiment analysis, and language generation tools for Thaana
•
27 items
•
Updated
This repository contains a fine-tuned Flan-T5 model on the Alpaca Dhivehi dataset, aimed at enabling Dhivehi language instruction-following tasks.
Note: The model can follow instructions and inputs to some extent, but it’s not strictly trained for perfect adherence. Outputs may be partially aligned but are not guaranteed to be fully accurate. Treat results as experimental.
google/flan-t5-small
(or whichever size you used) eval_loss
: 2.59 ROUGE-1
: 0.10 ROUGE-2
: 0.03 ROUGE-L
: 0.107To run inference using the fine-tuned model:
import torch
from transformers import T5Tokenizer, T5ForConditionalGeneration
MODEL_PATH = "alakxender/flan-t5-base-alpaca-dv5"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = T5Tokenizer.from_pretrained(MODEL_PATH)
model = T5ForConditionalGeneration.from_pretrained(MODEL_PATH).to(device)
def generate_response(instruction, input_text):
combined_input = f"{instruction.strip()} {input_text.strip()}" if input_text else instruction.strip()
inputs = tokenizer(combined_input, return_tensors="pt", truncation=True, max_length=256).to(device)
output_ids = model.generate(
**inputs,
max_new_tokens=256,
num_beams=8,
repetition_penalty=1.5,
no_repeat_ngram_size=3,
do_sample=True,
early_stopping=True,
temperature=0.1
)
decoded_output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
return decoded_output
# Example usage:
instruction = "ދީފައިވާ މައުޟޫޢާ ބެހޭގޮތުން ކުރު ޕެރެގްރާފެއް ލިޔެލާށެވެ."
input_text = "އިއާދަކުރަނިވި ހަކަތަ ބޭނުންކުރުމުގެ މުހިންމުކަން"
print(generate_response(instruction, input_text))
އިއާދަކުރަނިވި ހަކަތަ ބޭނުންކުރުމުގެ މުހިންމު އެއް މައުޟޫއަކީ ސޯލާ، ވިންޑް، ހައިޑްރޯ، ޖިއޮތަރމަލް، އަދި ހައިޑްރޯއިލެކްޓްރިކް ޕަވަރ ފަދަ އިއާދަކުރަނިވި ހަކަތައިން ގްރީންހައުސް ގޭސްތައް ބޭރުވުން .....
From the last evaluation:
{
'eval_loss': 2.591374158859253,
'eval_rouge1': 0.10920254665663279,
'eval_rouge2': 0.03587297080345582,
'eval_rougeL': 0.10796498746412672,
'eval_rougeLsum': 0.1083282268650986,
'eval_runtime': 1204.3847,
'eval_samples_per_second': 4.298,
'eval_steps_per_second': 2.149,
'epoch': 5.0
}