Compare commits
34 Commits
master
...
main/finet
| Author | SHA1 | Date |
|---|---|---|
|
|
4bcb4f2f5a | |
|
|
ad00842f91 | |
|
|
544d14bcc2 | |
|
|
57ca071282 | |
|
|
967b10e153 | |
|
|
33eff363bc | |
|
|
447de65d83 | |
|
|
029662e9d1 | |
|
|
cd535b4fe3 | |
|
|
03faf77ee4 | |
|
|
b895fda3b0 | |
|
|
12cef050a2 | |
|
|
04747ff17b | |
|
|
2d82373bc8 | |
|
|
5da854395e | |
|
|
74f912e7e3 | |
|
|
48df71addb | |
|
|
29d5fe0d58 | |
|
|
972031cb6d | |
|
|
87206a9462 | |
|
|
46e2c21cfd | |
|
|
c5e4fc68c9 | |
|
|
9ef12dc7fd | |
|
|
8d74e3becb | |
|
|
4a264e38eb | |
|
|
3eb9d92846 | |
|
|
6a6546a03d | |
|
|
8e1f346f6e | |
|
|
4007d446e3 | |
|
|
124e904c31 | |
|
|
2980d74be4 | |
|
|
73b06efb33 | |
|
|
b056db8282 | |
|
|
2d37e5c858 |
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Użyj oficjalnego obrazu Python jako bazowego
|
||||||
|
FROM --platform=linux/amd64 python:3.9-slim
|
||||||
|
|
||||||
|
# Ustaw katalog roboczy w kontenerze
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Zainstaluj git
|
||||||
|
RUN apt-get update && apt-get install -y git nano wget curl iputils-ping
|
||||||
|
|
||||||
|
# Skopiuj pliki wymagań (jeśli istnieją) i zainstaluj zależności
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --upgrade pip
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Skopiuj plik requirements.txt do kontenera
|
||||||
|
COPY requirements.txt .
|
||||||
|
|
||||||
|
# Zainstaluj zależności z pliku requirements.txt
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Zainstaluj Tesseract OCR
|
||||||
|
RUN apt-get install -y tesseract-ocr
|
||||||
|
|
||||||
|
# Skopiuj kod źródłowy do kontenera
|
||||||
|
COPY . .
|
||||||
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
|
# Uruchom aplikację
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
git config --global credential.helper store
|
||||||
|
git config --global user.name ${GIT_USERNAME}
|
||||||
|
git config --global user.email ${GIT_EMAIL}
|
||||||
|
echo "https://${GIT_USERNAME}:${GIT_TOKEN}@${GIT_HOST}" > ~/.git-credentials
|
||||||
|
cd /home
|
||||||
|
git clone --single-branch --branch main/finetuning https://repo.pokash.pl/POKASH.PL/ably.do.git
|
||||||
|
python /app/${MODELNAME}.py
|
||||||
|
|
||||||
|
# Po zakończeniu głównego procesu, przejdź w tryb czuwania
|
||||||
|
echo "Główny proces zakończony. Przechodzę w tryb czuwania..."
|
||||||
|
tail -f /dev/null
|
||||||
119
herbert.py
119
herbert.py
|
|
@ -1,119 +0,0 @@
|
||||||
import os
|
|
||||||
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
||||||
|
|
||||||
import torch
|
|
||||||
import faiss
|
|
||||||
import numpy as np
|
|
||||||
from sentence_transformers import SentenceTransformer
|
|
||||||
from datasets import Dataset
|
|
||||||
from peft import LoraConfig, get_peft_model
|
|
||||||
from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, Trainer, DataCollatorForLanguageModeling
|
|
||||||
|
|
||||||
# 1️⃣ Inicjalizacja modelu do embeddingów
|
|
||||||
embed_model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
||||||
|
|
||||||
# 2️⃣ Dodanie dokumentów i embeddingów
|
|
||||||
def read_documents_from_file(file_path):
|
|
||||||
with open(file_path, 'r', encoding='utf-8') as file:
|
|
||||||
content = file.read()
|
|
||||||
articles = content.split('\n\n')
|
|
||||||
documents = []
|
|
||||||
for article in articles:
|
|
||||||
if article.strip().startswith('Art.'):
|
|
||||||
documents.append(article.strip())
|
|
||||||
return documents
|
|
||||||
#documents = [
|
|
||||||
# "Jak założyć firmę w Polsce?",
|
|
||||||
# "Jak rozliczyć podatek VAT?",
|
|
||||||
# "Procedura składania reklamacji w e-sklepie.",
|
|
||||||
# "Jakie dokumenty są potrzebne do rejestracji działalności?"
|
|
||||||
#]
|
|
||||||
file_path = './docs/kodekspracy.txt' # Zmień na właściwą ścieżkę
|
|
||||||
documents = read_documents_from_file(file_path)
|
|
||||||
embeddings = embed_model.encode(documents)
|
|
||||||
|
|
||||||
# 3️⃣ Inicjalizacja FAISS i dodanie wektorów
|
|
||||||
dim = embeddings.shape[1]
|
|
||||||
index = faiss.IndexFlatL2(dim)
|
|
||||||
index.add(np.array(embeddings, dtype=np.float32))
|
|
||||||
|
|
||||||
# 4️⃣ Przygotowanie danych treningowych
|
|
||||||
def create_training_data():
|
|
||||||
data = {
|
|
||||||
"text": documents,
|
|
||||||
"embedding": embeddings.tolist()
|
|
||||||
}
|
|
||||||
return Dataset.from_dict(data)
|
|
||||||
|
|
||||||
dataset = create_training_data()
|
|
||||||
|
|
||||||
# Podział danych na treningowe i ewaluacyjne
|
|
||||||
split_dataset = dataset.train_test_split(test_size=0.25)
|
|
||||||
train_dataset = split_dataset["train"]
|
|
||||||
eval_dataset = split_dataset["test"]
|
|
||||||
|
|
||||||
# 5️⃣ Ładowanie modelu Gemma 2B
|
|
||||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
||||||
model_name = "Lajonbot/vicuna-7b-v1.5-PL-lora_unload"
|
|
||||||
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16).to(device)
|
|
||||||
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
||||||
|
|
||||||
# 6️⃣ Konfiguracja LoRA
|
|
||||||
lora_config = LoraConfig(
|
|
||||||
r=8, lora_alpha=32, lora_dropout=0.1, bias="none", task_type="CAUSAL_LM"
|
|
||||||
)
|
|
||||||
model = get_peft_model(model, lora_config)
|
|
||||||
|
|
||||||
# 7️⃣ Tokenizacja danych
|
|
||||||
max_length = 384
|
|
||||||
|
|
||||||
def tokenize_function(examples):
|
|
||||||
return tokenizer(
|
|
||||||
examples["text"],
|
|
||||||
padding="max_length",
|
|
||||||
truncation=True,
|
|
||||||
max_length=max_length
|
|
||||||
)
|
|
||||||
|
|
||||||
tokenized_train = train_dataset.map(tokenize_function, batched=True)
|
|
||||||
tokenized_eval = eval_dataset.map(tokenize_function, batched=True)
|
|
||||||
|
|
||||||
# 8️⃣ Parametry treningu
|
|
||||||
training_args = TrainingArguments(
|
|
||||||
output_dir="./results",
|
|
||||||
eval_strategy="steps", # Ewaluacja co określoną liczbę kroków
|
|
||||||
eval_steps=500, # Ewaluacja co 500 kroków
|
|
||||||
save_strategy="steps", # Zapis modelu co określoną liczbę kroków
|
|
||||||
save_steps=500, # Zapis modelu co 500 kroków
|
|
||||||
learning_rate=1e-5,
|
|
||||||
per_device_train_batch_size=2,
|
|
||||||
per_device_eval_batch_size=2,
|
|
||||||
num_train_epochs=16,
|
|
||||||
weight_decay=0.01,
|
|
||||||
load_best_model_at_end=True, # Wczytaj najlepszy model na końcu
|
|
||||||
metric_for_best_model="loss", # Kryterium wyboru najlepszego modelu
|
|
||||||
greater_is_better=False, # Niższy loss = lepszy model
|
|
||||||
)
|
|
||||||
|
|
||||||
# 9️⃣ Data Collator
|
|
||||||
data_collator = DataCollatorForLanguageModeling(
|
|
||||||
tokenizer=tokenizer,
|
|
||||||
mlm=False
|
|
||||||
)
|
|
||||||
|
|
||||||
# 🔟 Trening modelu
|
|
||||||
trainer = Trainer(
|
|
||||||
model=model,
|
|
||||||
args=training_args,
|
|
||||||
train_dataset=tokenized_train,
|
|
||||||
eval_dataset=tokenized_eval, # Dodany zestaw ewaluacyjny
|
|
||||||
data_collator=data_collator,
|
|
||||||
)
|
|
||||||
|
|
||||||
trainer.train()
|
|
||||||
|
|
||||||
# 1️⃣1️⃣ Zapis modelu
|
|
||||||
model.save_pretrained("./models/herbert")
|
|
||||||
tokenizer.save_pretrained("./models/herbert")
|
|
||||||
|
|
||||||
print("✅ Model został wytrenowany i zapisany!")
|
|
||||||
|
|
@ -4,5 +4,13 @@ datasets>=2.13.1
|
||||||
Pillow>=9.4.0
|
Pillow>=9.4.0
|
||||||
pytesseract>=0.3.10
|
pytesseract>=0.3.10
|
||||||
python-docx>=0.8.11
|
python-docx>=0.8.11
|
||||||
PyPDF2>=3.0.1
|
pypdf
|
||||||
huggingface-hub>=0.16.4
|
PyPDF2
|
||||||
|
huggingface-hub>=0.16.4
|
||||||
|
numpy
|
||||||
|
peft
|
||||||
|
weaviate-client
|
||||||
|
sentence_transformers
|
||||||
|
faiss-gpu
|
||||||
|
sentencepiece
|
||||||
|
sacremoses
|
||||||
Loading…
Reference in New Issue