This repository contains the full implementation of an NLP project developed for the Natural Language Processing course. The objective was to automatically generate short Slovenian traffic reports for RTV Slovenija using prompt engineering and fine-tuning of a large language model.
report/report.pdf
– Final project reportdata/
– Raw and processed data used for training, evaluation, and testingevalvacija/
– Contains generated predictions and references for evaluationextract_data.py
– Converts.rtf
reference files to.txt
rouge.py
– Computes ROUGE scores to evaluate generated outputsara_2.py
– Prompt-based report generation script (old)prompts_and_responses.py
– Generates reports using prompt engineering with relevant input data (old)
model_download.py
- Locally downloads the GaMS 9B model (needs 35 GB disk space)prompt_input_preparation.py
– Fetches inputs required for prompt engineeringprompt_engineering.py
– Runs LLM using a prompt, writing output toprompt_engineering_results/
prepare_txt_files_ft.py
– Converts all reference reports (year 2024) into.txt
formatfine_tunning_data_collection.py
– Collects training/validation data for fine-tuning- Outputs:
train_4.jsonl
,val_4.jsonl
- Outputs:
fine_tuning.py
– Fine-tunes the LLM on the above datasetllm_finetune_9/
– Folder of the fine-tuned modelevaluation_data_collection.py
– Collects evaluation data from the reference reports from folder2023/
generate_finetuned_results.py
– Generates reports using the fine-tuned model on many examplesgenerate_finetuned.py
– Generates a report on a single example with the fine-tuned model
Install the required packages:
pip install -r requirements.txt
Download the dataset from this link and extract the contents of the RTVSlo/
folder into the data/
folder.
Run the following to convert reference .rtf
reports into .txt
format:
python extract_data.py
The converted files are then put into a new folder data/txts.
- Download the model:
python model_download.py
- Run the prompt engineering script on 2023 dataset (must have excel data in
data/Podatki - PrometnoPorocilo_2022_2023_2024.xlsx
):
python prompt_engineering.py
Outputs are saved in prompt_engineering_results/
.
To generate a report using the fine-tuned model for a single input:
Single example generation:
- Edit the
data
variable in generate_finetuned.py with your input. - Run the script:
python generate_finetuned.py
The report will be printed to the console or in the log file when running on SLURM.
Multiple examples generation:
- Prepare the evaluation data:
python evaluation_data_collection.py
It will prepare the data based on the references inside the 2023/
folder.
- Generate reports:
python generate_finetuned_results.py
Outputs are saved in finetuned_results/
.
- Prepare .txt reference files:
python prepare_txt_files_ft.py
- Collect data for training:
python fine_tunning_data_collection.py
This creates train_4.jsonl and val_4.jsonl
- Fine-tune the model:
python fine_tuning.py
The trained model will be saved in llm_finetune_9/
.
The script calculates ROUGE scores between the files in the evalvacija/predictions/
and evalvacija/references/
directories. Before running the evaluation, make sure the generated reports you want to evaluate are placed in correct folders.
Run the evaluation:
python rouge.py
To run scripts on a SLURM-based cluster just change the file you want to run inside the file run.sh
and set bigger a higher time limit if needed.
After that you just submit the job with the following command:
sbatch run.sh
You can check the status of your job with:
squeue --me
For any questions or issues, please contact: